diff options
author | vamsic007 <vamsic007@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-12 14:30:41 +0000 |
---|---|---|
committer | vamsic007 <vamsic007@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-12 14:30:41 +0000 |
commit | ed705b30f8f693b700696ee69cf1def0b37ce5c8 (patch) | |
tree | 856da01197dde53e40f4ac2191db9d4e17aae5cd /java | |
parent | 64340596e434f75c0f953f7bd55a9efabac82d5a (diff) |
JavaEE application as a component
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@685166 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
5 files changed, 189 insertions, 0 deletions
diff --git a/java/sca/modules/contribution-jee/pom.xml b/java/sca/modules/contribution-jee/pom.xml index 5910e75608..d7ad035d82 100644 --- a/java/sca/modules/contribution-jee/pom.xml +++ b/java/sca/modules/contribution-jee/pom.xml @@ -65,6 +65,13 @@ <version>1.4-SNAPSHOT</version> <!--scope>runtime</scope--> </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-jee</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + <dependency> <groupId>org.apache.openejb</groupId> <artifactId>openejb-core</artifactId> diff --git a/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBModuleProcessor.java b/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBModuleProcessor.java index 493f704fe0..41107b5cba 100644 --- a/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBModuleProcessor.java +++ b/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/EJBModuleProcessor.java @@ -171,6 +171,7 @@ public class EJBModuleProcessor { for (Service service : componentType.getServices()) { ComponentService componentService = helper.createComponentService(); componentService.setService(service); + componentService.setInterfaceContract(service.getInterfaceContract()); component.getServices().add(componentService); } @@ -178,6 +179,7 @@ public class EJBModuleProcessor { for (Reference reference : componentType.getReferences()) { ComponentReference componentReference = helper.createComponentReference(); componentReference.setReference(reference); + componentReference.setInterfaceContract(reference.getInterfaceContract()); component.getReferences().add(componentReference); } diff --git a/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationProcessor.java b/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationProcessor.java new file mode 100644 index 0000000000..d709a1b07e --- /dev/null +++ b/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationProcessor.java @@ -0,0 +1,95 @@ +/* + * 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 java.util.Map; + +import org.apache.openejb.config.AppModule; +import org.apache.openejb.config.EjbModule; +import org.apache.openejb.jee.EnterpriseBean; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * @version $Rev$ $Date$ + */ +public class JavaEEApplicationProcessor { + private AppModule appModule; + private ComponentType componentType; + private AssemblyHelper helper; + + public JavaEEApplicationProcessor(AppModule appModule, AssemblyHelper helper) { + super(); + this.appModule = appModule; + this.helper = helper; + } + + public JavaEEApplicationProcessor(AppModule module) { + appModule = module; + helper = new AssemblyHelper(); + } + + public ComponentType getJavaEEAppComponentType() throws ContributionException { + if (componentType != null) { + return componentType; + } + componentType = helper.createComponentType(); + + // Process all EJB modules + for(EjbModule ejbModule : appModule.getEjbModules()) { + EJBModuleProcessor emp = new EJBModuleProcessor(ejbModule, helper); + Map<String, ComponentType> ejbComponentTypes = emp.getEjbComponentTypes(); + for(Map.Entry<String, ComponentType> entry : ejbComponentTypes.entrySet()) { + String beanName = entry.getKey(); + ComponentType ct = entry.getValue(); + EnterpriseBean bean = ejbModule.getEjbJar().getEnterpriseBeansByEjbName().get(beanName); + String mappedName = bean.getMappedName() != null ? bean.getMappedName() : beanName; + + String mappedName2 = mappedName.replace("/", "_"); + // Add all services from the bean + for(Service service : ct.getServices()) { + Service service2 = helper.createComponentService(); + String serviceName = mappedName2 + "_"+service.getName(); + service2.setName(serviceName); + service2.setInterfaceContract(service.getInterfaceContract()); + componentType.getServices().add(service2); + } + + String beanName2 = beanName.replace("/", "_"); + // Add all references + for(Reference reference : ct.getReferences()) { + Reference reference2 = helper.createComponentReference(); + String referenceName = beanName2+"_"+reference.getName(); + reference2.setName(referenceName); + reference2.setInterfaceContract(reference.getInterfaceContract()); + componentType.getReferences().add(reference2); + } + } + emp.getEjbAppComponentType(); + } + + // Process web modules (?) + // FIXME: SCA JEE Spec 1.0 - Sec 7.1.3 says nothing about web modules + + return componentType; + } +} diff --git a/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java b/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java index 9fdcb32de5..f784252b61 100644 --- a/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java +++ b/java/sca/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java @@ -130,6 +130,7 @@ public class WebModuleProcessor { for (Reference reference : componentType.getReferences()) { ComponentReference componentReference = helper.createComponentReference(); componentReference.setReference(reference); + componentReference.setInterfaceContract(reference.getInterfaceContract()); component.getReferences().add(componentReference); } diff --git a/java/sca/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationProcessorTestCase.java b/java/sca/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationProcessorTestCase.java new file mode 100644 index 0000000000..85b5e87e7f --- /dev/null +++ b/java/sca/modules/contribution-jee/src/test/java/org/apache/tuscany/sca/contribution/jee/JavaEEApplicationProcessorTestCase.java @@ -0,0 +1,84 @@ +/* + * 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 java.util.HashSet; +import java.util.Set; + +import org.apache.openejb.config.AppModule; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +public class JavaEEApplicationProcessorTestCase { + + AppModule appModule; + + @Before + public void setUp() throws Exception { + String jarFilePath = "target/test-classes/ejb-injection-sample.ear"; + JavaEEModuleHelper jmh = new JavaEEModuleHelper(); + appModule = jmh.getMetadataCompleteModules(jarFilePath); + } + + @Test + public void testJavaEEAppContribution() throws Exception { + JavaEEApplicationProcessor jap = new JavaEEApplicationProcessor(appModule); + + ComponentType ct = jap.getJavaEEAppComponentType(); + + // Check the services + Assert.assertEquals(6, ct.getServices().size()); + + Set<String> expectedServiceNames = new HashSet<String>(); + expectedServiceNames.add("BankBean_Bank"); + expectedServiceNames.add("ConverterBean_Converter"); + expectedServiceNames.add("ConverterBean_ConverterLocal"); + expectedServiceNames.add("Converter2Bean_ConverterLocal"); + expectedServiceNames.add("InvoiceBean_Invoice"); + expectedServiceNames.add("PurchaseOrderBean_PurchaseOrder"); + + Set<String> serviceNames = new HashSet<String>(); + for(Service service : ct.getServices()) { + serviceNames.add(service.getName()); + } + + Assert.assertEquals(expectedServiceNames, serviceNames); + + // Check the references + Assert.assertEquals(1, ct.getReferences().size()); + + Set<String> expectedReferenceNames = new HashSet<String>(); + expectedReferenceNames.add("BankBean_simple.BankBean_converter"); + + Set<String> referenceNames = new HashSet<String>(); + for (Reference r : ct.getReferences()) { + referenceNames.add(r.getName()); + } + + Assert.assertEquals(expectedReferenceNames, referenceNames); + } +} |