tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r399391 - in /incubator/tuscany/sandbox/jboynes/sca: core2/src/main/java/org/apache/tuscany/core/builder/ core2/src/test/java/org/apache/tuscany/core/builder/ core2/src/test/java/org/apache/tuscany/core/loader/ model/src/main/java/org/apach...
Date Wed, 03 May 2006 20:00:03 GMT
Author: jboynes
Date: Wed May  3 12:59:57 2006
New Revision: 399391

URL: http://svn.apache.org/viewcvs?rev=399391&view=rev
Log:
refactor builder for spi

Added:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
  (with props)
Modified:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java
    incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Component.java
    incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/CompositeComponentType.java
    incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java
    incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java
    incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderContext.java

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java?rev=399391&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java
Wed May  3 12:59:57 2006
@@ -0,0 +1,89 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.model.BoundReference;
+import org.apache.tuscany.model.BoundService;
+import org.apache.tuscany.model.Component;
+import org.apache.tuscany.model.Implementation;
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.builder.ComponentBuilder;
+import org.apache.tuscany.spi.builder.WireBuilder;
+import org.apache.tuscany.spi.context.CompositeContext;
+import org.apache.tuscany.spi.context.Context;
+import org.apache.tuscany.spi.wire.SourceWireFactory;
+import org.apache.tuscany.spi.wire.TargetWireFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuilderRegistryImpl implements BuilderRegistry {
+    private final Map<Class<? extends Implementation<?>>, ComponentBuilder<?
extends Implementation<?>>> componentBuilders = new HashMap<Class<? extends
Implementation<?>>, ComponentBuilder<? extends Implementation<?>>>();
+
+    public <I extends Implementation<?>> void register(ComponentBuilder<I>
builder) {
+        Class<?> aClass = builder.getClass();
+        Type[] interfaces = aClass.getGenericInterfaces();
+        for (Type type : interfaces) {
+            if (! (type instanceof ParameterizedType)) {
+                continue;
+            }
+            ParameterizedType interfaceType = (ParameterizedType) type;
+            if (!ComponentBuilder.class.equals(interfaceType.getRawType())) {
+                continue;
+            }
+            Class<I> implClass = (Class<I>) interfaceType.getActualTypeArguments()[0];
+            register(implClass, builder);
+            return;
+        }
+        throw new IllegalArgumentException("builder is not generified");
+    }
+
+    public <I extends Implementation<?>> void register(Class<I> implClass,
ComponentBuilder<I> builder) {
+        componentBuilders.put(implClass, builder);
+    }
+
+    public void register(WireBuilder builder) {
+        throw new UnsupportedOperationException();
+    }
+
+    public <I extends Implementation<?>> Context build(CompositeContext parent,
Component<I> component) {
+        Class<I> implClass = (Class<I>) component.getImplementation().getClass();
+        ComponentBuilder<I> componentBuilder = (ComponentBuilder<I>) componentBuilders.get(implClass);
+        return componentBuilder.build(parent, component);
+    }
+
+    public Context build(CompositeContext parent, BoundService boundService) {
+        throw new UnsupportedOperationException();
+    }
+
+    public Context build(CompositeContext parent, BoundReference boundReference) {
+        throw new UnsupportedOperationException();
+    }
+
+    public void connect(SourceWireFactory<?> source, TargetWireFactory<?> target)
{
+        throw new UnsupportedOperationException();
+    }
+
+    public void completeChain(TargetWireFactory<?> target) {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java?rev=399391&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
Wed May  3 12:59:57 2006
@@ -0,0 +1,63 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.model.Component;
+import org.apache.tuscany.model.CompositeImplementation;
+import org.apache.tuscany.spi.builder.ComponentBuilder;
+import org.apache.tuscany.spi.context.CompositeContext;
+import org.apache.tuscany.spi.context.Context;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuilderRegistryTestCase extends TestCase {
+    private BuilderRegistryImpl registry;
+
+    public void testRegistrationWithGenerics() {
+        GenerifiedBuilder builder = new GenerifiedBuilder();
+        registry.register(builder);
+        Component<CompositeImplementation> component = new Component(new CompositeImplementation());
+        registry.build(null, component);
+    }
+
+    public void testRegistrationWithoutGenerics() {
+        RawBuilder builder = new RawBuilder();
+        registry.register(CompositeImplementation.class, builder);
+        Component<CompositeImplementation> component = new Component(new CompositeImplementation());
+        registry.build(null, component);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        registry = new BuilderRegistryImpl();
+    }
+
+    public static class GenerifiedBuilder implements ComponentBuilder<CompositeImplementation>
{
+        public Context build(CompositeContext parent, Component<CompositeImplementation>
component) {
+            return null;
+        }
+    }
+
+    @SuppressWarnings({"RawUseOfParameterizedType"})
+    public static class RawBuilder implements ComponentBuilder {
+        public Context build(CompositeContext parent, Component component) {
+            return null;
+        }
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java?rev=399391&r1=399390&r2=399391&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java
Wed May  3 12:59:57 2006
@@ -67,6 +67,6 @@
         mockReader = mock(XMLStreamReader.class);
         mockRegistry = mock(StAXLoaderRegistry.class);
         loader.setRegistry((StAXLoaderRegistry) mockRegistry.proxy());
-        loaderContext = new LoaderContext(null);
+        loaderContext = new LoaderContext(null, null);
     }
 }

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java?rev=399391&r1=399390&r2=399391&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java
Wed May  3 12:59:57 2006
@@ -76,7 +76,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         name = new QName("http://mock", "test");
-        loaderContext = new LoaderContext(null);
+        loaderContext = new LoaderContext(null, null);
         registry = new StAXLoaderRegistryImpl();
         mockMonitor = mock(StAXLoaderRegistryImpl.Monitor.class);
         registry.setMonitor((StAXLoaderRegistryImpl.Monitor) mockMonitor.proxy());

Modified: incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Component.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Component.java?rev=399391&r1=399390&r2=399391&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Component.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/Component.java
Wed May  3 12:59:57 2006
@@ -16,19 +16,19 @@
  */
 package org.apache.tuscany.model;
 
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @version $Rev$ $Date$
  */
-public class Component<T extends Implementation> extends ModelObject {
+public class Component<I extends Implementation<?>> extends ModelObject {
     private String name;
-    private final T implementation;
+    private final I implementation;
     private final Map<String, ReferenceTarget> referenceTargets = new HashMap<String,
ReferenceTarget>();
     private final Map<String, PropertyValue<?>> propertyValues = new HashMap<String,
PropertyValue<?>>();
 
-    public Component(T implementation) {
+    public Component(I implementation) {
         this.implementation = implementation;
     }
 
@@ -40,7 +40,7 @@
         this.name = name;
     }
 
-    public T getImplementation() {
+    public I getImplementation() {
         return implementation;
     }
 

Modified: incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/CompositeComponentType.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/CompositeComponentType.java?rev=399391&r1=399390&r2=399391&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/CompositeComponentType.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/model/src/main/java/org/apache/tuscany/model/CompositeComponentType.java
Wed May  3 12:59:57 2006
@@ -24,7 +24,7 @@
  */
 public class CompositeComponentType extends ComponentType {
     private String name;
-    private final Map<String, Component> components = new HashMap<String, Component>();
+    private final Map<String, Component<?>> components = new HashMap<String,
Component<?>>();
 
     public String getName() {
         return name;
@@ -34,7 +34,7 @@
         this.name = name;
     }
 
-    public Map<String, Component> getComponents() {
+    public Map<String, Component<?>> getComponents() {
         return components;
     }
 

Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java?rev=399391&r1=399390&r2=399391&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java
Wed May  3 12:59:57 2006
@@ -19,6 +19,7 @@
 import org.apache.tuscany.model.BoundReference;
 import org.apache.tuscany.model.BoundService;
 import org.apache.tuscany.model.Component;
+import org.apache.tuscany.model.Implementation;
 import org.apache.tuscany.spi.context.CompositeContext;
 import org.apache.tuscany.spi.context.Context;
 import org.apache.tuscany.spi.wire.SourceWireFactory;
@@ -28,11 +29,13 @@
  * @version $Rev$ $Date$
  */
 public interface BuilderRegistry {
-    void register(ComponentBuilder<?> builder);
+    <I extends Implementation<?>> void register(ComponentBuilder<I> builder);
+
+    <I extends Implementation<?>> void register(Class<I> implClass, ComponentBuilder<I>
builder);
 
     void register(WireBuilder builder);
 
-    Context build(CompositeContext parent, Component component);
+    <I extends Implementation<?>> Context build(CompositeContext parent, Component<I>
component);
 
     Context build(CompositeContext parent, BoundService boundService);
 

Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java?rev=399391&r1=399390&r2=399391&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java
Wed May  3 12:59:57 2006
@@ -17,11 +17,13 @@
 package org.apache.tuscany.spi.builder;
 
 import org.apache.tuscany.model.Component;
+import org.apache.tuscany.model.Implementation;
 import org.apache.tuscany.spi.context.CompositeContext;
+import org.apache.tuscany.spi.context.Context;
 
 /**
  * @version $Rev$ $Date$
  */
-public interface ComponentBuilder<T extends Component> {
-    void build(CompositeContext parent, T component);
+public interface ComponentBuilder<I extends Implementation<?>> {
+    Context build(CompositeContext parent, Component<I> component);
 }

Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderContext.java?rev=399391&r1=399390&r2=399391&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderContext.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderContext.java
Wed May  3 12:59:57 2006
@@ -16,6 +16,8 @@
  */
 package org.apache.tuscany.spi.loader;
 
+import javax.xml.stream.XMLInputFactory;
+
 /**
  * Context holder that can be used during the load process to store information
  * that is not part of the logical model. This should be regarded as transient
@@ -25,21 +27,34 @@
  */
 public class LoaderContext {
     private final ClassLoader classLoader;
+    private final XMLInputFactory xmlFactory;
 
     /**
      * Constructor specifying the loader for application resources.
      *
      * @param classLoader the loader for application resources
+     * @param xmlFactory  a factory that can be used to obtain an StAX XMLStreamReader
      */
-    public LoaderContext(ClassLoader classLoader) {
+    public LoaderContext(ClassLoader classLoader, XMLInputFactory xmlFactory) {
         this.classLoader = classLoader;
+        this.xmlFactory = xmlFactory;
     }
 
     /**
      * Returns a class loader that can be used to load application resources.
+     *
      * @return a class loader that can be used to load application resources
      */
     public ClassLoader getClassLoader() {
         return classLoader;
+    }
+
+    /**
+     * Returns a factory that can be used to obtain an StAX XMLStreamReader.
+     *
+     * @return a factory that can be used to obtain an StAX XMLStreamReader
+     */
+    public XMLInputFactory getXmlFactory() {
+        return xmlFactory;
     }
 }



Mime
View raw message