diff options
Diffstat (limited to 'branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl')
3 files changed, 216 insertions, 35 deletions
diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedImpl.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedImpl.java new file mode 100644 index 0000000000..cd23887312 --- /dev/null +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedImpl.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.sca.contribution.jee.impl; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor; +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; +import org.apache.tuscany.sca.contribution.jee.EJBImplementationGenerated; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + + +/** + * The model representing an EJB implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +class EJBImplementationGeneratedImpl extends ImplementationImpl implements EJBImplementationGenerated { + + private String ejbLink; + + /** + * Constructs a new EJB implementation. + */ + EJBImplementationGeneratedImpl() { + super(); + } + + @Override + public ConstrainingType getConstrainingType() { + // The EJB implementation does not support constrainingTypes + return null; + } + + public String getEJBLink() { + return ejbLink; + } + + @Override + public void setConstrainingType(ConstrainingType constrainingType) { + // The EJB implementation does not support constrainingTypes + } + + public void setEJBLink(String ejbLink) { + this.ejbLink = ejbLink; + } + +} diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEExtensionImpl.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEExtensionImpl.java index 8d8d0f4c35..c4e180bf82 100644 --- a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEExtensionImpl.java +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEExtensionImpl.java @@ -23,9 +23,14 @@ import java.util.Map; import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.jee.EJBImplementationGenerated; import org.apache.tuscany.sca.contribution.jee.EjbInfo; import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; @@ -97,14 +102,16 @@ public class JavaEEExtensionImpl implements JavaEEExtension { return componentType; } - public ComponentType createImplementationJeeComponentType(EjbModuleInfo ejbModule) { - ComponentType componentType = assemblyFactory.createComponentType(); - + public void createImplementationJeeComposite(EjbModuleInfo ejbModule, Composite composite) { + for(Map.Entry<String, EjbInfo> entry : ejbModule.getEjbInfos().entrySet()) { EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo.beanName); + if(ejbInfo.ejbType.compareTo(EjbType.MESSAGE_DRIVEN) != 0) { for(Class<?> intf : ejbInfo.businessRemote) { - Service service = assemblyFactory.createComponentService(); + ComponentService service = assemblyFactory.createComponentService(); String intfName = intf.getName(); String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; serviceName = ejbInfo.beanName+"_"+serviceName; @@ -117,11 +124,12 @@ public class JavaEEExtensionImpl implements JavaEEExtension { e.printStackTrace(); } service.setInterfaceContract(ic); - componentType.getServices().add(service); + + addComponentService(composite, component, service); } for(Class<?> intf : ejbInfo.businessLocal) { - Service service = assemblyFactory.createComponentService(); + ComponentService service = assemblyFactory.createComponentService(); String intfName = intf.getName(); String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; serviceName = ejbInfo.beanName+"_"+serviceName; @@ -136,25 +144,25 @@ public class JavaEEExtensionImpl implements JavaEEExtension { service.setInterfaceContract(ic); service.getRequiredIntents().add(EJB_INTENT); - componentType.getServices().add(service); + addComponentService(composite, component, service); } } } - - return componentType; } - - public ComponentType createImplementationJeeComponentType(JavaEEApplicationInfo appInfo) { - ComponentType componentType = assemblyFactory.createComponentType(); + + public void createImplementationJeeComposite(JavaEEApplicationInfo appInfo, Composite composite) { for(Map.Entry<String, EjbModuleInfo> entry0 : appInfo.getEjbModuleInfos().entrySet()) { EjbModuleInfo ejbModule = entry0.getValue(); for(Map.Entry<String, EjbInfo> entry : ejbModule.getEjbInfos().entrySet()) { EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo.beanName); + if(ejbInfo.ejbType.compareTo(EjbType.MESSAGE_DRIVEN) != 0) { for(Class<?> intf : ejbInfo.businessRemote) { - Service service = assemblyFactory.createComponentService(); + ComponentService service = assemblyFactory.createComponentService(); String intfName = intf.getName(); String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; serviceName = ejbInfo.mappedName+"_"+serviceName; @@ -167,11 +175,12 @@ public class JavaEEExtensionImpl implements JavaEEExtension { e.printStackTrace(); } service.setInterfaceContract(ic); - componentType.getServices().add(service); + + addComponentService(composite, component, service); } for(Class<?> intf : ejbInfo.businessLocal) { - Service service = assemblyFactory.createComponentService(); + ComponentService service = assemblyFactory.createComponentService(); String intfName = intf.getName(); String serviceName = intfName.lastIndexOf(".") != -1 ? intfName.substring(intfName.lastIndexOf(".") + 1) : intfName; serviceName = ejbInfo.mappedName+"_"+serviceName; @@ -186,12 +195,59 @@ public class JavaEEExtensionImpl implements JavaEEExtension { service.setInterfaceContract(ic); service.getRequiredIntents().add(EJB_INTENT); - componentType.getServices().add(service); + addComponentService(composite, component, service); } } } } + } + + /** + * We are fluffing up the JEEImplemention composite to represented the components + * in the JEE archive. Given the JEEimplemenation composite find a named component + * it if already exists or create it if it doesn't. + * + * @param composite + * @param componentName + * @return + */ + private Component findComponent(Composite composite, String componentName){ + Component component = null; - return componentType; + for (Component tmpComponent : composite.getComponents()){ + if (tmpComponent.getName().equals(componentName)){ + component = tmpComponent; + break; + } + } + + if (component == null){ + component = assemblyFactory.createComponent(); + component.setName(componentName); + composite.getComponents().add(component); + + EJBImplementationGenerated implementation = new EJBImplementationGeneratedImpl(); + component.setImplementation(implementation); + } + + return component; + } + + /** + * Add a component service and fluff up a composite service to match + * + * @param composite + * @param component + * @param service + */ + private void addComponentService(Composite composite, Component component, ComponentService service){ + component.getImplementation().getServices().add(service); + + CompositeService compositeService = assemblyFactory.createCompositeService(); + composite.getServices().add(compositeService); + + compositeService.setName(service.getName()); + compositeService.setPromotedComponent(component); + compositeService.setPromotedService(service); } } diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java index f02b74bd8d..ad7e54b84f 100644 --- a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/JavaEEOptionalExtensionImpl.java @@ -24,11 +24,18 @@ import java.util.Map; import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.jee.EJBImplementationGenerated; import org.apache.tuscany.sca.contribution.jee.EjbInfo; import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; import org.apache.tuscany.sca.contribution.jee.EjbReferenceInfo; @@ -167,15 +174,16 @@ public class JavaEEOptionalExtensionImpl implements JavaEEOptionalExtension { return componentType; } - public ComponentType createImplementationJeeComponentType(WebModuleInfo webModule) { - ComponentType componentType = assemblyFactory.createComponentType(); + public void createImplementationJeeComposite(WebModuleInfo webModule, Composite composite) { + + Component component = findComponent(composite, webModule.getModuleName()); // Process Remote EJB References for(Map.Entry<String, EjbReferenceInfo> entry : webModule.getEjbReferences().entrySet()) { EjbReferenceInfo ejbRef = entry.getValue(); String referenceName = entry.getKey(); referenceName = referenceName.replace("/", "_"); - Reference reference = assemblyFactory.createComponentReference(); + ComponentReference reference = assemblyFactory.createComponentReference(); reference.setName(referenceName); InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); try { @@ -187,24 +195,25 @@ public class JavaEEOptionalExtensionImpl implements JavaEEOptionalExtension { reference.setInterfaceContract(ic); reference.getRequiredIntents().add(EJB_INTENT); reference.setMultiplicity(Multiplicity.ZERO_ONE); - componentType.getReferences().add(reference); + + addComponentReference(composite, component, reference); } - - return componentType; } - public ComponentType createImplementationJeeComponentType(EjbModuleInfo ejbModule) { - ComponentType componentType = assemblyFactory.createComponentType(); + public void createImplementationJeeComposite(EjbModuleInfo ejbModule, Composite composite) { for(Map.Entry<String, EjbInfo> entry : ejbModule.getEjbInfos().entrySet()) { EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo.beanName); + // Process Remote EJB References for(Map.Entry<String, EjbReferenceInfo> entry1 : ejbInfo.ejbReferences.entrySet()) { EjbReferenceInfo ejbRef = entry1.getValue(); String referenceName = ejbRef.referenceName; referenceName = referenceName.replace("/", "_"); referenceName = ejbInfo.beanName + "_" + referenceName; - Reference reference = assemblyFactory.createComponentReference(); + ComponentReference reference = assemblyFactory.createComponentReference(); reference.setName(referenceName); InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); try { @@ -216,28 +225,30 @@ public class JavaEEOptionalExtensionImpl implements JavaEEOptionalExtension { reference.setInterfaceContract(ic); reference.getRequiredIntents().add(EJB_INTENT); reference.setMultiplicity(Multiplicity.ZERO_ONE); - componentType.getReferences().add(reference); + + addComponentReference(composite, component, reference); } } - - return componentType; } - public ComponentType createImplementationJeeComponentType(JavaEEApplicationInfo appInfo) { - ComponentType componentType = assemblyFactory.createComponentType(); + + public void createImplementationJeeComposite(JavaEEApplicationInfo appInfo, Composite composite) { for(Map.Entry<String, EjbModuleInfo> entry0 : appInfo.getEjbModuleInfos().entrySet()) { EjbModuleInfo ejbModule = entry0.getValue(); for(Map.Entry<String, EjbInfo> entry : ejbModule.getEjbInfos().entrySet()) { EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo.beanName); + // Process Remote EJB References for(Map.Entry<String, EjbReferenceInfo> entry1 : ejbInfo.ejbReferences.entrySet()) { EjbReferenceInfo ejbRef = entry1.getValue(); String referenceName = ejbRef.referenceName; referenceName = referenceName.replace("/", "_"); referenceName = ejbInfo.beanName + "_" + referenceName; - Reference reference = assemblyFactory.createComponentReference(); + ComponentReference reference = assemblyFactory.createComponentReference(); reference.setName(referenceName); InterfaceContract ic = javaInterfaceFactory.createJavaInterfaceContract(); try { @@ -249,11 +260,58 @@ public class JavaEEOptionalExtensionImpl implements JavaEEOptionalExtension { reference.setInterfaceContract(ic); reference.getRequiredIntents().add(EJB_INTENT); reference.setMultiplicity(Multiplicity.ZERO_ONE); - componentType.getReferences().add(reference); + + addComponentReference(composite, component, reference); } } } + } + + /** + * We are fluffing up the JEEImplemention composite to represented the components + * in the JEE archive. Given the JEEimplemenation composite find a named component + * it if already exists or create it if it doesn't. + * + * @param composite + * @param componentName + * @return + */ + private Component findComponent(Composite composite, String componentName){ + Component component = null; - return componentType; - } + for (Component tmpComponent : composite.getComponents()){ + if (tmpComponent.getName().equals(componentName)){ + component = tmpComponent; + break; + } + } + + if (component == null){ + component = assemblyFactory.createComponent(); + component.setName(componentName); + composite.getComponents().add(component); + + EJBImplementationGenerated implementation = new EJBImplementationGeneratedImpl(); + component.setImplementation(implementation); + } + + return component; + } + + /** + * Add a component reference and fluff up a composite reference to match + * + * @param composite + * @param component + * @param service + */ + private void addComponentReference(Composite composite, Component component, ComponentReference reference){ + component.getImplementation().getReferences().add(reference); + + CompositeReference compositeReference = assemblyFactory.createCompositeReference(); + composite.getReferences().add(compositeReference); + + compositeReference.setName(reference.getName()); + compositeReference.getPromotedReferences().add(reference); + } } |