From c4bec56bbd6b8d145ecbe4132e899c5bd89f75ed Mon Sep 17 00:00:00 2001 From: vamsic007 Date: Sat, 25 Apr 2009 17:17:11 +0000 Subject: TUSCANY-2977 determine implementation.jee component type from application composite if one is available o Added a model object resolver to obtain application composite using uri git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@768567 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/contribution/jee/ModelObject.java | 32 +++++++ .../contribution/jee/ModelObjectModelResolver.java | 73 ++++++++++++++++ .../sca/contribution/jee/impl/ModelObjectImpl.java | 51 ++++++++++++ ...tuscany.sca.contribution.resolver.ModelResolver | 3 +- .../jee/xml/JEEImplementationProcessor.java | 97 +++++++++++++++++----- 5 files changed, 232 insertions(+), 24 deletions(-) create mode 100644 branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObject.java create mode 100644 branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObjectModelResolver.java create mode 100644 branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/ModelObjectImpl.java diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObject.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObject.java new file mode 100644 index 0000000000..e981339733 --- /dev/null +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObject.java @@ -0,0 +1,32 @@ +/* + * 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.net.URI; + +/** + * @version $Rev$ $Date$ + */ +public interface ModelObject { + URI getUri(); + void setUri(URI uri); + + Object getObject(); + void setObject(Object obj); +} diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObjectModelResolver.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObjectModelResolver.java new file mode 100644 index 0000000000..aa24dcac2c --- /dev/null +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ModelObjectModelResolver.java @@ -0,0 +1,73 @@ +/* + * 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.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.jee.impl.ModelObjectImpl; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for obtaining any model object using URI. + * + * @version $Rev$ $Date$ + */ +public class ModelObjectModelResolver implements ModelResolver { + + private Map map = new HashMap(); + private Contribution contribution; + + public ModelObjectModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + public void addModel(Object resolved) { + map.put(((ModelObject)resolved).getUri(), (ModelObject)resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(((ModelObject)resolved).getUri()); + } + + public T resolveModel(Class modelClass, T unresolved) { + URI uri = ((ModelObject)unresolved).getUri(); + if (uri != null) { + ModelObject resolved = (ModelObject) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } else { + for(Artifact artifact : contribution.getArtifacts()) { + if(artifact.getURI().equals(uri.toString())) { + resolved = new ModelObjectImpl(); + resolved.setUri(uri); + resolved.setObject(artifact.getModel()); + return modelClass.cast(resolved); + } + } + } + } + return unresolved; + } +} diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/ModelObjectImpl.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/ModelObjectImpl.java new file mode 100644 index 0000000000..95050dfd88 --- /dev/null +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/impl/ModelObjectImpl.java @@ -0,0 +1,51 @@ +/* + * 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 java.net.URI; + +import org.apache.tuscany.sca.contribution.jee.ModelObject; + +/** + * @version $Rev$ $Date$ + */ +public class ModelObjectImpl implements ModelObject { + + private URI uri; + private Object obj; + + public ModelObjectImpl() { + } + + public Object getObject() { + return obj; + } + + public void setObject(Object obj) { + this.obj = obj; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } +} diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/branches/sca-java-1.x/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver index 8aae799e5b..90ff87e0b1 100644 --- a/branches/sca-java-1.x/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver +++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -17,4 +17,5 @@ org.apache.tuscany.sca.contribution.jee.WebModuleModelResolver;model=org.apache.tuscany.sca.contribution.jee.WebModuleInfo org.apache.tuscany.sca.contribution.jee.EjbModuleModelResolver;model=org.apache.tuscany.sca.contribution.jee.EjbModuleInfo -org.apache.tuscany.sca.contribution.jee.JavaEEApplicationModelResolver;model=org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo \ No newline at end of file +org.apache.tuscany.sca.contribution.jee.JavaEEApplicationModelResolver;model=org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo +org.apache.tuscany.sca.contribution.jee.ModelObjectModelResolver;model=org.apache.tuscany.sca.contribution.jee.ModelObject 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 d9f80a5e00..4b1d45cbc5 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 @@ -29,14 +29,17 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.xml.Constants; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.jee.ModelObject; import org.apache.tuscany.sca.contribution.jee.EjbModuleInfo; import org.apache.tuscany.sca.contribution.jee.ExternalEarInfo; import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo; import org.apache.tuscany.sca.contribution.jee.JavaEEExtension; import org.apache.tuscany.sca.contribution.jee.JavaEEOptionalExtension; import org.apache.tuscany.sca.contribution.jee.WebModuleInfo; +import org.apache.tuscany.sca.contribution.jee.impl.ModelObjectImpl; import org.apache.tuscany.sca.contribution.jee.impl.EjbModuleInfoImpl; import org.apache.tuscany.sca.contribution.jee.impl.JavaEEApplicationInfoImpl; import org.apache.tuscany.sca.contribution.jee.impl.WebModuleInfoImpl; @@ -160,36 +163,84 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem } if(moduleInfo instanceof WebModuleInfo) { - if(jeeOptionalExtension != null) { - ComponentType ct = jeeOptionalExtension.createImplementationJeeComponentType((WebModuleInfo)moduleInfo); - implementation.getReferences().addAll(ct.getReferences()); - implementation.getProperties().addAll(ct.getProperties()); + // Check for web composite + ModelObject unresolved = new ModelObjectImpl(); + unresolved.setUri(URI.create("WEB-INF/web.composite")); + ModelObject resolved = resolver.resolveModel(ModelObject.class, unresolved); + if(resolved != unresolved) { + // Found web composite + Composite appComposite = (Composite)resolved.getObject(); + implementation.getServices().addAll(appComposite.getServices()); + implementation.getReferences().addAll(appComposite.getReferences()); + implementation.getProperties().addAll(appComposite.getProperties()); + } + + // TODO: Obtain includeDefaults value from the composite + boolean includeDefaults = false; + + if(includeDefaults || resolved == unresolved) { + if(jeeOptionalExtension != null) { + ComponentType ct = jeeOptionalExtension.createImplementationJeeComponentType((WebModuleInfo)moduleInfo); + implementation.getReferences().addAll(ct.getReferences()); + implementation.getProperties().addAll(ct.getProperties()); + } } - // TODO: check for web composite } else if(moduleInfo instanceof EjbModuleInfo) { - if(jeeExtension != null) { - ComponentType ct = jeeExtension.createImplementationJeeComponentType((EjbModuleInfo)moduleInfo); - implementation.getServices().addAll(ct.getServices()); + // Check for ejb-jar composite + ModelObject unresolved = new ModelObjectImpl(); + unresolved.setUri(URI.create("META-INF/ejb-jar.composite")); + ModelObject resolved = resolver.resolveModel(ModelObject.class, unresolved); + if(resolved != unresolved) { + // Found ejb-jar composite + Composite appComposite = (Composite)resolved.getObject(); + implementation.getServices().addAll(appComposite.getServices()); + implementation.getReferences().addAll(appComposite.getReferences()); + implementation.getProperties().addAll(appComposite.getProperties()); } - if(jeeOptionalExtension != null) { - ComponentType ct = jeeOptionalExtension.createImplementationJeeComponentType((EjbModuleInfo)moduleInfo); - implementation.getServices().addAll(ct.getServices()); - implementation.getReferences().addAll(ct.getReferences()); - implementation.getProperties().addAll(ct.getProperties()); + + // TODO: Obtain includeDefaults value from the composite + boolean includeDefaults = false; + + if(includeDefaults || resolved == unresolved) { + if(jeeExtension != null) { + ComponentType ct = jeeExtension.createImplementationJeeComponentType((EjbModuleInfo)moduleInfo); + implementation.getServices().addAll(ct.getServices()); + } + if(jeeOptionalExtension != null) { + ComponentType ct = jeeOptionalExtension.createImplementationJeeComponentType((EjbModuleInfo)moduleInfo); + implementation.getServices().addAll(ct.getServices()); + implementation.getReferences().addAll(ct.getReferences()); + implementation.getProperties().addAll(ct.getProperties()); + } } - // TODO: check for ejb-jar composite } else if(moduleInfo instanceof JavaEEApplicationInfo) { - if(jeeExtension != null) { - ComponentType ct = jeeExtension.createImplementationJeeComponentType((JavaEEApplicationInfo)moduleInfo); - implementation.getServices().addAll(ct.getServices()); + // Check for application composite + ModelObject unresolved = new ModelObjectImpl(); + unresolved.setUri(URI.create("META-INF/application.composite")); + ModelObject resolved = resolver.resolveModel(ModelObject.class, unresolved); + if(resolved != unresolved) { + // Found application composite + Composite appComposite = (Composite)resolved.getObject(); + implementation.getServices().addAll(appComposite.getServices()); + implementation.getReferences().addAll(appComposite.getReferences()); + implementation.getProperties().addAll(appComposite.getProperties()); } - if(jeeOptionalExtension != null) { - ComponentType ct = jeeOptionalExtension.createImplementationJeeComponentType((JavaEEApplicationInfo)moduleInfo); - implementation.getServices().addAll(ct.getServices()); - implementation.getReferences().addAll(ct.getReferences()); - implementation.getProperties().addAll(ct.getProperties()); + + // TODO: Obtain includeDefaults value from the composite + boolean includeDefaults = false; + + if(includeDefaults || resolved == unresolved) { + if(jeeExtension != null) { + ComponentType ct = jeeExtension.createImplementationJeeComponentType((JavaEEApplicationInfo)moduleInfo); + implementation.getServices().addAll(ct.getServices()); + } + if(jeeOptionalExtension != null) { + ComponentType ct = jeeOptionalExtension.createImplementationJeeComponentType((JavaEEApplicationInfo)moduleInfo); + implementation.getServices().addAll(ct.getServices()); + implementation.getReferences().addAll(ct.getReferences()); + implementation.getProperties().addAll(ct.getProperties()); + } } - // TODO: check for application composite } } implementation.setUnresolved(false); -- cgit v1.2.3