From 62dfafcd597b775154b63ecf5e7edad35ca3a9b8 Mon Sep 17 00:00:00 2001 From: antelder Date: Thu, 19 Mar 2009 10:31:17 +0000 Subject: delete test tag git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@755899 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/DefaultJavaImportExportFactory.java | 30 -- .../tuscany/sca/contribution/java/JavaExport.java | 43 --- .../tuscany/sca/contribution/java/JavaImport.java | 58 ---- .../contribution/java/JavaImportExportFactory.java | 42 --- .../java/impl/ClassLoaderModelResolver.java | 159 --------- .../java/impl/ClassReferenceModelResolver.java | 159 --------- .../java/impl/ContributionClassLoader.java | 383 --------------------- .../sca/contribution/java/impl/JavaExportImpl.java | 58 ---- .../java/impl/JavaExportModelResolver.java | 76 ---- .../java/impl/JavaExportProcessor.java | 148 -------- .../java/impl/JavaImportExportFactoryImpl.java | 41 --- .../sca/contribution/java/impl/JavaImportImpl.java | 110 ------ .../java/impl/JavaImportModelResolver.java | 62 ---- .../java/impl/JavaImportProcessor.java | 153 -------- 14 files changed, 1522 deletions(-) delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java delete mode 100644 sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java (limited to 'sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany') diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java deleted file mode 100644 index 886c61c00a..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.java; - -import org.apache.tuscany.sca.contribution.java.impl.JavaImportExportFactoryImpl; - -/** - * Default Java Import/Export Factory implementation - * - * @version $Rev$ $Date$ - */ -public class DefaultJavaImportExportFactory extends JavaImportExportFactoryImpl implements JavaImportExportFactory { -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java deleted file mode 100644 index 41e93ec148..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.java; - -import org.apache.tuscany.sca.contribution.Export; - -/** - * Base Java Export model interface - * - * @version $Rev$ $Date$ - */ -public interface JavaExport extends Export { - /** - * Get java package that identifies the import - * - * @return The package name - */ - String getPackage(); - - /** - * Set java package that identifies the import - * - * @param packageName The package name - */ - void setPackage(String packageName); -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java deleted file mode 100644 index d3568f6283..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.java; - -import org.apache.tuscany.sca.contribution.Import; - -/** - * Base Java Import model interface - * - * @version $Rev$ $Date$ - */ -public interface JavaImport extends Import { - - /** - * Get the location used to resolve the definitions for this import - * - * @return The import location - */ - String getLocation(); - - /** - * Set the location used to resolve the definitions for this import - * - * @param location The import location - */ - void setLocation(String location); - - /** - * Get java package that identifies the import - * - * @return The package name - */ - String getPackage(); - - /** - * Set java package that identifies the import - * - * @param packageName The package name - */ - void setPackage(String packageName); -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java deleted file mode 100644 index af2ca9cd57..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.java; - -/** - * Base Java Import/Export model factory - * - * @version $Rev$ $Date$ - */ -public interface JavaImportExportFactory { - - /** - * Create a java import model object - * - * @return The new JavaImport model object - */ - JavaImport createJavaImport(); - - /** - * Create a java export model object - * - * @return The new JavaExport model object - */ - JavaExport createJavaExport(); -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java deleted file mode 100644 index 135b3fbb69..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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.java.impl; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.Import; -import org.apache.tuscany.sca.contribution.java.JavaImport; -import org.apache.tuscany.sca.contribution.resolver.ClassReference; -import org.apache.tuscany.sca.contribution.resolver.DefaultDelegatingModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; - -/** - * A Model Resolver for ClassReferences. - * - * @version $Rev$ $Date$ - */ -public class ClassLoaderModelResolver extends URLClassLoader implements ModelResolver { - private Contribution contribution; - private Map importResolvers = new HashMap(); - - private static ClassLoader parentClassLoader() { - ClassLoader parentClassLoader = ServiceDiscovery.getInstance().getServiceDiscoverer().getClass().getClassLoader(); - return parentClassLoader; - } - - public ClassLoaderModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories) throws MalformedURLException { - super(new URL[] {new URL(contribution.getLocation())}, parentClassLoader()); - this.contribution = contribution; - - // Index Java import resolvers by package name - Map> resolverMap = new HashMap>(); - for (Import import_: this.contribution.getImports()) { - if (import_ instanceof JavaImport) { - JavaImport javaImport = (JavaImport)import_; - List resolvers = resolverMap.get(javaImport.getPackage()); - if (resolvers == null) { - resolvers = new ArrayList(); - resolverMap.put(javaImport.getPackage(), resolvers); - } - resolvers.add(javaImport.getModelResolver()); - } - } - - // Create a delegating model resolver for each imported package - for (Map.Entry> entry: resolverMap.entrySet()) { - importResolvers.put(entry.getKey(), new DefaultDelegatingModelResolver(entry.getValue())); - } - } - - public void addModel(Object resolved) { - throw new IllegalStateException(); - } - - public Object removeModel(Object resolved) { - throw new IllegalStateException(); - } - - public T resolveModel(Class modelClass, T unresolved) { - if (!(unresolved instanceof ClassReference)) { - return unresolved; - } - - try { - - // Load the class and return a class reference for it - String className = ((ClassReference)unresolved).getClassName(); - Class clazz = Class.forName(className, true, this); - return modelClass.cast(new ClassReference(clazz)); - - } catch (ClassNotFoundException e) { - return unresolved; - } catch (NoClassDefFoundError e) { - return unresolved; - } - } - - @Override - public URL findResource(String name) { - - //TODO delegate to the Java import resolvers - - URL url = super.findResource(name); - return url; - } - - @Override - public Enumeration findResources(String name) throws IOException { - - //TODO delegate to the Java import resolvers - //Enumeration importedResources; - - Enumeration resources = super.findResources(name); - List allResources = new ArrayList(); - //for (; importedResources.hasMoreElements(); ) { - // allResources.add(importedResources.nextElement()); - //} - for (; resources.hasMoreElements(); ) { - allResources.add(resources.nextElement()); - } - return Collections.enumeration(allResources); - } - - @Override - protected Class findClass(String name) throws ClassNotFoundException { - - // Extract the package name - int d = name.lastIndexOf('.'); - String packageName; - if (d != -1) { - packageName = name.substring(0, d); - } else { - packageName = null; - } - - // First try to load the class using the Java import resolvers - ModelResolver importResolver = importResolvers.get(packageName); - if (importResolver != null) { - ClassReference classReference = importResolver.resolveModel(ClassReference.class, new ClassReference(name)); - if (!classReference.isUnresolved()) { - return classReference.getJavaClass(); - } - } - - // Next, try to load the class from the current contribution - Class clazz = super.findClass(name); - return clazz; - } - -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java deleted file mode 100644 index 11e13ced11..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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.java.impl; - -import java.lang.ref.WeakReference; -import java.lang.reflect.Constructor; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.resolver.ClassReference; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; - -/** - * A Model Resolver for ClassReferences. - * @deprecated Use ClassLoaderModelResolver instead - * @version $Rev: 557916 $ $Date: 2007-07-20 01:04:40 -0700 (Fri, 20 Jul 2007) $ - */ -@Deprecated() -public class ClassReferenceModelResolver implements ModelResolver { - private Contribution contribution; - private WeakReference classLoader; - private Map map = new HashMap(); - - private ModelResolver osgiResolver; - - public ClassReferenceModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories) { - this.contribution = contribution; - if (this.contribution != null) { - // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy. - // ClassLoader cl = contribution.getClassLoader(); - ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction() { - public ClassLoader run() { - return contribution.getClassLoader(); - } - }); - - if (cl == null) { - // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy. - //ClassLoader contextClassLoader = AccessController.doPrivileged(new PrivilegedAction() { - // public ClassLoader run() { - // return Thread.currentThread().getContextClassLoader(); - // } - //}); - ClassLoader contextClassLoader = ServiceDiscovery.getInstance().getServiceDiscoverer().getClass().getClassLoader(); - cl = new ContributionClassLoader(contribution, contextClassLoader); - contribution.setClassLoader(cl); - } - this.classLoader = new WeakReference(cl); - } else { - // This path should be used only for unit testing. - // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy. - // this.classLoader = new WeakReference(this.getClass().getClassLoader()); - ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction() { - public ClassLoader run() { - return this.getClass().getClassLoader(); - } - }); - this.classLoader = new WeakReference( cl ); - } - - try { - Class osgiResolverClass = - Class.forName("org.apache.tuscany.sca.contribution.osgi.impl.OSGiClassReferenceModelResolver"); - if (osgiResolverClass != null) { - Constructor constructor = - osgiResolverClass.getConstructor(Contribution.class, FactoryExtensionPoint.class); - this.osgiResolver = (ModelResolver)constructor.newInstance(contribution, modelFactories); - } - } catch (Throwable e) { - // Ignore error, non-OSGi classloading is used in this case - } - } - - public void addModel(Object resolved) { - ClassReference clazz = (ClassReference)resolved; - map.put(clazz.getClassName(), clazz); - } - - public Object removeModel(Object resolved) { - return map.remove(((ClassReference)resolved).getClassName()); - } - - - - public T resolveModel(Class modelClass, T unresolved) { - if (!(unresolved instanceof ClassReference)) { - return unresolved; - } - Object resolved = map.get(((ClassReference)unresolved).getClassName()); - - if (resolved != null) { - return modelClass.cast(resolved); - } - - //Load a class on demand - Class clazz = null; - - if (osgiResolver != null) { - resolved = osgiResolver.resolveModel(modelClass, unresolved); - clazz = ((ClassReference)resolved).getJavaClass(); - } - - if (clazz == null) { - try { - // Search contribution ClassLoader (which has visibility of classes in the contribution - // as well as explicitly imported packages from other contributions) - clazz = Class.forName(((ClassReference)unresolved).getClassName(), true, classLoader.get()); - } catch (ClassNotFoundException e) { - } catch (NoClassDefFoundError e) { - } - } - - if (clazz != null) { - //if we load the class - // Store a new ClassReference wrapping the loaded class - ClassReference classReference = new ClassReference(clazz); - map.put(clazz.getName(), classReference); - - // Return the resolved ClassReference - return modelClass.cast(classReference); - } else { - return unresolved; - } - - } - - - /*************** - * Helper methods - ***************/ - - private String getPackageName(ClassReference clazz) { - int pos = clazz.getClassName().lastIndexOf("."); - return clazz.getClassName().substring(0, pos); - } - -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java deleted file mode 100644 index 008bfec31a..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java +++ /dev/null @@ -1,383 +0,0 @@ -/* - * 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.java.impl; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashSet; - -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.Export; -import org.apache.tuscany.sca.contribution.Import; -import org.apache.tuscany.sca.contribution.java.JavaImport; - - -public class ContributionClassLoader extends URLClassLoader { -// public class ContributionClassLoader { - - private Contribution contribution; - // private b urlClassLoader; - - /** - * Constructor for contribution ClassLoader - * - * @param contribution - * @param parent - * @throws MalformedURLException - */ - public ContributionClassLoader(Contribution contribution, final ClassLoader parent) { - super(new URL[0], parent); - // Note that privileged use of getContextClassLoader have been promoted to callers. - // super(new URL[0], parent == null?Thread.currentThread().getContextClassLoader(): null); - this.contribution = contribution; - if (contribution.getLocation() != null) { - try { - this.addURL(new URL(contribution.getLocation())); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - } - - /* - * Return the ClassLoader corresponding to a contribution providing an export - * Create a new ClassLoader for the contribution if one does not exist - */ - private ClassLoader getExportClassLoader(Contribution exportingContribution) { - ClassLoader cl = exportingContribution.getClassLoader(); - if (!(cl instanceof ContributionClassLoader)) { - if (cl == null) { - cl = getParent(); - } - - cl = new ContributionClassLoader(exportingContribution, cl); - exportingContribution.setClassLoader(cl); - } - return cl; - } - - /* (non-Javadoc) - * @see java.net.URLClassLoader#findClass(java.lang.String) - * - * Search path for class: - * This contribution - * Imported contributions - */ - @Override - protected Class findClass(String className) throws ClassNotFoundException { - - Class clazz = null; - try { - clazz = findClassFromContribution(className); - } catch (ClassNotFoundException e) { - - for (Import import_ : this.contribution.getImports()) { - if (classNameMatchesImport(className, import_)) { - // Delegate the resolution to the imported contribution - for (Contribution exportingContribution : ((JavaImportModelResolver)import_.getModelResolver()).getExportContributions()) { - - ClassLoader exportClassLoader = getExportClassLoader(exportingContribution); - if (exportClassLoader instanceof ContributionClassLoader) { - - for (Export export : exportingContribution.getExports()) { - try { - if (import_.match(export)) { - clazz = ((ContributionClassLoader)exportClassLoader).findClassFromContribution(className); - break; - } - } catch (ClassNotFoundException e1) { - continue; - } - - } - if (clazz != null) break; - } - } - if (clazz != null) break; - } - } - - if (clazz == null) throw e; - } - return clazz; - } - - - /* (non-Javadoc) - * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean) - * - * Search path for class: - * Parent ClassLoader - * This contribution - * Imported contributions - * - */ - @Override - protected synchronized Class loadClass(String className, boolean resolveClass) - throws ClassNotFoundException { - - Class clazz = null; - try { - - if (this.getParent() != null) - clazz = this.getParent().loadClass(className); - - } catch (ClassNotFoundException e) { - } - - if (clazz == null) - clazz = findClass(className); - - - if (resolveClass) - this.resolveClass(clazz); - return clazz; - - } - - - - /* - * (non-Javadoc) - * - * @see java.net.URLClassLoader#findResource(java.lang.String) - */ - @Override - public URL findResource(String name) { - - URL url = findResourceFromContribution(name); - - if (url == null) { - for (Import import_ : this.contribution.getImports()) { - if (resourceNameMatchesImport(name, import_)) { - // Delegate the resolution to the imported contribution - for (Contribution exportingContribution : ((JavaImportModelResolver)import_.getModelResolver()).getExportContributions()) { - - ClassLoader exportClassLoader = getExportClassLoader(exportingContribution); - if (exportClassLoader instanceof ContributionClassLoader) { - - for (Export export : exportingContribution.getExports()) { - if (import_.match(export)) { - url = ((ContributionClassLoader)exportClassLoader).findResourceFromContribution(name); - if (url != null) break; - } - } - if (url != null) break; - } - } - if (url != null) break; - } - } - - } - return url; - } - - - /* (non-Javadoc) - * @see java.net.URLClassLoader#findResources(java.lang.String) - */ - @Override - public Enumeration findResources(String name) throws IOException { - - return Collections.enumeration(findResourceSet(name)); - } - - - - - /* (non-Javadoc) - * @see java.lang.ClassLoader#getResource(java.lang.String) - * - * Find a resource. - * Search path for resource: - * Parent ClassLoader - * This contribution - * Imported contributions - */ - @Override - public URL getResource(String resName) { - - URL resource = null; - - if (this.getParent() != null) { - resource = this.getParent().getResource(resName); - } - if (resource == null) - resource = findResource(resName); - - return resource; - } - - - - /* (non-Javadoc) - * @see java.lang.ClassLoader#getResources(java.lang.String) - * - * Return list of resources from this contribution, resources - * imported through imported contributions and resources from parent - * ClassLoader. - */ - @Override - public Enumeration getResources(String resName) throws IOException { - - HashSet resourceSet = findResourceSet(resName); - addEnumerationToCollection(resourceSet, super.getResources(resName)); - - return Collections.enumeration(resourceSet); - } - - - /* - * Find set of resources - */ - private HashSet findResourceSet(String name) throws IOException { - - HashSet resources = new HashSet(); - - addEnumerationToCollection(resources, super.findResources(name)); - - for (Import import_ : this.contribution.getImports()) { - if (!(import_ instanceof JavaImport)) { - continue; - } - if (resourceNameMatchesImport(name, import_)) { - // Delegate the resolution to the imported contribution - for (Contribution exportingContribution : ((JavaImportModelResolver)import_.getModelResolver()).getExportContributions()) { - - ClassLoader exportClassLoader = getExportClassLoader(exportingContribution); - if (exportClassLoader instanceof ContributionClassLoader) { - - for (Export export : exportingContribution.getExports()) { - if (import_.match(export)) { - addEnumerationToCollection(resources, - ((ContributionClassLoader)exportClassLoader).findResources(name)); - } - } - } - } - } - } - - return resources; - } - - - /* - * Find class from contribution. If class has already been loaded, return loaded class. - */ - private Class findClassFromContribution(String className) throws ClassNotFoundException { - - Class clazz = findLoadedClass(className); - if (clazz == null) - clazz = super.findClass(className); - return clazz; - - } - - /* - * Find resource from contribution. - */ - private URL findResourceFromContribution(String name) { - - return super.findResource(name); - } - - /** - * Check if a class name matches an import statement. - * Class matches if the package name used in matches - * - * @param name Name of class - * @param import_ SCA contribution import - * @return true if this is a matching import - */ - private boolean classNameMatchesImport(String name, Import import_) { - - if (import_ instanceof JavaImport && name != null && name.lastIndexOf('.') > 0) { - JavaImport javaImport = (JavaImport) import_; - - String packageName = name.substring(0, name.lastIndexOf('.')); - if (javaImport.getPackage().endsWith(".*")) { - String prefix = javaImport.getPackage().substring(0, javaImport.getPackage().length() -1); - if (packageName.startsWith(prefix)) { - return true; - } - } else { - return packageName.equals(javaImport.getPackage()); - } - } - - return false; - } - - /** - * Check if a resource name matches an import statement. - * Resource matches if package/namespace match the directory of resource. - * - * @param name Name of resource - * @param import_ SCA contribution import - * @return true if this is a matching import - */ - private boolean resourceNameMatchesImport(String name, Import import_) { - - - if (name == null || name.lastIndexOf('/') <= 0) - return false; - else if (import_ instanceof JavaImport) { - JavaImport javaImport = (JavaImport) import_; - - if (javaImport.getPackage().endsWith(".*")) { - String packageName = name.substring(0, name.lastIndexOf('/')).replace('/', '.'); - String prefix = javaImport.getPackage().substring(0, javaImport.getPackage().length() -1); - if (packageName.startsWith(prefix)) { - return true; - } - } else { - // 'name' is a resource : contains "/" as separators - // Get package name from resource name - String packageName = name.substring(0, name.lastIndexOf('/')); - return packageName.equals(javaImport.getPackage().replaceAll("\\.", "/")); - } - } - return false; - } - - /* - * Add an enumeration to a Collection - */ - private void addEnumerationToCollection(Collection collection, Enumeration enumeration) { - - while (enumeration.hasMoreElements()) - collection.add(enumeration.nextElement()); - } - - - @Override - public String toString() { - return "SCA Contribution ClassLoader location: " + contribution.getLocation() + " parent ClassLoader: " + getParent(); - } - - -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java deleted file mode 100644 index f35f35ac4c..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.java.impl; - -import org.apache.tuscany.sca.contribution.java.JavaExport; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; - -/** - * Implementation of a Java Import model - * - * @version $Rev$ $Date$ - */ -public class JavaExportImpl implements JavaExport { - private ModelResolver modelResolver; - - /** - * Java package being exported - */ - private String packageName; - - public JavaExportImpl() { - super(); - } - - public String getPackage() { - return this.packageName; - } - - public void setPackage(String packageName) { - this.packageName = packageName; - } - - public ModelResolver getModelResolver() { - return modelResolver; - } - - public void setModelResolver(ModelResolver modelResolver) { - this.modelResolver = modelResolver; - } - -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java deleted file mode 100644 index 8d5412f6d7..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.java.impl; - -import org.apache.tuscany.sca.contribution.java.JavaExport; -import org.apache.tuscany.sca.contribution.resolver.ClassReference; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; - -/** - * A model resolver for Java exports. - * - * @version $Rev$ $Date$ - */ -public class JavaExportModelResolver implements ModelResolver { - - private JavaExport export; - private ModelResolver resolver; - - public JavaExportModelResolver(JavaExport export, ModelResolver resolver) { - this.export = export; - this.resolver = resolver; - } - - public void addModel(Object resolved) { - throw new IllegalStateException(); - } - - public Object removeModel(Object resolved) { - throw new IllegalStateException(); - } - - public T resolveModel(Class modelClass, T unresolved) { - if (!(unresolved instanceof ClassReference)) { - return unresolved; - } - - // Filter package name - ClassReference classReference = (ClassReference)unresolved; - String className = classReference.getClassName(); - int d = className.lastIndexOf('.'); - String packageName; - if (d != -1) { - packageName = className.substring(0, d); - } else { - packageName = ""; - } - if (export.getPackage().equals(packageName)) { - - // Package matches the exported package, delegate to the - // contribution's resolver - return resolver.resolveModel(modelClass, unresolved); - } else { - - // Package is not exported, return the unresolved object - return unresolved; - } - } - -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java deleted file mode 100644 index 6decc004a6..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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.java.impl; - -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.contribution.java.JavaExport; -import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - -/** - * Artifact processor for Java Export - * - * @version $Rev$ $Date$ - */ -public class JavaExportProcessor implements StAXArtifactProcessor { - private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; - - private static final QName EXPORT_JAVA = new QName(SCA11_NS, "export.java"); - - private static final String PACKAGE = "package"; - - private final JavaImportExportFactory factory; - private final Monitor monitor; - - public JavaExportProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - super(); - this.factory = modelFactories.getFactory(JavaImportExportFactory.class); - this.monitor = monitor; - } - - /** - * Report a error. - * - * @param problems - * @param message - * @param model - */ - private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } - - public QName getArtifactType() { - return EXPORT_JAVA; - } - - public Class getModelType() { - return JavaExport.class; - } - - /** - * Process - */ - public JavaExport read(XMLStreamReader reader) throws ContributionReadException { - JavaExport javaExport = this.factory.createJavaExport(); - QName element = null; - - try { - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - element = reader.getName(); - - // Read - if (EXPORT_JAVA.equals(element)) { - String packageName = reader.getAttributeValue(null, PACKAGE); - if (packageName == null) { - error("AttributePackageMissing", reader); - //throw new ContributionReadException("Attribute 'package' is missing"); - } else - javaExport.setPackage(packageName); - } - break; - case XMLStreamConstants.END_ELEMENT: - if (EXPORT_JAVA.equals(reader.getName())) { - return javaExport; - } - break; - } - - //Read the next element - if (reader.hasNext()) { - reader.next(); - } - } - } - catch (XMLStreamException e) { - ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); - } - - return javaExport; - } - - public void write(JavaExport javaExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - - // Write - writer.writeStartElement(EXPORT_JAVA.getNamespaceURI(), EXPORT_JAVA.getLocalPart()); - - if (javaExport.getPackage() != null) { - writer.writeAttribute(PACKAGE, javaExport.getPackage()); - } - - writer.writeEndElement(); - } - - public void resolve(JavaExport javaExport, ModelResolver resolver) throws ContributionResolveException { - - if (javaExport.getPackage() != null) - // Initialize the export resolver - javaExport.setModelResolver(new JavaExportModelResolver(javaExport, resolver)); - } -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java deleted file mode 100644 index e5dc397f4e..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.java.impl; - -import org.apache.tuscany.sca.contribution.java.JavaExport; -import org.apache.tuscany.sca.contribution.java.JavaImport; -import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory; - -/** - * Java Import/Export Factory implementation - * - * @version $Rev$ $Date$ - */ -public class JavaImportExportFactoryImpl implements JavaImportExportFactory { - - public JavaImport createJavaImport() { - return new JavaImportImpl(); - } - - public JavaExport createJavaExport() { - return new JavaExportImpl(); - } - -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java deleted file mode 100644 index cc18d5f798..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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.java.impl; - -import java.util.List; - -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.Export; -import org.apache.tuscany.sca.contribution.java.JavaExport; -import org.apache.tuscany.sca.contribution.java.JavaImport; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; - -/** - * Implementation of a Java Import model - * - * @version $Rev$ $Date$ - */ -public class JavaImportImpl implements JavaImport { - private ModelResolver modelResolver; - private List contributions; - /** - * Java package name being imported - */ - private String packageName; - /** - * Contribution URI where the artifact is imported from - */ - private String location; - - public JavaImportImpl() { - super(); - } - - public String getLocation() { - return this.location; - } - - public void setLocation(String location) { - this.location = location; - } - - public String getPackage() { - return this.packageName; - } - - public void setPackage(String packageName) { - this.packageName = packageName; - } - - public ModelResolver getModelResolver() { - return this.modelResolver; - } - - public void setModelResolver(ModelResolver modelResolver) { - this.modelResolver = modelResolver; - } - public List getExportContributions() { - return contributions; - } - - public void setExportContributions(List contributions) { - this.contributions = contributions; - } - - /** - * Match a JavaImport to a given JavaExport based on : - * location is not provided - * import and export packages match - */ - public boolean match(Export export) { - if(export instanceof JavaExport) { - JavaExport javaExport = (JavaExport)export; - String exportedPackage = javaExport.getPackage(); - if (packageName.equals(exportedPackage)) { - return true; - } else { - if (packageName.endsWith(".*")) { - String prefix = packageName.substring(0, packageName.length() - 1); - if (exportedPackage.startsWith(prefix)) { - return true; - } - } - } - } - - return false; - } - - @Override - public String toString() { - return String.valueOf(packageName); - } -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java deleted file mode 100644 index 484eddd222..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.java.impl; - -import java.util.List; - -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; - -/** - * A JavaImport specific model resolver. This model resolver is temporary - * and provides the ContributionClassLoader with the list of exporting - * contributions that it currently needs. - * - * FIXME Remove this class after the ContributionClassLoader is simplified - * and cleaned up. - * - * @version $Rev$ $Date$ - */ -public class JavaImportModelResolver implements ModelResolver { - - private ModelResolver modelResolver; - private List contributions; - - public JavaImportModelResolver(List contributions, ModelResolver modelResolver) { - this.modelResolver = modelResolver; - this.contributions = contributions; - } - - public List getExportContributions() { - return contributions; - } - - public void addModel(Object resolved) { - modelResolver.addModel(resolved); - } - - public Object removeModel(Object resolved) { - return modelResolver.removeModel(resolved); - } - - public T resolveModel(Class modelClass, T unresolved) { - return modelResolver.resolveModel(modelClass, unresolved); - } -} diff --git a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java b/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java deleted file mode 100644 index 48a1698bf4..0000000000 --- a/sandbox/ant/sca/tags/2.0-M2/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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.java.impl; - -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.contribution.java.JavaImport; -import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - -/** - * Artifact Processor for Java Imports - * - * @version $Rev$ $Date$ - */ -public class JavaImportProcessor implements StAXArtifactProcessor { - private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; - - private static final QName IMPORT_JAVA = new QName(SCA11_NS, "import.java"); - - private static final String PACKAGE = "package"; - private static final String LOCATION = "location"; - - private final JavaImportExportFactory factory; - private final Monitor monitor; - - public JavaImportProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - super(); - this.factory = modelFactories.getFactory(JavaImportExportFactory.class); - this.monitor = monitor; - } - - /** - * Report a error. - * - * @param problems - * @param message - * @param model - */ - private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } - - public QName getArtifactType() { - return IMPORT_JAVA; - } - - public Class getModelType() { - return JavaImport.class; - } - - /** - * Process - */ - public JavaImport read(XMLStreamReader reader) throws ContributionReadException { - JavaImport javaImport = this.factory.createJavaImport(); - QName element = null; - - try { - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - element = reader.getName(); - - // Read - if (IMPORT_JAVA.equals(element)) { - String packageName = reader.getAttributeValue(null, PACKAGE); - if (packageName == null) { - error("AttributePackageMissing", reader); - //throw new ContributionReadException("Attribute 'package' is missing"); - } else - javaImport.setPackage(packageName); - - String location = reader.getAttributeValue(null, LOCATION); - javaImport.setLocation(location); - } - break; - case XMLStreamConstants.END_ELEMENT: - if (IMPORT_JAVA.equals(reader.getName())) { - return javaImport; - } - break; - } - - // Read the next element - if (reader.hasNext()) { - reader.next(); - } - } - } - catch (XMLStreamException e) { - ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); - } - - return javaImport; - } - - public void write(JavaImport javaImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - - // Write - writer.writeStartElement(IMPORT_JAVA.getNamespaceURI(), IMPORT_JAVA.getLocalPart()); - - if (javaImport.getPackage() != null) { - writer.writeAttribute(PACKAGE, javaImport.getPackage()); - } - if (javaImport.getLocation() != null) { - writer.writeAttribute(LOCATION, javaImport.getLocation()); - } - - writer.writeEndElement(); - } - - - public void resolve(JavaImport model, ModelResolver resolver) throws ContributionResolveException { - - } -} -- cgit v1.2.3