diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-15 00:26:00 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-15 00:26:00 +0000 |
commit | d5f1d093fe6fa491cdec392dca7137639e98d149 (patch) | |
tree | b98c79d8231a2617ee1dce43b1782d30d93686bc /branches/sca-android/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java | |
parent | f4e3e383071b6947d56794d9af5e9e6438aa3235 (diff) |
Pulled a recent revision of trunk into the sca-android branch, to apply the android patches from JIRA TUSCANY-2440 to it.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@695318 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-android/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java')
-rw-r--r-- | branches/sca-android/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/branches/sca-android/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java b/branches/sca-android/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java new file mode 100644 index 0000000000..58821b767d --- /dev/null +++ b/branches/sca-android/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/WebModuleProcessor.java @@ -0,0 +1,160 @@ +/* + * 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.WebModule; +import org.apache.openejb.jee.EjbRef; +import org.apache.openejb.jee.EjbReference; +import org.apache.openejb.jee.EnvEntry; +import org.apache.openejb.jee.WebApp; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +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.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.implementation.web.WebImplementation; +import org.apache.tuscany.sca.implementation.web.WebImplementationFactory; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +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 = helper.createComponentType(); + + WebApp webApp = webModule.getWebApp(); + ClassLoader classLoader = webModule.getClassLoader(); + + // Process Remote EJB References + for (Map.Entry<String, EjbRef> entry : webApp.getEjbRefMap().entrySet()) { + EjbRef ejbRef = entry.getValue(); + if (ejbRef.getRefType().compareTo(EjbReference.Type.REMOTE) != 0) { + // Only Remote EJB references need to be considered. + // Skip the current one as it is a remote reference. + continue; + } + String referenceName = entry.getKey(); + referenceName = referenceName.replace("/", "_"); + Reference reference = helper.createComponentReference(); + reference.setName(referenceName); + InterfaceContract ic = null; + try { + Class<?> clazz = classLoader.loadClass(ejbRef.getInterface()); + ic = helper.createInterfaceContract(clazz); + } catch (Exception e) { + componentType = null; + throw new ContributionException(e); + } + reference.setInterfaceContract(ic); + reference.getRequiredIntents().add(AssemblyHelper.EJB_INTENT); + componentType.getReferences().add(reference); + } + + // Process env-entries to compute properties + 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)) { + continue; + } + String propertyName = entry.getKey(); + propertyName = propertyName.replace("/", "_"); + String value = envEntry.getEnvEntryValue(); + Property property = helper.createComponentProperty(); + property.setName(propertyName); + property.setXSDType(AssemblyHelper.ALLOWED_ENV_ENTRY_TYPES.get(type)); + property.setValue(value); + componentType.getProperties().add(property); + } + + return componentType; + } + + public Composite getWebAppComposite() throws ContributionException { + getWebAppComponentType(); + + Composite composite = helper.createComposite(); + + ModelFactoryExtensionPoint mfep = new DefaultModelFactoryExtensionPoint(); + WebImplementationFactory wif = mfep.getFactory(WebImplementationFactory.class); + WebImplementation impl = wif.createWebImplementation(); + impl.setWebURI(webModule.getModuleId()); + + // Create component + Component component = helper.createComponent(); + String componentName = webModule.getModuleId(); + component.setName(componentName); + component.setImplementation(impl); + + // Add references + for (Reference reference : componentType.getReferences()) { + ComponentReference componentReference = helper.createComponentReference(); + componentReference.setReference(reference); + componentReference.setInterfaceContract(reference.getInterfaceContract()); + componentReference.getRequiredIntents().addAll(reference.getRequiredIntents()); + component.getReferences().add(componentReference); + } + + // Add properties + for (Property property : componentType.getProperties()) { + ComponentProperty componentProperty = helper.createComponentProperty(); + componentProperty.setProperty(property); + component.getProperties().add(componentProperty); + } + + // Add component to composite + composite.getComponents().add(component); + + // Add composite references + for (ComponentReference reference : component.getReferences()) { + CompositeReference compositeReference = helper.createCompositeReference(); + compositeReference.setInterfaceContract(reference.getInterfaceContract()); + compositeReference.getRequiredIntents().addAll(reference.getRequiredIntents()); + compositeReference.getPromotedReferences().add(reference); + composite.getReferences().add(compositeReference); + } + + return composite; + } +} |