summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-04-23 12:48:19 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-04-23 12:48:19 +0000
commit310e9fb3277f36407eac8146745517d90ba15285 (patch)
tree8d5a46a7385df9599ee2be620b62bb4b3a1b8c55
parent39f2edc10dce04cf4b84f7c68af95dc1dfb446df (diff)
Add an external ear modelresolver approach to the jee itest
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@767905 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--branches/sca-java-1.x/itest/implementation-jee-external-ear/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver18
-rw-r--r--branches/sca-java-1.x/itest/implementation-jee-external-ear/src/test/java/itest/SomeCustomModelResolver.java77
-rw-r--r--branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java28
-rw-r--r--branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java32
4 files changed, 132 insertions, 23 deletions
diff --git a/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
new file mode 100644
index 0000000000..76fa697c6a
--- /dev/null
+++ b/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
@@ -0,0 +1,18 @@
+# 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.
+
+itest.SomeCustomModelResolver;model=org.apache.tuscany.sca.contribution.jee.ExternalEarInfo
diff --git a/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/test/java/itest/SomeCustomModelResolver.java b/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/test/java/itest/SomeCustomModelResolver.java
new file mode 100644
index 0000000000..b534297148
--- /dev/null
+++ b/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/test/java/itest/SomeCustomModelResolver.java
@@ -0,0 +1,77 @@
+/*
+ * 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 itest;
+
+import java.io.File;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.jee.ExternalEarInfo;
+import org.apache.tuscany.sca.contribution.jee.JavaEEApplicationInfo;
+import org.apache.tuscany.sca.contribution.jee.JavaEEIntrospector;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+public class SomeCustomModelResolver implements ModelResolver {
+
+ private Map<URI, ExternalEarInfo> map = new HashMap<URI, ExternalEarInfo>();
+ private JavaEEIntrospector jeeIntrospector;
+
+
+ public SomeCustomModelResolver(Contribution contribution, ExtensionPointRegistry extensionPoints) {
+ jeeIntrospector = extensionPoints.getExtensionPoint(JavaEEIntrospector.class);
+ }
+
+ public void addModel(Object resolved) {
+ ExternalEarInfo jeeApp = (ExternalEarInfo)resolved;
+ map.put(jeeApp.getAppInfo().getUri(), jeeApp);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(((ExternalEarInfo)resolved).getAppInfo().getUri());
+ }
+
+ public <T> T resolveModel(final Class<T> modelClass, T unresolved) {
+ URI uri = ((ExternalEarInfo)unresolved).getAppInfo().getUri();
+ if (uri != null) {
+ ExternalEarInfo resolved = (ExternalEarInfo) map.get(uri);
+ if (resolved != null) {
+ return modelClass.cast(resolved);
+ } else {
+ try {
+ File f = new File(uri.toString());
+ final JavaEEApplicationInfo o = jeeIntrospector.introspectJeeArchive(f.toURI().toURL());
+ return (T)new ExternalEarInfo() {
+ public JavaEEApplicationInfo getAppInfo() {
+ return (JavaEEApplicationInfo)o;
+ }
+ };
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ return unresolved;
+ }
+
+}
diff --git a/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java
new file mode 100644
index 0000000000..509ee7d776
--- /dev/null
+++ b/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+
+/**
+ * @version $Rev: 755722 $ $Date: 2009-03-18 20:23:02 +0000 (Wed, 18 Mar 2009) $
+ */
+public interface ExternalEarInfo {
+
+ JavaEEApplicationInfo getAppInfo();
+}
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 e8be60f671..d9f80a5e00 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
@@ -20,7 +20,6 @@ package org.apache.tuscany.sca.implementation.jee.xml;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
-import java.io.File;
import java.net.URI;
import javax.xml.namespace.QName;
@@ -33,9 +32,9 @@ import org.apache.tuscany.sca.assembly.ComponentType;
import org.apache.tuscany.sca.assembly.xml.Constants;
import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
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.JavaEEIntrospector;
import org.apache.tuscany.sca.contribution.jee.JavaEEOptionalExtension;
import org.apache.tuscany.sca.contribution.jee.WebModuleInfo;
import org.apache.tuscany.sca.contribution.jee.impl.EjbModuleInfoImpl;
@@ -47,7 +46,6 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.service.ContributionReadException;
import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.implementation.jee.JEEImplementation;
import org.apache.tuscany.sca.implementation.jee.JEEImplementationFactory;
import org.apache.tuscany.sca.monitor.Monitor;
@@ -60,17 +58,13 @@ import org.apache.tuscany.sca.monitor.Monitor;
public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<JEEImplementation> {
private static final QName IMPLEMENTATION_JEE = new QName(Constants.SCA10_NS, "implementation.jee");
- private ExtensionPointRegistry extensionPoints;
private AssemblyFactory assemblyFactory;
private JEEImplementationFactory implementationFactory;
private JavaEEExtension jeeExtension;
private JavaEEOptionalExtension jeeOptionalExtension;
private Monitor monitor;
-
- public JEEImplementationProcessor(ExtensionPointRegistry extensionPoints, Monitor monitor) {
- this.extensionPoints = extensionPoints;
- ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ public JEEImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
this.implementationFactory = modelFactories.getFactory(JEEImplementationFactory.class);
this.jeeExtension = modelFactories.getFactory(JavaEEExtension.class);
@@ -117,7 +111,6 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem
// Resolve the component type
String uri = implementation.getURI();
String archive = implementation.getArchive();
- boolean unresolvedEar = false;;
if (uri != null) {
Object moduleInfo = null;
if(uri.equals("")) {
@@ -156,11 +149,14 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem
ejbModuleInfo = resolver.resolveModel(EjbModuleInfo.class, ejbModuleInfo);
moduleInfo = ejbModuleInfo;
} else if(uri.endsWith(".ear")) {
- JavaEEApplicationInfo appInfo = new JavaEEApplicationInfoImpl();
+ final JavaEEApplicationInfo appInfo = new JavaEEApplicationInfoImpl();
appInfo.setUri(URI.create(archive));
- JavaEEApplicationInfo resolved = resolver.resolveModel(JavaEEApplicationInfo.class, appInfo);
- unresolvedEar = resolved == appInfo;
- moduleInfo = appInfo;
+ ExternalEarInfo ee = new ExternalEarInfo() {
+ public JavaEEApplicationInfo getAppInfo() {
+ return appInfo;
+ }};
+ ee = resolver.resolveModel(ExternalEarInfo.class, ee);
+ moduleInfo = ee.getAppInfo();
}
if(moduleInfo instanceof WebModuleInfo) {
@@ -183,16 +179,6 @@ public class JEEImplementationProcessor extends BaseStAXArtifactProcessor implem
}
// TODO: check for ejb-jar composite
} else if(moduleInfo instanceof JavaEEApplicationInfo) {
- if (unresolvedEar) {
- JavaEEIntrospector jeeIntrospector = extensionPoints.getExtensionPoint(JavaEEIntrospector.class);
- try {
- File f = new File(((JavaEEApplicationInfo)moduleInfo).getUri().toString());
- moduleInfo = jeeIntrospector.introspectJeeArchive(f.toURI().toURL());
- } catch (Exception e) {
- throw new ContributionResolveException(e);
- }
- }
-
if(jeeExtension != null) {
ComponentType ct = jeeExtension.createImplementationJeeComponentType((JavaEEApplicationInfo)moduleInfo);
implementation.getServices().addAll(ct.getServices());