You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/08/12 01:24:54 UTC

svn commit: r684980 - in /tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee: AssemblyHelper.java EJBModuleProcessor.java WebModuleProcessor.java

Author: rfeng
Date: Mon Aug 11 16:24:54 2008
New Revision: 684980

URL: http://svn.apache.org/viewvc?rev=684980&view=rev
Log:
Make AssemblyHelper non-static so that factories can be passed in 

Modified:
    tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/AssemblyHelper.java
    tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBModuleProcessor.java
    tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java

Modified: tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/AssemblyHelper.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/AssemblyHelper.java?rev=684980&r1=684979&r2=684980&view=diff
==============================================================================
--- tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/AssemblyHelper.java (original)
+++ tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/AssemblyHelper.java Mon Aug 11 16:24:54 2008
@@ -50,8 +50,8 @@
  * @version $Rev$ $Date$
  */
 public class AssemblyHelper {
-    private static AssemblyFactory af = new DefaultAssemblyFactory();
-    private static JavaInterfaceFactory jif = new DefaultJavaInterfaceFactory();
+    private AssemblyFactory af;
+    private JavaInterfaceFactory jif;
 
     public static final Map<String, QName> ALLOWED_ENV_ENTRY_TYPES;
     public static Intent CONVERSATIONAL_INTENT;
@@ -82,7 +82,19 @@
 
     }
 
