From 76f33c9cd9b1ca39509e9ca956d5596901138df2 Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 22 May 2009 16:52:57 +0000 Subject: TUSCANY-3052 - Correct the way that JEEImplementations are represented so that they appear as composites. In that way an application composite, when present, can naturally be included in the component hierarchy. When an application composite isn't present then the composite is created on the fly based on the information from the introspected archive. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@777618 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/assembly/xml/CompositeProcessor.java | 6 +- .../jee/EJBImplementationGenerated.java | 44 ++++++++++ .../sca/contribution/jee/JavaEEExtension.java | 10 ++- .../contribution/jee/JavaEEOptionalExtension.java | 12 ++- .../jee/impl/EJBImplementationGeneratedImpl.java | 67 +++++++++++++++ .../contribution/jee/impl/JavaEEExtensionImpl.java | 90 +++++++++++++++++---- .../jee/impl/JavaEEOptionalExtensionImpl.java | 94 +++++++++++++++++----- .../sca/implementation/jee/JEEImplementation.java | 4 +- .../jee/impl/JEEImplementationImpl.java | 6 +- .../jee/xml/JEEImplementationProcessor.java | 63 ++++++++------- 10 files changed, 324 insertions(+), 72 deletions(-) create mode 100644 branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBImplementationGenerated.java create mode 100644 branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/EJBImplementationGeneratedImpl.java diff --git a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java index c4528e0bf2..2297b06a2d 100644 --- a/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java +++ b/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java @@ -56,6 +56,7 @@ 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.Wire; +import org.apache.tuscany.sca.assembly.impl.CompositeImpl; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; @@ -682,7 +683,10 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt // Write the component implementation Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { + // check that we really have CompositeImpl and treat this specially. Some + // extension extend CompositeImpl and we want these to be treated by the extension + // processor. + if ((implementation != null ) && (implementation.getClass().equals(CompositeImpl.class))) { writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, ((Composite)implementation).getName())); //write extended attributes diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBImplementationGenerated.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBImplementationGenerated.java new file mode 100644 index 0000000000..f486b63904 --- /dev/null +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBImplementationGenerated.java @@ -0,0 +1,44 @@ +/* + * 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; + +import org.apache.tuscany.sca.assembly.Implementation; + + + +/** + * The model representing an EJB implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public interface EJBImplementationGenerated extends Implementation { + + /** + * Returns the EJB link URI. + * @return the EJB link URI + */ + String getEJBLink(); + + /** + * Sets the EJB link URI. + * @param ejbLink the EJB link URI + */ + void setEJBLink(String ejbLink); + +} diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEExtension.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEExtension.java index a78448521f..7b7d1f161f 100644 --- a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEExtension.java +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEExtension.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.contribution.jee; import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; /** * Compute componentType with EJB3 business interfaces translating into SCA services. @@ -26,7 +27,12 @@ import org.apache.tuscany.sca.assembly.ComponentType; * @version $Rev$ $Date$ */ public interface JavaEEExtension { + // The EJBImplementation model is a straight implementation so we deal in + // component types ComponentType createImplementationEjbComponentType(EjbModuleInfo ejbModule, String ejbName); - ComponentType createImplementationJeeComponentType(EjbModuleInfo ejbModule); - ComponentType createImplementationJeeComponentType(JavaEEApplicationInfo appInfo); + + // The JEEImplemenation model is a composite and so we have to fluff + // up the composite contents to match the JEE artifact + void createImplementationJeeComposite(EjbModuleInfo ejbModule, Composite composite); + void createImplementationJeeComposite(JavaEEApplicationInfo appInfo, Composite composite); } diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEOptionalExtension.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEOptionalExtension.java index 3461b149e4..50a449ce78 100644 --- a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEOptionalExtension.java +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEOptionalExtension.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.contribution.jee; import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; /** * Compute componentType with Remote EJB references translating into SCA references and env-entries translating into @@ -27,9 +28,14 @@ import org.apache.tuscany.sca.assembly.ComponentType; * @version $Rev$ $Date$ */ public interface JavaEEOptionalExtension { + // The EJBImplementation and WEBImplemenation models are straight implementations so + // we deals in component types ComponentType createImplementationWebComponentType(WebModuleInfo webModule); ComponentType createImplementationEjbComponentType(EjbModuleInfo ejbModule, String ejbName); - ComponentType createImplementationJeeComponentType(WebModuleInfo webModule); - ComponentType createImplementationJeeComponentType(EjbModuleInfo ejbModule); - ComponentType createImplementationJeeComponentType(JavaEEApplicationInfo appInfo); + + // The JEEImplemenation model is a composite and so we have to fluff + // up the composite contents to match the JEE artifact + void createImplementationJeeComposite(WebModuleInfo webModule, Composite composite); + void createImplementationJeeComposite(EjbModuleInfo ejbModule, Composite composite); + void createImplementationJeeComposite(JavaEEApplicationInfo appInfo, Composite composite); } 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 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 entry0 : appInfo.getEjbModuleInfos().entrySet()) { EjbModuleInfo ejbModule = entry0.getValue(); for(Map.Entry 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 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 entry : ejbModule.getEjbInfos().entrySet()) { EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo.beanName); + // Process Remote EJB References for(Map.Entry 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 entry0 : appInfo.getEjbModuleInfos().entrySet()) { EjbModuleInfo ejbModule = entry0.getValue(); for(Map.Entry entry : ejbModule.getEjbInfos().entrySet()) { EjbInfo ejbInfo = entry.getValue(); + + Component component = findComponent(composite, ejbInfo.beanName); + // Process Remote EJB References for(Map.Entry 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); + } } diff --git a/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/JEEImplementation.java b/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/JEEImplementation.java index 90b71223b4..779ac976ee 100644 --- a/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/JEEImplementation.java +++ b/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/JEEImplementation.java @@ -18,14 +18,14 @@ */ package org.apache.tuscany.sca.implementation.jee; -import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Composite; /** * The model representing a JEE implementation in an SCA assembly model. * * @version $Rev$ $Date$ */ -public interface JEEImplementation extends Implementation { +public interface JEEImplementation extends Composite { /** * Returns the archive. diff --git a/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/impl/JEEImplementationImpl.java b/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/impl/JEEImplementationImpl.java index 4d16dbf35d..39f3c12816 100644 --- a/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/impl/JEEImplementationImpl.java +++ b/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/impl/JEEImplementationImpl.java @@ -19,7 +19,7 @@ package org.apache.tuscany.sca.implementation.jee.impl; import org.apache.tuscany.sca.assembly.ConstrainingType; -import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; +import org.apache.tuscany.sca.assembly.impl.CompositeImpl; import org.apache.tuscany.sca.implementation.jee.JEEImplementation; /** @@ -27,7 +27,7 @@ import org.apache.tuscany.sca.implementation.jee.JEEImplementation; * * @version $Rev$ $Date$ */ -public class JEEImplementationImpl extends ImplementationImpl implements JEEImplementation { +public class JEEImplementationImpl extends CompositeImpl implements JEEImplementation { private String archive; @@ -56,4 +56,6 @@ public class JEEImplementationImpl extends ImplementationImpl implements JEEImpl public void setArchive(String archive) { this.archive = archive; } + + } diff --git a/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java b/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java index 072394df75..53bc9fab32 100644 --- a/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java +++ b/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java @@ -185,21 +185,19 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem unresolved.setUri(URI.create("WEB-INF/web.composite")); ModelObject resolved = resolver.resolveModel(ModelObject.class, unresolved); if(resolved != unresolved) { - // Found web composite + // Found web composite so the war itself must have been the contribution Composite appComposite = (Composite)resolved.getObject(); - implementation.getServices().addAll(appComposite.getServices()); - implementation.getReferences().addAll(appComposite.getReferences()); - implementation.getProperties().addAll(appComposite.getProperties()); + mergeCompositeInfo(appComposite, implementation); } // TODO: Obtain includeDefaults value from the composite boolean includeDefaults = false; if(includeDefaults || resolved == unresolved) { + // there is either no application composite or we are ignoring it as the + // war is nested inside another contribution if(jeeOptionalExtension != null) { - ComponentType ct = jeeOptionalExtension.createImplementationJeeComponentType((WebModuleInfo)moduleInfo); - implementation.getReferences().addAll(ct.getReferences()); - implementation.getProperties().addAll(ct.getProperties()); + jeeOptionalExtension.createImplementationJeeComposite((WebModuleInfo)moduleInfo, implementation); } } } else if(moduleInfo instanceof EjbModuleInfo) { @@ -208,11 +206,9 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem unresolved.setUri(URI.create("META-INF/ejb-jar.composite")); ModelObject resolved = resolver.resolveModel(ModelObject.class, unresolved); if(resolved != unresolved) { - // Found ejb-jar composite + // Found ejb-jar composite so the ejb jar itself must have been the contribution Composite appComposite = (Composite)resolved.getObject(); - implementation.getServices().addAll(appComposite.getServices()); - implementation.getReferences().addAll(appComposite.getReferences()); - implementation.getProperties().addAll(appComposite.getProperties()); + mergeCompositeInfo(appComposite, implementation); } // TODO: Obtain includeDefaults value from the composite @@ -220,14 +216,11 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem if(includeDefaults || resolved == unresolved) { if(jeeExtension != null) { - ComponentType ct = jeeExtension.createImplementationJeeComponentType((EjbModuleInfo)moduleInfo); - implementation.getServices().addAll(ct.getServices()); + jeeExtension.createImplementationJeeComposite((EjbModuleInfo)moduleInfo, implementation); + } if(jeeOptionalExtension != null) { - ComponentType ct = jeeOptionalExtension.createImplementationJeeComponentType((EjbModuleInfo)moduleInfo); - implementation.getServices().addAll(ct.getServices()); - implementation.getReferences().addAll(ct.getReferences()); - implementation.getProperties().addAll(ct.getProperties()); + jeeOptionalExtension.createImplementationJeeComposite((EjbModuleInfo)moduleInfo, implementation); } } } else if(moduleInfo instanceof JavaEEApplicationInfo) { @@ -246,10 +239,9 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem } if(appComposite != null) { - // Found application composite - implementation.getServices().addAll(appComposite.getServices()); - implementation.getReferences().addAll(appComposite.getReferences()); - implementation.getProperties().addAll(appComposite.getProperties()); + // Found application composite so copy it's details across into + // the implementation (which is itself a composite) + mergeCompositeInfo(appComposite, implementation); } // TODO: Obtain includeDefaults value from the composite @@ -257,20 +249,37 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem if(includeDefaults || appComposite == null) { if(jeeExtension != null) { - ComponentType ct = jeeExtension.createImplementationJeeComponentType((JavaEEApplicationInfo)moduleInfo); - implementation.getServices().addAll(ct.getServices()); + jeeExtension.createImplementationJeeComposite((JavaEEApplicationInfo)moduleInfo, implementation); } if(jeeOptionalExtension != null) { - ComponentType ct = jeeOptionalExtension.createImplementationJeeComponentType((JavaEEApplicationInfo)moduleInfo); - implementation.getServices().addAll(ct.getServices()); - implementation.getReferences().addAll(ct.getReferences()); - implementation.getProperties().addAll(ct.getProperties()); + jeeOptionalExtension.createImplementationJeeComposite((JavaEEApplicationInfo)moduleInfo, implementation); } } } } implementation.setUnresolved(false); } + + private void mergeCompositeInfo(Composite fromComposite, Composite intoComposite){ + intoComposite.getApplicablePolicySets().addAll(fromComposite.getApplicablePolicySets()); + intoComposite.getAttributeExtensions().addAll(fromComposite.getAttributeExtensions()); + intoComposite.setAutowire(fromComposite.getAutowire()); + intoComposite.getComponents().addAll(fromComposite.getComponents()); + intoComposite.setConstrainingType(fromComposite.getConstrainingType()); + intoComposite.getExtensions().addAll(fromComposite.getExtensions()); + intoComposite.setLocal(fromComposite.isLocal()); + intoComposite.getIncludes().addAll(fromComposite.getIncludes()); + intoComposite.setName(fromComposite.getName()); + intoComposite.getPolicySets().addAll(fromComposite.getPolicySets()); + intoComposite.getProperties().addAll(fromComposite.getProperties()); + intoComposite.getReferences().addAll(fromComposite.getReferences()); + intoComposite.getRequiredIntents().addAll(fromComposite.getRequiredIntents()); + intoComposite.getServices().addAll(fromComposite.getServices()); + intoComposite.setType(fromComposite.getType()); + intoComposite.setUnresolved(fromComposite.isUnresolved()); + intoComposite.setURI(fromComposite.getURI()); + intoComposite.getWires().addAll(fromComposite.getWires()); + } public void write(JEEImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { -- cgit v1.2.3