You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2009/04/23 14:48:20 UTC

svn commit: r767905 - in /tuscany/branches/sca-java-1.x: itest/implementation-jee-external-ear/src/main/resources/META-INF/services/ itest/implementation-jee-external-ear/src/test/java/itest/ modules/contribution-jee/src/main/java/org/apache/tuscany/sc...

Author: antelder
Date: Thu Apr 23 12:48:19 2009
New Revision: 767905

URL: http://svn.apache.org/viewvc?rev=767905&view=rev
Log:
Add an external ear modelresolver approach to the jee itest

Added:
    tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
    tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/test/java/itest/SomeCustomModelResolver.java
    tuscany/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java
Modified:
    tuscany/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java

Added: tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver?rev=767905&view=auto
==============================================================================
--- tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver (added)
+++ tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver Thu Apr 23 12:48:19 2009
@@ -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

Added: tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/test/java/itest/SomeCustomModelResolver.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/test/java/itest/SomeCustomModelResolver.java?rev=767905&view=auto
==============================================================================
--- tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/test/java/itest/SomeCustomModelResolver.java (added)
+++ tuscany/branches/sca-java-1.x/itest/implementation-jee-external-ear/src/test/java/itest/SomeCustomModelResolver.java Thu Apr 23 12:48:19 2009
@@ -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;
+    }
+
+}

Added: tuscany/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java?rev=767905&view=auto
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java (added)
+++ tuscany/branches/sca-java-1.x/modules/contribution-jee/src/main/java/org/apache/tuscany/sca/contribution/jee/ExternalEarInfo.java Thu Apr 23 12:48:19 2009
@@ -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();
+}

Modified: tuscany/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java?rev=767905&r1=767904&r2=767905&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/implementation-jee/src/main/java/org/apache/tuscany/sca/implementation/jee/xml/JEEImplementationProcessor.java Thu Apr 23 12:48:19 2009
@@ -20,7 +20,6 @@
 
 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.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.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 @@
 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 @@
         // 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 @@
                 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 @@
                 }
                 // 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());