-    public static JavaInterfaceContract createInterfaceContract(Class<?> clazz) throws InvalidInterfaceException {
+    public AssemblyHelper() {
+        super();
+        af = new DefaultAssemblyFactory();
+        jif = new DefaultJavaInterfaceFactory();
+    }
+
+    public AssemblyHelper(AssemblyFactory af, JavaInterfaceFactory jif) {
+        super();
+        this.af = af;
+        this.jif = jif;
+    }
+
+    public JavaInterfaceContract createInterfaceContract(Class<?> clazz) throws InvalidInterfaceException {
         JavaInterface ji = jif.createJavaInterface(clazz);
         JavaInterfaceContract jic = jif.createJavaInterfaceContract();
         jic.setInterface(ji);
@@ -90,23 +102,23 @@
         return jic;
     }
 
-    public static ComponentService createComponentService() {
+    public ComponentService createComponentService() {
         return af.createComponentService();
     }
 
-    public static ComponentReference createComponentReference() {
+    public ComponentReference createComponentReference() {
         return af.createComponentReference();
     }
 
-    public static ComponentProperty createComponentProperty() {
+    public ComponentProperty createComponentProperty() {
         return af.createComponentProperty();
     }
 
-    public static ComponentType createComponentType() {
+    public ComponentType createComponentType() {
         return af.createComponentType();
     }
 
-    public static Component createComponentFromComponentType(ComponentType componentType, String componentName) {
+    public Component createComponentFromComponentType(ComponentType componentType, String componentName) {
         Component component = af.createComponent();
         component.setName(componentName);
 
@@ -130,19 +142,19 @@
         return component;
     }
 
-    public static Composite createComposite() {
+    public Composite createComposite() {
         return af.createComposite();
     }
 
-    public static Component createComponent() {
+    public Component createComponent() {
         return af.createComponent();
     }
 
-    public static CompositeReference createCompositeReference() {
+    public CompositeReference createCompositeReference() {
         return af.createCompositeReference();
     }
 
-    public static CompositeService createCompositeService() {
+    public CompositeService createCompositeService() {
         return af.createCompositeService();
     }
 }

Modified: tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBModuleProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBModuleProcessor.java?rev=684980&r1=684979&r2=684980&view=diff
==============================================================================
--- tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBModuleProcessor.java (original)
+++ tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBModuleProcessor.java Mon Aug 11 16:24:54 2008
@@ -56,14 +56,20 @@
  * @version $Rev$ $Date$
  */
 public class EJBModuleProcessor {
-
     private EjbModule ejbModule;
-
+    private AssemblyHelper helper;
     private Map<String, List<String>> intfToBean = new HashMap<String, List<String>>();
     private List<String> statefulBeans = new ArrayList<String>();
 
+    public EJBModuleProcessor(EjbModule ejbModule, AssemblyHelper helper) {
+        super();
+        this.ejbModule = ejbModule;
+        this.helper = helper;
+    }
+
     public EJBModuleProcessor(EjbModule ejbModule) {
         this.ejbModule = ejbModule;
+        this.helper = new AssemblyHelper();
     }
 
     public Map<String, ComponentType> getEjbComponentTypes() throws ContributionException {
@@ -100,7 +106,7 @@
                 String intf = ((JavaInterface)reference.getInterfaceContract().getInterface()).getName();
                 for (String bean : intfToBean.get(intf)) {
                     if (statefulBeans.contains(bean)) {
-                        reference.getRequiredIntents().add(AssemblyHelper.CONVERSATIONAL_INTENT);
+                        reference.getRequiredIntents().add(helper.CONVERSATIONAL_INTENT);
                         break;
                     }
                 }
@@ -111,7 +117,7 @@
     }
 
     public ComponentType getEjbAppComponentType() throws ContributionException {
-        ComponentType componentType = AssemblyHelper.createComponentType();
+        ComponentType componentType = helper.createComponentType();
 
         Map<String, ComponentType> ejbComponentTypes = getEjbComponentTypes();
 
@@ -120,7 +126,7 @@
             ComponentType ejbComponentType = entry.getValue();
 
             for (Service service : ejbComponentType.getServices()) {
-                Service service2 = AssemblyHelper.createComponentService();
+                Service service2 = helper.createComponentService();
                 service2.setName(beanName + "_" + service.getName());
                 service2.setInterfaceContract(service.getInterfaceContract());
                 service2.getRequiredIntents().addAll(service.getRequiredIntents());
@@ -129,7 +135,7 @@
             }
 
             for (Reference reference : ejbComponentType.getReferences()) {
-                Reference reference2 = AssemblyHelper.createComponentReference();
+                Reference reference2 = helper.createComponentReference();
                 reference2.setName(beanName + "_" + reference.getName());
                 reference2.setInterfaceContract(reference.getInterfaceContract());
                 reference2.getRequiredIntents().addAll(reference.getRequiredIntents());
@@ -142,7 +148,7 @@
     }
 
     public Composite getEjbAppComposite() throws ContributionException {
-        Composite composite = AssemblyHelper.createComposite();
+        Composite composite = helper.createComposite();
 
         Map<String, ComponentType> ejbComponentTypes = getEjbComponentTypes();
 
@@ -156,28 +162,28 @@
             EJBImplementation impl = eif.createEJBImplementation();
             impl.setEJBLink(ejbModule.getModuleId() + "#" + ejbName);
             // Create component
-            Component component = AssemblyHelper.createComponent();
+            Component component = helper.createComponent();
             String componentName = ejbName;
             component.setName(componentName);
             component.setImplementation(impl);
 
             // Add services
             for (Service service : componentType.getServices()) {
-                ComponentService componentService = AssemblyHelper.createComponentService();
+                ComponentService componentService = helper.createComponentService();
                 componentService.setService(service);
                 component.getServices().add(componentService);
             }
 
             // Add references
             for (Reference reference : componentType.getReferences()) {
-                ComponentReference componentReference = AssemblyHelper.createComponentReference();
+                ComponentReference componentReference = helper.createComponentReference();
                 componentReference.setReference(reference);
                 component.getReferences().add(componentReference);
             }
 
             // Add properties
             for (Property property : componentType.getProperties()) {
-                ComponentProperty componentProperty = AssemblyHelper.createComponentProperty();
+                ComponentProperty componentProperty = helper.createComponentProperty();
                 componentProperty.setProperty(property);
                 component.getProperties().add(componentProperty);
             }
@@ -187,7 +193,7 @@
 
             // Add composite services
             for (ComponentService service : component.getServices()) {
-                CompositeService compositeService = AssemblyHelper.createCompositeService();
+                CompositeService compositeService = helper.createCompositeService();
                 compositeService.setInterfaceContract(service.getInterfaceContract());
                 compositeService.setPromotedComponent(component);
                 compositeService.setPromotedService(service);
@@ -196,7 +202,7 @@
 
             // Add composite references
             for (ComponentReference reference : component.getReferences()) {
-                CompositeReference compositeReference = AssemblyHelper.createCompositeReference();
+                CompositeReference compositeReference = helper.createCompositeReference();
                 compositeReference.setInterfaceContract(reference.getInterfaceContract());
                 compositeReference.getPromotedReferences().add(reference);
                 composite.getReferences().add(compositeReference);
@@ -206,7 +212,7 @@
     }
 
     private ComponentType getEjbComponentType(SessionBean bean, ClassLoader cl) throws ContributionException {
-        ComponentType componentType = AssemblyHelper.createComponentType();
+        ComponentType componentType = helper.createComponentType();
 
         boolean conversational = bean.getSessionType().equals(SessionType.STATEFUL);
         if (conversational) {
@@ -226,12 +232,12 @@
 
             String serviceName =
                 intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName;
-            Service service = AssemblyHelper.createComponentService();
+            Service service = helper.createComponentService();
             service.setName(serviceName);
             InterfaceContract ic = null;
             try {
                 Class<?> clazz = cl.loadClass(intfName);
-                ic = AssemblyHelper.createInterfaceContract(clazz);
+                ic = helper.createInterfaceContract(clazz);
                 ic.getInterface().setConversational(conversational);
                 ic.getInterface().setRemotable(true);
             } catch (Exception e) {
@@ -239,7 +245,7 @@
             }
             service.setInterfaceContract(ic);
             if (conversational) {
-                service.getRequiredIntents().add(AssemblyHelper.CONVERSATIONAL_INTENT);
+                service.getRequiredIntents().add(helper.CONVERSATIONAL_INTENT);
             }
             componentType.getServices().add(service);
         }
@@ -248,19 +254,19 @@
         for (String intfName : bean.getBusinessLocal()) {
             String serviceName =
                 intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName;
-            Service service = AssemblyHelper.createComponentService();
+            Service service = helper.createComponentService();
             service.setName(serviceName);
             InterfaceContract ic = null;
             try {
                 Class<?> clazz = cl.loadClass(intfName);
-                ic = AssemblyHelper.createInterfaceContract(clazz);
+                ic = helper.createInterfaceContract(clazz);
                 ic.getInterface().setConversational(conversational);
             } catch (Exception e) {
                 throw new ContributionException(e);
             }
             service.setInterfaceContract(ic);
             if (conversational) {
-                service.getRequiredIntents().add(AssemblyHelper.CONVERSATIONAL_INTENT);
+                service.getRequiredIntents().add(helper.CONVERSATIONAL_INTENT);
             }
             componentType.getServices().add(service);
         }
@@ -273,12 +279,12 @@
             }
             String referenceName = entry.getKey();
             referenceName = referenceName.replace("/", "_");
-            Reference reference = AssemblyHelper.createComponentReference();
+            Reference reference = helper.createComponentReference();
             reference.setName(referenceName);
             InterfaceContract ic = null;
             try {
                 Class<?> clazz = cl.loadClass(ejbRef.getInterface());
-                ic = AssemblyHelper.createInterfaceContract(clazz);
+                ic = helper.createInterfaceContract(clazz);
             } catch (Exception e) {
                 throw new ContributionException(e);
             }
@@ -290,15 +296,15 @@
         for (Map.Entry<String, EnvEntry> entry : bean.getEnvEntryMap().entrySet()) {
             EnvEntry envEntry = entry.getValue();
             String type = envEntry.getEnvEntryType();
-            if (!AssemblyHelper.ALLOWED_ENV_ENTRY_TYPES.containsKey(type)) {
+            if (!helper.ALLOWED_ENV_ENTRY_TYPES.containsKey(type)) {
                 continue;
             }
             String propertyName = entry.getKey();
             propertyName = propertyName.replace("/", "_");
             String value = envEntry.getEnvEntryValue();
-            Property property = AssemblyHelper.createComponentProperty();
+            Property property = helper.createComponentProperty();
             property.setName(propertyName);
-            property.setXSDType(AssemblyHelper.ALLOWED_ENV_ENTRY_TYPES.get(type));
+            property.setXSDType(helper.ALLOWED_ENV_ENTRY_TYPES.get(type));
             property.setValue(value);
             componentType.getProperties().add(property);
         }
@@ -307,7 +313,7 @@
     }
 
     private ComponentType getEjbComponentType(MessageDrivenBean bean, ClassLoader cl) throws ContributionException {
-        ComponentType componentType = AssemblyHelper.createComponentType();
+        ComponentType componentType = helper.createComponentType();
 
         // Process Remote EJB References
         for (Map.Entry<String, EjbRef> entry : bean.getEjbRefMap().entrySet()) {
@@ -317,12 +323,12 @@
             }
             String referenceName = entry.getKey();
             referenceName = referenceName.replace("/", "_");
-            Reference reference = AssemblyHelper.createComponentReference();
+            Reference reference = helper.createComponentReference();
             reference.setName(referenceName);
             InterfaceContract ic = null;
             try {
                 Class<?> clazz = cl.loadClass(ejbRef.getInterface());
-                ic = AssemblyHelper.createInterfaceContract(clazz);
+                ic = helper.createInterfaceContract(clazz);
             } catch (Exception e) {
                 throw new ContributionException(e);
             }
@@ -334,15 +340,15 @@
         for (Map.Entry<String, EnvEntry> entry : bean.getEnvEntryMap().entrySet()) {
             EnvEntry envEntry = entry.getValue();
             String type = envEntry.getEnvEntryType();
-            if (!AssemblyHelper.ALLOWED_ENV_ENTRY_TYPES.containsKey(type)) {
+            if (!helper.ALLOWED_ENV_ENTRY_TYPES.containsKey(type)) {
                 continue;
             }
             String propertyName = entry.getKey();
             propertyName = propertyName.replace("/", "_");
             String value = envEntry.getEnvEntryValue();
-            Property property = AssemblyHelper.createComponentProperty();
+            Property property = helper.createComponentProperty();
             property.setName(propertyName);
-            property.setXSDType(AssemblyHelper.ALLOWED_ENV_ENTRY_TYPES.get(type));
+            property.setXSDType(helper.ALLOWED_ENV_ENTRY_TYPES.get(type));
             property.setValue(value);
             componentType.getProperties().add(property);
         }

Modified: tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java?rev=684980&r1=684979&r2=684980&view=diff
==============================================================================
--- tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java (original)
+++ tuscany/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java Mon Aug 11 16:24:54 2008
@@ -44,16 +44,24 @@
 public class WebModuleProcessor {
     private WebModule webModule;
     private ComponentType componentType;
+    private AssemblyHelper helper;
+
+    public WebModuleProcessor(WebModule webModule, AssemblyHelper helper) {
+        super();
+        this.webModule = webModule;
+        this.helper = helper;
+    }
 
     public WebModuleProcessor(WebModule module) {
         webModule = module;
+        helper = new AssemblyHelper();
     }
 
     public ComponentType getWebAppComponentType() throws ContributionException {
         if (componentType != null) {
             return componentType;
         }
-        componentType = AssemblyHelper.createComponentType();
+        componentType = helper.createComponentType();
 
         WebApp webApp = webModule.getWebApp();
         ClassLoader classLoader = webModule.getClassLoader();
@@ -68,12 +76,12 @@
             }
             String referenceName = entry.getKey();
             referenceName = referenceName.replace("/", "_");
-            Reference reference = AssemblyHelper.createComponentReference();
+            Reference reference = helper.createComponentReference();
             reference.setName(referenceName);
             InterfaceContract ic = null;
             try {
                 Class<?> clazz = classLoader.loadClass(ejbRef.getInterface());
-                ic = AssemblyHelper.createInterfaceContract(clazz);
+                ic = helper.createInterfaceContract(clazz);
             } catch (Exception e) {
                 componentType = null;
                 throw new ContributionException(e);
@@ -86,15 +94,15 @@
         for (Map.Entry<String, EnvEntry> entry : webApp.getEnvEntryMap().entrySet()) {
             EnvEntry envEntry = entry.getValue();
             String type = envEntry.getEnvEntryType();
-            if (!AssemblyHelper.ALLOWED_ENV_ENTRY_TYPES.containsKey(type)) {
+            if (!helper.ALLOWED_ENV_ENTRY_TYPES.containsKey(type)) {
                 continue;
             }
             String propertyName = entry.getKey();
             propertyName = propertyName.replace("/", "_");
             String value = envEntry.getEnvEntryValue();
-            Property property = AssemblyHelper.createComponentProperty();
+            Property property = helper.createComponentProperty();
             property.setName(propertyName);
-            property.setXSDType(AssemblyHelper.ALLOWED_ENV_ENTRY_TYPES.get(type));
+            property.setXSDType(helper.ALLOWED_ENV_ENTRY_TYPES.get(type));
             property.setValue(value);
             componentType.getProperties().add(property);
         }
@@ -105,7 +113,7 @@
     public Composite getWebAppComposite() throws ContributionException {
         getWebAppComponentType();
 
-        Composite composite = AssemblyHelper.createComposite();
+        Composite composite = helper.createComposite();
 
         ModelFactoryExtensionPoint mfep = new DefaultModelFactoryExtensionPoint();
         WebImplementationFactory wif = mfep.getFactory(WebImplementationFactory.class);
@@ -113,21 +121,21 @@
         impl.setWebURI(webModule.getModuleId());
 
         // Create component
-        Component component = AssemblyHelper.createComponent();
+        Component component = helper.createComponent();
         String componentName = webModule.getModuleId();
         component.setName(componentName);
         component.setImplementation(impl);
 
         // Add references
         for (Reference reference : componentType.getReferences()) {
-            ComponentReference componentReference = AssemblyHelper.createComponentReference();
+            ComponentReference componentReference = helper.createComponentReference();
             componentReference.setReference(reference);
             component.getReferences().add(componentReference);
         }
 
         // Add properties
         for (Property property : componentType.getProperties()) {
-            ComponentProperty componentProperty = AssemblyHelper.createComponentProperty();
+            ComponentProperty componentProperty = helper.createComponentProperty();
             componentProperty.setProperty(property);
             component.getProperties().add(componentProperty);
         }
@@ -137,7 +145,7 @@
 
         // Add composite references
         for (ComponentReference reference : component.getReferences()) {
-            CompositeReference compositeReference = AssemblyHelper.createCompositeReference();
+            CompositeReference compositeReference = helper.createCompositeReference();
             compositeReference.setInterfaceContract(reference.getInterfaceContract());
             compositeReference.getPromotedReferences().add(reference);
             composite.getReferences().add(compositeReference);