summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/contribution
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/modules/contribution')
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java16
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java160
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java12
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java19
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java13
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java17
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java9
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java26
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java26
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java3
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java22
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java131
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java78
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java79
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java3
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java68
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java44
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java35
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java94
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java6
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java8
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java3
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java63
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java234
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java10
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java15
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java9
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java9
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java9
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java12
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java49
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java11
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java11
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java24
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java39
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java10
-rw-r--r--java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor1
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java75
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java21
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java23
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java21
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java21
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java8
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java13
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java23
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java10
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java30
47 files changed, 522 insertions, 1101 deletions
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java
index df313f3635..86146fc31b 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java
@@ -32,12 +32,12 @@ 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.processor.ProcessorContext;
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;
-import org.apache.tuscany.sca.monitor.Monitor;
/**
* A Model Resolver for ClassReferences.
@@ -46,6 +46,7 @@ import org.apache.tuscany.sca.monitor.Monitor;
*/
public class ClassLoaderModelResolver extends URLClassLoader implements ModelResolver {
private Contribution contribution;
+ private ProcessorContext context;
private Map<String, ModelResolver> importResolvers = new HashMap<String, ModelResolver>();
private static ClassLoader parentClassLoader(Contribution contribution) {
@@ -67,10 +68,9 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes
return urls.toArray(new URL[urls.size()]);
}
- public ClassLoaderModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) throws IOException {
+ public ClassLoaderModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories) throws IOException {
super(getContributionURLs(contribution), parentClassLoader(contribution));
this.contribution = contribution;
-
// Index Java import resolvers by package name
Map<String, List<ModelResolver>> resolverMap = new HashMap<String, List<ModelResolver>>();
for (Import import_: this.contribution.getImports()) {
@@ -91,21 +91,21 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes
}
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
if (!(unresolved instanceof ClassReference)) {
return unresolved;
}
try {
-
+ this.context = context;
// Load the class and return a class reference for it
String className = ((ClassReference)unresolved).getClassName();
Class<?> clazz = Class.forName(className, true, this);
@@ -159,7 +159,7 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes
// 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));
+ ClassReference classReference = importResolver.resolveModel(ClassReference.class, new ClassReference(name), context);
if (!classReference.isUnresolved()) {
return classReference.getJavaClass();
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java
deleted file mode 100644
index c023b3dc5b..0000000000
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java
+++ /dev/null
@@ -1,160 +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;
-import org.apache.tuscany.sca.monitor.Monitor;
-
-/**
- * A Model Resolver for ClassReferences.
- * @deprecated Use ClassLoaderModelResolver instead
- * @version $Rev$ $Date$
- */
-@Deprecated()
-public class ClassReferenceModelResolver implements ModelResolver {
- private Contribution contribution;
- private WeakReference<ClassLoader> classLoader;
- private Map<String, ClassReference> map = new HashMap<String, ClassReference>();
-
- private ModelResolver osgiResolver;
-
- public ClassReferenceModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) {
- 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<ClassLoader>() {
- 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<ClassLoader>() {
- // 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<ClassLoader>(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<ClassLoader>(this.getClass().getClassLoader());
- ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
- public ClassLoader run() {
- return this.getClass().getClassLoader();
- }
- });
- this.classLoader = new WeakReference<ClassLoader>( 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> T resolveModel(Class<T> 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/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java
index c1e3f13b77..9b02ce4abb 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java
@@ -20,9 +20,9 @@
package org.apache.tuscany.sca.contribution.java.impl;
import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.resolver.ClassReference;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.monitor.Monitor;
/**
* A model resolver for Java exports.
@@ -34,20 +34,20 @@ public class JavaExportModelResolver implements ModelResolver {
private JavaExport export;
private ModelResolver resolver;
- public JavaExportModelResolver(JavaExport export, ModelResolver resolver, Monitor monitor) {
+ public JavaExportModelResolver(JavaExport export, ModelResolver resolver) {
this.export = export;
this.resolver = resolver;
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
if (!(unresolved instanceof ClassReference)) {
return unresolved;
}
@@ -66,7 +66,7 @@ public class JavaExportModelResolver implements ModelResolver {
// Package matches the exported package, delegate to the
// contribution's resolver
- return resolver.resolveModel(modelClass, unresolved);
+ return resolver.resolveModel(modelClass, unresolved, context);
} else {
// Package is not exported, return the unresolved object
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java
index 73fbea31a0..de25081832 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java
@@ -32,6 +32,7 @@ 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.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
@@ -52,12 +53,10 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> {
private static final String PACKAGE = "package";
private final JavaImportExportFactory factory;
- private final Monitor monitor;
- public JavaExportProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ public JavaExportProcessor(FactoryExtensionPoint modelFactories) {
super();
this.factory = modelFactories.getFactory(JavaImportExportFactory.class);
- this.monitor = monitor;
}
/**
@@ -67,7 +66,7 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> {
* @param message
* @param model
*/
- private void error(String message, Object model, Object... messageParameters) {
+ private void error(Monitor monitor, 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);
@@ -85,7 +84,7 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> {
/**
* Process <export package=""/>
*/
- public JavaExport read(XMLStreamReader reader) throws ContributionReadException {
+ public JavaExport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
JavaExport javaExport = this.factory.createJavaExport();
QName element = null;
@@ -100,7 +99,7 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> {
if (EXPORT_JAVA.equals(element)) {
String packageName = reader.getAttributeValue(null, PACKAGE);
if (packageName == null) {
- error("AttributePackageMissing", reader);
+ error(context.getMonitor(), "AttributePackageMissing", reader);
//throw new ContributionReadException("Attribute 'package' is missing");
} else
javaExport.setPackage(packageName);
@@ -121,13 +120,13 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> {
}
catch (XMLStreamException e) {
ContributionReadException ex = new ContributionReadException(e);
- error("XMLStreamException", reader, ex);
+ error(context.getMonitor(), "XMLStreamException", reader, ex);
}
return javaExport;
}
- public void write(JavaExport javaExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ public void write(JavaExport javaExport, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
// Write <export.java>
writer.writeStartElement(EXPORT_JAVA.getNamespaceURI(), EXPORT_JAVA.getLocalPart());
@@ -139,10 +138,10 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> {
writer.writeEndElement();
}
- public void resolve(JavaExport javaExport, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(JavaExport javaExport, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
if (javaExport.getPackage() != null)
// Initialize the export resolver
- javaExport.setModelResolver(new JavaExportModelResolver(javaExport, resolver, monitor));
+ javaExport.setModelResolver(new JavaExportModelResolver(javaExport, resolver));
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java
index 484eddd222..344e730bdc 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java
@@ -22,6 +22,7 @@ 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.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
/**
@@ -48,15 +49,15 @@ public class JavaImportModelResolver implements ModelResolver {
return contributions;
}
- public void addModel(Object resolved) {
- modelResolver.addModel(resolved);
+ public void addModel(Object resolved, ProcessorContext context) {
+ modelResolver.addModel(resolved, context);
}
- public Object removeModel(Object resolved) {
- return modelResolver.removeModel(resolved);
+ public Object removeModel(Object resolved, ProcessorContext context) {
+ return modelResolver.removeModel(resolved, context);
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
- return modelResolver.resolveModel(modelClass, unresolved);
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
+ return modelResolver.resolveModel(modelClass, unresolved, context);
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java
index 48a1698bf4..c16660277a 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java
@@ -32,6 +32,7 @@ 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.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
@@ -53,12 +54,10 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> {
private static final String LOCATION = "location";
private final JavaImportExportFactory factory;
- private final Monitor monitor;
- public JavaImportProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ public JavaImportProcessor(FactoryExtensionPoint modelFactories) {
super();
this.factory = modelFactories.getFactory(JavaImportExportFactory.class);
- this.monitor = monitor;
}
/**
@@ -68,7 +67,7 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> {
* @param message
* @param model
*/
- private void error(String message, Object model, Object... messageParameters) {
+ private void error(Monitor monitor, 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);
@@ -86,7 +85,7 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> {
/**
* Process <import.java package="" location=""/>
*/
- public JavaImport read(XMLStreamReader reader) throws ContributionReadException {
+ public JavaImport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
JavaImport javaImport = this.factory.createJavaImport();
QName element = null;
@@ -101,7 +100,7 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> {
if (IMPORT_JAVA.equals(element)) {
String packageName = reader.getAttributeValue(null, PACKAGE);
if (packageName == null) {
- error("AttributePackageMissing", reader);
+ error(context.getMonitor(), "AttributePackageMissing", reader);
//throw new ContributionReadException("Attribute 'package' is missing");
} else
javaImport.setPackage(packageName);
@@ -125,13 +124,13 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> {
}
catch (XMLStreamException e) {
ContributionReadException ex = new ContributionReadException(e);
- error("XMLStreamException", reader, ex);
+ error(context.getMonitor(), "XMLStreamException", reader, ex);
}
return javaImport;
}
- public void write(JavaImport javaImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ public void write(JavaImport javaImport, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
// Write <import.java>
writer.writeStartElement(IMPORT_JAVA.getNamespaceURI(), IMPORT_JAVA.getLocalPart());
@@ -147,7 +146,7 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> {
}
- public void resolve(JavaImport model, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(JavaImport model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java
index 5c5ae22f77..7bf3c32c93 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.contribution.namespace.impl;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
/**
@@ -34,21 +35,21 @@ public class NamespaceExportModelResolver implements ModelResolver {
this.resolver = resolver;
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
// Just delegate to the contribution's model resolver, namespace
// based filtering is implemented in the model specific model
// resolver, which know how to get the namespace of the particular
// type of model that they handle
- return resolver.resolveModel(modelClass, unresolved);
+ return resolver.resolveModel(modelClass, unresolved, context);
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java
index 030fc1754b..a23f38e8ef 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java
@@ -34,6 +34,7 @@ import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
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.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
@@ -57,17 +58,14 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen
private final AssemblyFactory extensionFactory;
private final StAXArtifactProcessor<Object> extensionProcessor;
private final StAXAttributeProcessor<Object> attributeProcessor;
- private final Monitor monitor;
public NamespaceExportProcessor(FactoryExtensionPoint modelFactories,
StAXArtifactProcessor<Object> extensionProcessor,
- StAXAttributeProcessor<Object> attributeProcessor,
- Monitor monitor) {
+ StAXAttributeProcessor<Object> attributeProcessor) {
this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class);
this.extensionFactory = modelFactories.getFactory(AssemblyFactory.class);
this.extensionProcessor = extensionProcessor;
this.attributeProcessor = attributeProcessor;
- this.monitor = monitor;
}
/**
@@ -77,7 +75,7 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen
* @param message
* @param model
*/
- private void error(String message, Object model, Object... messageParameters) {
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
if (monitor != null) {
Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
monitor.problem(problem);
@@ -95,7 +93,7 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen
/**
* Process <export namespace=""/>
*/
- public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException {
+ public NamespaceExport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
NamespaceExport namespaceExport = this.factory.createNamespaceExport();
QName element = null;
@@ -110,14 +108,14 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen
if (EXPORT.equals(element)) {
String ns = reader.getAttributeValue(null, NAMESPACE);
if (ns == null) {
- error("AttributeNameSpaceMissing", reader);
+ error(context.getMonitor(), "AttributeNameSpaceMissing", reader);
//throw new ContributionReadException("Attribute 'namespace' is missing");
} else {
namespaceExport.setNamespace(ns);
}
- readExtendedAttributes(reader, namespaceExport, attributeProcessor, extensionFactory);
+ readExtendedAttributes(reader, namespaceExport, attributeProcessor, extensionFactory, context);
} else {
- readExtendedElement(reader, namespaceExport, extensionProcessor);
+ readExtendedElement(reader, namespaceExport, extensionProcessor, context);
}
break;
@@ -136,13 +134,13 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen
}
catch (XMLStreamException e) {
ContributionReadException ex = new ContributionReadException(e);
- error("XMLStreamException", reader, ex);
+ error(context.getMonitor(), "XMLStreamException", reader, ex);
}
return namespaceExport;
}
- public void write(NamespaceExport namespaceExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ public void write(NamespaceExport namespaceExport, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
// Write <export>
writer.writeStartElement(EXPORT.getNamespaceURI(), EXPORT.getLocalPart());
@@ -151,14 +149,14 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen
writer.writeAttribute(NAMESPACE, namespaceExport.getNamespace());
}
- writeExtendedAttributes(writer, namespaceExport, attributeProcessor);
+ writeExtendedAttributes(writer, namespaceExport, attributeProcessor, context);
- writeExtendedElements(writer, namespaceExport, extensionProcessor);
+ writeExtendedElements(writer, namespaceExport, extensionProcessor, context);
writer.writeEndElement();
}
- public void resolve(NamespaceExport namespaceExport, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(NamespaceExport namespaceExport, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
if (namespaceExport.getNamespace() != null)
// Initialize the export's resolver
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java
index b213d5e899..2efa8d6aca 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java
@@ -34,6 +34,7 @@ import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
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.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
@@ -59,14 +60,11 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen
private final AssemblyFactory extensionFactory;
private final StAXArtifactProcessor<Object> extensionProcessor;
private final StAXAttributeProcessor<Object> attributeProcessor;
- private final Monitor monitor;
public NamespaceImportProcessor(FactoryExtensionPoint modelFactories,
StAXArtifactProcessor<Object> extensionProcessor,
- StAXAttributeProcessor<Object> attributeProcessor,
- Monitor monitor) {
+ StAXAttributeProcessor<Object> attributeProcessor) {
this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class);
- this.monitor = monitor;
this.extensionFactory = modelFactories.getFactory(AssemblyFactory.class);
this.extensionProcessor = extensionProcessor;
this.attributeProcessor = attributeProcessor;
@@ -79,7 +77,7 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen
* @param message
* @param model
*/
- private void error(String message, Object model, Object... messageParameters) {
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
if (monitor != null) {
Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
monitor.problem(problem);
@@ -97,7 +95,7 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen
/**
* Process <import namespace="" location=""/>
*/
- public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException {
+ public NamespaceImport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
NamespaceImport namespaceImport = this.factory.createNamespaceImport();
QName element;
@@ -112,7 +110,7 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen
if (IMPORT.equals(element)) {
String ns = reader.getAttributeValue(null, NAMESPACE);
if (ns == null) {
- error("AttributeNameSpaceMissing", reader);
+ error(context.getMonitor(), "AttributeNameSpaceMissing", reader);
//throw new ContributionReadException("Attribute 'namespace' is missing");
} else {
namespaceImport.setNamespace(ns);
@@ -122,9 +120,9 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen
if (location != null) {
namespaceImport.setLocation(location);
}
- readExtendedAttributes(reader, namespaceImport, attributeProcessor, extensionFactory);
+ readExtendedAttributes(reader, namespaceImport, attributeProcessor, extensionFactory, context);
} else {
- readExtendedElement(reader, namespaceImport, extensionProcessor);
+ readExtendedElement(reader, namespaceImport, extensionProcessor, context);
}
break;
case XMLStreamConstants.END_ELEMENT:
@@ -142,13 +140,13 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen
}
catch (XMLStreamException e) {
ContributionReadException ex = new ContributionReadException(e);
- error("XMLStreamException", reader, ex);
+ error(context.getMonitor(), "XMLStreamException", reader, ex);
}
return namespaceImport;
}
- public void write(NamespaceImport namespaceImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ public void write(NamespaceImport namespaceImport, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
// Write <import>
writer.writeStartElement(IMPORT.getNamespaceURI(), IMPORT.getLocalPart());
@@ -160,12 +158,12 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen
writer.writeAttribute(LOCATION, namespaceImport.getLocation());
}
- writeExtendedAttributes(writer, namespaceImport, attributeProcessor);
- writeExtendedElements(writer, namespaceImport, extensionProcessor);
+ writeExtendedAttributes(writer, namespaceImport, attributeProcessor, context);
+ writeExtendedElements(writer, namespaceImport, extensionProcessor, context);
writer.writeEndElement();
}
- public void resolve(NamespaceImport model, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(NamespaceImport model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java
index 5be0b188f4..9ac3aebaf6 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java
@@ -34,8 +34,9 @@ public interface ArtifactProcessor<M> {
*
* @param model The model to resolve
* @param resolver The resolver to use to resolve referenced models
+ * @param context The context for the processor
*/
- void resolve(M model, ModelResolver resolver) throws ContributionResolveException;
+ void resolve(M model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException;
/**
* Returns the type of model handled by this artifact processor.
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
index bae566639a..817e5a5ee2 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
@@ -260,25 +260,26 @@ public abstract class BaseStAXArtifactProcessor {
/**
*
* @param reader
- * @param elementName
* @param extensible
* @param extensionAttributeProcessor
* @param extensionAttributeProcessor
* @param extensionFactory
+ * @param context TODO
+ * @param elementName
* @throws ContributionReadException
* @throws XMLStreamException
*/
protected void readExtendedAttributes(XMLStreamReader reader,
Extensible extensible,
StAXAttributeProcessor extensionAttributeProcessor,
- AssemblyFactory extensionFactory) throws ContributionReadException,
+ AssemblyFactory extensionFactory, ProcessorContext context) throws ContributionReadException,
XMLStreamException {
QName elementName = reader.getName();
for (int a = 0; a < reader.getAttributeCount(); a++) {
QName attributeName = reader.getAttributeName(a);
if (attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) {
if (!elementName.getNamespaceURI().equals(attributeName.getNamespaceURI())) {
- Object attributeValue = extensionAttributeProcessor.read(attributeName, reader);
+ Object attributeValue = extensionAttributeProcessor.read(attributeName, reader, context);
Extension attributeExtension;
if (attributeValue instanceof Extension) {
attributeExtension = (Extension)attributeValue;
@@ -296,29 +297,30 @@ public abstract class BaseStAXArtifactProcessor {
/**
*
- * @param attributeModel
* @param writer
* @param extensibleElement
* @param extensionAttributeProcessor
+ * @param context TODO
+ * @param attributeModel
* @throws ContributionWriteException
* @throws XMLStreamException
*/
protected void writeExtendedAttributes(XMLStreamWriter writer,
Extensible extensibleElement,
- StAXAttributeProcessor extensionAttributeProcessor)
+ StAXAttributeProcessor extensionAttributeProcessor, ProcessorContext context)
throws ContributionWriteException, XMLStreamException {
for (Extension extension : extensibleElement.getAttributeExtensions()) {
if (extension.isAttribute()) {
- extensionAttributeProcessor.write(extension, writer);
+ extensionAttributeProcessor.write(extension, writer, context);
}
}
}
protected void readExtendedElement(XMLStreamReader reader,
Extensible extensible,
- StAXArtifactProcessor extensionProcessor) throws ContributionReadException,
+ StAXArtifactProcessor extensionProcessor, ProcessorContext context) throws ContributionReadException,
XMLStreamException {
- Object ext = extensionProcessor.read(reader);
+ Object ext = extensionProcessor.read(reader, context);
if (extensible != null) {
extensible.getExtensions().add(ext);
}
@@ -326,10 +328,10 @@ public abstract class BaseStAXArtifactProcessor {
protected void writeExtendedElements(XMLStreamWriter writer,
Extensible extensible,
- StAXArtifactProcessor extensionProcessor) throws ContributionWriteException,
+ StAXArtifactProcessor extensionProcessor, ProcessorContext context) throws ContributionWriteException,
XMLStreamException {
for (Object ext : extensible.getExtensions()) {
- extensionProcessor.write(ext, writer);
+ extensionProcessor.write(ext, writer, context);
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java
index 945be504be..9c176fe1bf 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java
@@ -38,7 +38,6 @@ import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
import org.apache.tuscany.sca.extensibility.ServiceDeclarationParser;
import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.monitor.Problem.Severity;
@@ -52,11 +51,9 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
private ExtensionPointRegistry extensionPoints;
private FactoryExtensionPoint modelFactories;
- private MonitorFactory monitorFactory;
private boolean loaded;
private StAXArtifactProcessor<Object> extensibleStAXProcessor;
private StAXAttributeProcessor<Object> extensibleStAXAttributeProcessor;
- private Monitor monitor = null;
/**
* Constructs a new extension point.
@@ -67,36 +64,12 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
- if (monitorFactory != null)
- this.monitor = monitorFactory.createMonitor();
- this.extensibleStAXProcessor =
- new ExtensibleStAXArtifactProcessor(this, inputFactory, outputFactory, this.monitor);
+ this.extensibleStAXProcessor = new ExtensibleStAXArtifactProcessor(this, inputFactory, outputFactory);
StAXAttributeProcessorExtensionPoint attributeExtensionPoint =
extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class);
this.extensibleStAXAttributeProcessor =
- new ExtensibleStAXAttributeProcessor(attributeExtensionPoint, inputFactory, outputFactory, this.monitor);
- }
-
- /**
- * Report a exception.
- *
- * @param problems
- * @param message
- * @param model
- */
- private void error(String message, Object model, Exception ex) {
- if (monitor != null) {
- Problem problem =
- monitor.createProblem(this.getClass().getName(),
- "contribution-validation-messages",
- Severity.ERROR,
- model,
- message,
- ex);
- monitor.problem(problem);
- }
+ new ExtensibleStAXAttributeProcessor(attributeExtensionPoint, inputFactory, outputFactory);
}
public void addArtifactProcessor(StAXArtifactProcessor<?> artifactProcessor) {
@@ -143,7 +116,6 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class.getName());
} catch (IOException e) {
IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", extensibleStAXProcessor, ie);
throw ie;
}
@@ -165,7 +137,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
StAXArtifactProcessor<?> processor =
new LazyStAXArtifactProcessor(artifactType, modelTypeName, factoryName, processorDeclaration,
extensionPoints, modelFactories, extensibleStAXProcessor,
- extensibleStAXAttributeProcessor, monitor);
+ extensibleStAXAttributeProcessor);
addArtifactProcessor(processor);
}
@@ -187,7 +159,6 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
private Class<?> modelType;
private StAXArtifactProcessor<Object> extensionProcessor;
private StAXAttributeProcessor<Object> extensionAttributeProcessor;
- private Monitor monitor;
LazyStAXArtifactProcessor(QName artifactType,
String modelTypeName,
@@ -196,8 +167,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
ExtensionPointRegistry extensionPoints,
FactoryExtensionPoint modelFactories,
StAXArtifactProcessor<Object> extensionProcessor,
- StAXAttributeProcessor<Object> extensionAttributeProcessor,
- Monitor monitor) {
+ StAXAttributeProcessor<Object> extensionAttributeProcessor) {
this.extensionPoints = extensionPoints;
this.artifactType = artifactType;
@@ -206,14 +176,13 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
this.processorDeclaration = processorDeclaration;
this.extensionProcessor = extensionProcessor;
this.extensionAttributeProcessor = extensionAttributeProcessor;
- this.monitor = monitor;
}
public QName getArtifactType() {
return artifactType;
}
- private void error(String message, Object model, Exception ex) {
+ private void error(Monitor monitor, String message, Object model, Exception ex) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(),
@@ -250,14 +219,10 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
processorClass.getConstructor(FactoryExtensionPoint.class,
QName.class,
Class.class,
- Object.class,
- Monitor.class);
- processor =
- constructor
- .newInstance(modelFactories, artifactType, getModelType(), modelFactory, monitor);
+ Object.class);
+ processor = constructor.newInstance(modelFactories, artifactType, getModelType(), modelFactory);
} catch (Exception e) {
IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", processor, ie);
throw ie;
}
} else {
@@ -270,83 +235,51 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
(Class<StAXArtifactProcessor>)processorDeclaration.loadClass();
try {
Constructor<StAXArtifactProcessor> constructor =
- processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class);
- processor = constructor.newInstance(modelFactories, monitor);
+ processorClass.getConstructor(FactoryExtensionPoint.class);
+ processor = constructor.newInstance(modelFactories);
} catch (NoSuchMethodException e) {
try {
Constructor<StAXArtifactProcessor> constructor =
- processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class);
- processor = constructor.newInstance(extensionPoints, monitor);
+ processorClass.getConstructor(ExtensionPointRegistry.class);
+ processor = constructor.newInstance(extensionPoints);
} catch (NoSuchMethodException e1) {
try {
Constructor<StAXArtifactProcessor> constructor =
processorClass.getConstructor(FactoryExtensionPoint.class,
- StAXArtifactProcessor.class,
- Monitor.class);
- processor = constructor.newInstance(modelFactories, extensionProcessor, monitor);
+ StAXArtifactProcessor.class);
+ processor = constructor.newInstance(modelFactories, extensionProcessor);
} catch (NoSuchMethodException e2) {
try {
Constructor<StAXArtifactProcessor> constructor =
processorClass.getConstructor(FactoryExtensionPoint.class,
StAXArtifactProcessor.class,
- StAXAttributeProcessor.class,
- Monitor.class);
+ StAXAttributeProcessor.class);
processor =
constructor.newInstance(modelFactories,
extensionProcessor,
- extensionAttributeProcessor,
- monitor);
+ extensionAttributeProcessor);
} catch (NoSuchMethodException e2a) {
try {
Constructor<StAXArtifactProcessor> constructor =
processorClass.getConstructor(ExtensionPointRegistry.class,
- StAXArtifactProcessor.class,
- Monitor.class);
- processor =
- constructor.newInstance(extensionPoints, extensionProcessor, monitor);
+ StAXArtifactProcessor.class);
+ processor = constructor.newInstance(extensionPoints, extensionProcessor);
} catch (NoSuchMethodException e3) {
try {
Constructor<StAXArtifactProcessor> constructor =
processorClass.getConstructor(ExtensionPointRegistry.class,
StAXArtifactProcessor.class,
- StAXAttributeProcessor.class,
- Monitor.class);
+ StAXAttributeProcessor.class);
processor =
constructor.newInstance(extensionPoints,
extensionProcessor,
- extensionAttributeProcessor,
- monitor);
+ extensionAttributeProcessor);
} catch (NoSuchMethodException e3a) {
- try {
- Constructor<StAXArtifactProcessor> constructor =
- processorClass.getConstructor(FactoryExtensionPoint.class);
- processor = constructor.newInstance(modelFactories);
- } catch (NoSuchMethodException e4) {
- try {
- Constructor<StAXArtifactProcessor> constructor =
- processorClass.getConstructor(ExtensionPointRegistry.class);
- processor = constructor.newInstance(extensionPoints);
- } catch (NoSuchMethodException e4a) {
- try {
- Constructor<StAXArtifactProcessor> constructor =
- processorClass
- .getConstructor(FactoryExtensionPoint.class,
- StAXArtifactProcessor.class);
- processor =
- constructor.newInstance(modelFactories,
- extensionProcessor);
- } catch (NoSuchMethodException e5) {
- Constructor<StAXArtifactProcessor> constructor =
- processorClass
- .getConstructor(ExtensionPointRegistry.class,
- StAXArtifactProcessor.class);
- processor =
- constructor.newInstance(extensionPoints,
- extensionProcessor);
- }
- }
- }
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor();
+ processor = constructor.newInstance();
+
}
}
}
@@ -355,7 +288,6 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
}
} catch (Exception e) {
IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", processor, ie);
throw ie;
}
}
@@ -363,14 +295,15 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
return processor;
}
- public Object read(XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException {
- return getProcessor().read(inputSource);
+ public Object read(XMLStreamReader inputSource, ProcessorContext context) throws ContributionReadException,
+ XMLStreamException {
+ return getProcessor().read(inputSource, context);
}
@SuppressWarnings("unchecked")
- public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException,
- XMLStreamException {
- getProcessor().write(model, outputSource);
+ public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context)
+ throws ContributionWriteException, XMLStreamException {
+ getProcessor().write(model, outputSource, context);
}
public Class<?> getModelType() {
@@ -379,7 +312,6 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
modelType = processorDeclaration.loadClass(modelTypeName);
} catch (Exception e) {
IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", processorDeclaration, ie);
throw ie;
}
}
@@ -387,8 +319,9 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends
}
@SuppressWarnings("unchecked")
- public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
- getProcessor().resolve(model, resolver);
+ public void resolve(Object model, ModelResolver resolver, ProcessorContext context)
+ throws ContributionResolveException {
+ getProcessor().resolve(model, resolver, context);
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java
index d13885bce9..66a605c46a 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java
@@ -69,8 +69,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
if (monitorFactory != null) {
this.monitor = monitorFactory.createMonitor();
}
- this.extensibleStAXAttributeProcessor =
- new ExtensibleStAXAttributeProcessor(this, inputFactory, outputFactory, this.monitor);
+ this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(this, inputFactory, outputFactory);
}
/**
@@ -158,8 +157,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
// Create a processor wrapper and register it
StAXAttributeProcessor<?> processor =
new LazyStAXAttributeProcessor(artifactType, modelTypeName, factoryName, processorDeclaration,
- extensionPoints, modelFactories, extensibleStAXAttributeProcessor,
- monitor);
+ extensionPoints, modelFactories, extensibleStAXAttributeProcessor);
addArtifactProcessor(processor);
}
@@ -180,7 +178,6 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
private StAXAttributeProcessor<?> processor;
private Class<?> modelType;
private StAXAttributeProcessor<Object> extensionProcessor;
- private Monitor monitor;
LazyStAXAttributeProcessor(QName artifactType,
String modelTypeName,
@@ -188,8 +185,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
ServiceDeclaration processorDeclaration,
ExtensionPointRegistry extensionPoints,
FactoryExtensionPoint modelFactories,
- StAXAttributeProcessor<Object> extensionProcessor,
- Monitor monitor) {
+ StAXAttributeProcessor<Object> extensionProcessor) {
this.extensionPoints = extensionPoints;
this.artifactType = artifactType;
@@ -197,26 +193,12 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
this.factoryName = factoryName;
this.processorDeclaration = processorDeclaration;
this.extensionProcessor = extensionProcessor;
- this.monitor = monitor;
}
public QName getArtifactType() {
return artifactType;
}
- private void error(String message, Object model, Exception ex) {
- if (monitor != null) {
- Problem problem =
- monitor.createProblem(this.getClass().getName(),
- "contribution-validation-messages",
- Severity.ERROR,
- model,
- message,
- ex);
- monitor.problem(problem);
- }
- }
-
@SuppressWarnings("unchecked")
private StAXAttributeProcessor getProcessor() {
if (processor == null) {
@@ -228,27 +210,25 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
(Class<StAXAttributeProcessor>)processorDeclaration.loadClass();
try {
Constructor<StAXAttributeProcessor> constructor =
- processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class);
- processor = constructor.newInstance(modelFactories, monitor);
+ processorClass.getConstructor(FactoryExtensionPoint.class);
+ processor = constructor.newInstance(modelFactories);
} catch (NoSuchMethodException e) {
try {
Constructor<StAXAttributeProcessor> constructor =
- processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class);
- processor = constructor.newInstance(extensionPoints, monitor);
+ processorClass.getConstructor(ExtensionPointRegistry.class);
+ processor = constructor.newInstance(extensionPoints);
} catch (NoSuchMethodException e1) {
try {
Constructor<StAXAttributeProcessor> constructor =
processorClass.getConstructor(FactoryExtensionPoint.class,
- StAXArtifactProcessor.class,
- Monitor.class);
- processor = constructor.newInstance(modelFactories, extensionProcessor, monitor);
+ StAXArtifactProcessor.class);
+ processor = constructor.newInstance(modelFactories, extensionProcessor);
} catch (NoSuchMethodException e2) {
try {
Constructor<StAXAttributeProcessor> constructor =
processorClass.getConstructor(ExtensionPointRegistry.class,
- StAXArtifactProcessor.class,
- Monitor.class);
- processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor);
+ StAXArtifactProcessor.class);
+ processor = constructor.newInstance(extensionPoints, extensionProcessor);
} catch (NoSuchMethodException e3) {
try {
Constructor<StAXAttributeProcessor> constructor =
@@ -260,18 +240,11 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
processorClass.getConstructor(ExtensionPointRegistry.class);
processor = constructor.newInstance(extensionPoints);
} catch (NoSuchMethodException e4a) {
- try {
- Constructor<StAXAttributeProcessor> constructor =
- processorClass.getConstructor(FactoryExtensionPoint.class,
- StAXArtifactProcessor.class);
- processor = constructor.newInstance(modelFactories, extensionProcessor);
- } catch (NoSuchMethodException e5) {
- Constructor<StAXAttributeProcessor> constructor =
- processorClass.getConstructor(ExtensionPointRegistry.class,
- StAXArtifactProcessor.class);
- processor =
- constructor.newInstance(extensionPoints, extensionProcessor);
- }
+
+ Constructor<StAXAttributeProcessor> constructor =
+ processorClass.getConstructor();
+ processor = constructor.newInstance();
+
}
}
}
@@ -280,7 +253,6 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
}
} catch (Exception e) {
IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", processor, ie);
throw ie;
}
@@ -288,15 +260,15 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
return processor;
}
- public Object read(QName attributeName, XMLStreamReader inputSource) throws ContributionReadException,
- XMLStreamException {
- return getProcessor().read(attributeName, inputSource);
+ public Object read(QName attributeName, XMLStreamReader inputSource, ProcessorContext context)
+ throws ContributionReadException, XMLStreamException {
+ return getProcessor().read(attributeName, inputSource, context);
}
@SuppressWarnings("unchecked")
- public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException,
- XMLStreamException {
- getProcessor().write(model, outputSource);
+ public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context)
+ throws ContributionWriteException, XMLStreamException {
+ getProcessor().write(model, outputSource, context);
}
public Class<?> getModelType() {
@@ -305,7 +277,6 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
modelType = processorDeclaration.loadClass(modelTypeName);
} catch (Exception e) {
IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", processorDeclaration, ie);
throw ie;
}
}
@@ -313,8 +284,9 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends
}
@SuppressWarnings("unchecked")
- public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
- getProcessor().resolve(model, resolver);
+ public void resolve(Object model, ModelResolver resolver, ProcessorContext context)
+ throws ContributionResolveException {
+ getProcessor().resolve(model, resolver, context);
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java
index 3c7c2f1430..3fc6140f6d 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java
@@ -38,10 +38,6 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
-import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
-import org.apache.tuscany.sca.monitor.Problem;
-import org.apache.tuscany.sca.monitor.Problem.Severity;
/**
* The default implementation of a URL artifact processor extension point.
@@ -54,7 +50,6 @@ public class DefaultURLArtifactProcessorExtensionPoint extends
private ExtensionPointRegistry extensionPoints;
private StAXArtifactProcessor<?> staxProcessor;
private boolean loaded;
- private Monitor monitor = null;
/**
* Constructs a new extension point.
@@ -65,32 +60,9 @@ public class DefaultURLArtifactProcessorExtensionPoint extends
XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
- if (monitorFactory != null)
- this.monitor = monitorFactory.createMonitor();
StAXArtifactProcessorExtensionPoint staxProcessors =
extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, this.monitor);
- }
-
- /**
- * Report a exception.
- *
- * @param problems
- * @param message
- * @param model
- */
- private void error(String message, Object model, Exception ex) {
- if (monitor != null) {
- Problem problem =
- monitor.createProblem(this.getClass().getName(),
- "contribution-validation-messages",
- Severity.ERROR,
- model,
- message,
- ex);
- monitor.problem(problem);
- }
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory);
}
public void addArtifactProcessor(URLArtifactProcessor<?> artifactProcessor) {
@@ -232,7 +204,6 @@ public class DefaultURLArtifactProcessorExtensionPoint extends
ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class.getName());
} catch (IOException e) {
IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", staxProcessor, ie);
throw ie;
}
@@ -245,7 +216,7 @@ public class DefaultURLArtifactProcessorExtensionPoint extends
// Create a processor wrapper and register it
URLArtifactProcessor<?> processor =
new LazyURLArtifactProcessor(artifactType, modelTypeName, processorDeclaration, extensionPoints,
- staxProcessor, monitor);
+ staxProcessor);
addArtifactProcessor(processor);
}
@@ -265,39 +236,23 @@ public class DefaultURLArtifactProcessorExtensionPoint extends
private URLArtifactProcessor<?> processor;
private Class<?> modelType;
private StAXArtifactProcessor<?> staxProcessor;
- private Monitor monitor;
LazyURLArtifactProcessor(String artifactType,
String modelTypeName,
ServiceDeclaration processorDeclaration,
ExtensionPointRegistry extensionPoints,
- StAXArtifactProcessor<?> staxProcessor,
- Monitor monitor) {
+ StAXArtifactProcessor<?> staxProcessor) {
this.artifactType = artifactType;
this.modelTypeName = modelTypeName;
this.processorDeclaration = processorDeclaration;
this.extensionPoints = extensionPoints;
this.staxProcessor = staxProcessor;
- this.monitor = monitor;
}
public String getArtifactType() {
return artifactType;
}
- private void error(String message, Object model, Exception ex) {
- if (monitor != null) {
- Problem problem =
- monitor.createProblem(this.getClass().getName(),
- "contribution-validation-messages",
- Severity.ERROR,
- model,
- message,
- ex);
- monitor.problem(problem);
- }
- }
-
@SuppressWarnings("unchecked")
private URLArtifactProcessor getProcessor() {
if (processor == null) {
@@ -308,35 +263,32 @@ public class DefaultURLArtifactProcessorExtensionPoint extends
(Class<URLArtifactProcessor>)processorDeclaration.loadClass();
try {
Constructor<URLArtifactProcessor> constructor =
- processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class);
- processor = constructor.newInstance(modelFactories, monitor);
+ processorClass.getConstructor(FactoryExtensionPoint.class);
+ processor = constructor.newInstance(modelFactories);
} catch (NoSuchMethodException e) {
try {
Constructor<URLArtifactProcessor> constructor =
processorClass.getConstructor(FactoryExtensionPoint.class,
- StAXArtifactProcessor.class,
- Monitor.class);
- processor = constructor.newInstance(modelFactories, staxProcessor, monitor);
+ StAXArtifactProcessor.class);
+ processor = constructor.newInstance(modelFactories, staxProcessor);
} catch (NoSuchMethodException e2) {
Constructor<URLArtifactProcessor> constructor =
processorClass.getConstructor(ExtensionPointRegistry.class,
- StAXArtifactProcessor.class,
- Monitor.class);
- processor = constructor.newInstance(extensionPoints, staxProcessor, monitor);
+ StAXArtifactProcessor.class);
+ processor = constructor.newInstance(extensionPoints, staxProcessor);
}
}
} catch (Throwable e) {
IllegalStateException ie = new IllegalStateException("Exception during getProcessor() for " +
processorDeclaration.getClassName(), e);
- error("IllegalStateException", processor, ie);
throw ie;
}
}
return processor;
}
- public Object read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException {
- return getProcessor().read(contributionURL, artifactURI, artifactURL);
+ public Object read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context) throws ContributionReadException {
+ return getProcessor().read(contributionURL, artifactURI, artifactURL, context);
}
public Class<?> getModelType() {
@@ -345,7 +297,6 @@ public class DefaultURLArtifactProcessorExtensionPoint extends
modelType = processorDeclaration.loadClass(modelTypeName);
} catch (ClassNotFoundException e) {
IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", processorDeclaration, ie);
throw ie;
}
}
@@ -353,18 +304,18 @@ public class DefaultURLArtifactProcessorExtensionPoint extends
}
@SuppressWarnings("unchecked")
- public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
- getProcessor().resolve(model, resolver);
+ public void resolve(Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ getProcessor().resolve(model, resolver, context);
} // end method resolve
/**
* Preresolve phase, for ExtendedURLArtifactProcessors only
*/
@SuppressWarnings("unchecked")
- public void preResolve( Object model, ModelResolver resolver ) throws ContributionResolveException {
+ public void preResolve( Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
URLArtifactProcessor<?> processor = getProcessor();
if( processor instanceof ExtendedURLArtifactProcessor ) {
- ((ExtendedURLArtifactProcessor)processor).preResolve(model, resolver);
+ ((ExtendedURLArtifactProcessor)processor).preResolve(model, resolver, context);
} // end if
} // end method resolve
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java
index 952adbc4e3..ca579110ae 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java
@@ -34,7 +34,8 @@ public interface ExtendedArtifactProcessor<M> extends ArtifactProcessor<M> {
*
* @param model The model to resolve
* @param resolver The resolver to use to resolve referenced models
+ * @param context The context
*/
- void preResolve(M model, ModelResolver resolver) throws ContributionResolveException;
+ void preResolve(M model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException;
} // end interface
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
index a31b24a295..91db32b806 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
@@ -34,6 +34,8 @@ import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+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;
@@ -54,7 +56,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
private XMLInputFactory inputFactory;
private XMLOutputFactory outputFactory;
private StAXArtifactProcessorExtensionPoint processors;
- private Monitor monitor;
+
/**
* Constructs a new ExtensibleStAXArtifactProcessor.
@@ -64,8 +66,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
*/
public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors,
XMLInputFactory inputFactory,
- XMLOutputFactory outputFactory,
- Monitor monitor) {
+ XMLOutputFactory outputFactory) {
super();
this.processors = processors;
this.inputFactory = inputFactory;
@@ -73,7 +74,17 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
if (this.outputFactory != null) {
this.outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
}
- this.monitor = monitor;
+ }
+
+ public ExtensibleStAXArtifactProcessor(ExtensionPointRegistry registry) {
+ super();
+ this.processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.inputFactory = factories.getFactory(XMLInputFactory.class);
+ this.outputFactory = factories.getFactory(XMLOutputFactory.class);
+ if (this.outputFactory != null) {
+ this.outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+ }
}
/**
@@ -83,7 +94,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
* @param message
* @param model
*/
- private void warning(String message, Object model, Object... messageParameters) {
+ private void warning(Monitor monitor, String message, Object model, Object... messageParameters) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(),
@@ -103,7 +114,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
* @param message
* @param model
*/
- private void error(String message, Object model, Object... messageParameters) {
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(),
@@ -123,7 +134,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
* @param message
* @param model
*/
- private void error(String message, Object model, Exception ex) {
+ private void error(Monitor monitor, String message, Object model, Exception ex) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(),
@@ -136,8 +147,8 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
}
}
- public Object read(XMLStreamReader source) throws ContributionReadException, XMLStreamException {
-
+ public Object read(XMLStreamReader source, ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ Monitor monitor = context.getMonitor();
// Delegate to the processor associated with the element QName
int event = source.getEventType();
if (event == XMLStreamConstants.START_DOCUMENT) {
@@ -147,49 +158,49 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
StAXArtifactProcessor<?> processor = (StAXArtifactProcessor<?>)processors.getProcessor(name);
if (processor == null) {
Location location = source.getLocation();
- error("ElementCannotBeProcessed", processors, name, location);
+ error(monitor, "ElementCannotBeProcessed", processors, name, location);
StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT);
if (anyElementProcessor != null) {
- return anyElementProcessor.read(source);
+ return anyElementProcessor.read(source, context);
} else {
return null;
}
}
- return processor.read(source);
+ return processor.read(source, context);
}
@SuppressWarnings("unchecked")
- public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
-
+ public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
+ Monitor monitor = context.getMonitor();
// Delegate to the processor associated with the model type
if (model != null) {
StAXArtifactProcessor processor = processors.getProcessor(model.getClass());
if (processor != null) {
- processor.write(model, outputSource);
+ processor.write(model, outputSource, context);
} else {
if (logger.isLoggable(Level.WARNING)) {
logger.warning("No StAX processor is configured to handle " + model.getClass());
}
if (!XMLStreamReader.class.isInstance(model)) {
- warning("NoStaxProcessor", processors, model.getClass());
+ warning(monitor, "NoStaxProcessor", processors, model.getClass());
}
StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT);
if (anyElementProcessor != null) {
- anyElementProcessor.write(model, outputSource);
+ anyElementProcessor.write(model, outputSource, context);
}
}
}
}
@SuppressWarnings("unchecked")
- public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
// Delegate to the processor associated with the model type
if (model != null) {
StAXArtifactProcessor processor = processors.getProcessor(model.getClass());
if (processor != null) {
- processor.resolve(model, resolver);
+ processor.resolve(model, resolver, context);
}
}
}
@@ -198,10 +209,12 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
* Read a model from an InputStream.
* @param is The artifact InputStream
* @param type Model type
+ * @param context TODO
* @return The model
* @throws ContributionReadException
*/
- public <M> M read(InputStream is, Class<M> type) throws ContributionReadException {
+ public <M> M read(InputStream is, Class<M> type, ProcessorContext context) throws ContributionReadException {
+ Monitor monitor = context.getMonitor();
try {
XMLStreamReader reader;
try {
@@ -209,11 +222,11 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
try {
reader.nextTag();
QName name = reader.getName();
- Object mo = read(reader);
+ Object mo = read(reader, context);
if (type.isInstance(mo)) {
return type.cast(mo);
} else {
- error("UnrecognizedElementException", reader, name);
+ error(monitor, "UnrecognizedElementException", reader, name);
UnrecognizedElementException e = new UnrecognizedElementException(name);
throw e;
}
@@ -221,7 +234,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
Location location = reader.getLocation();
e.setLine(location.getLineNumber());
e.setColumn(location.getColumnNumber());
- error("ContributionReadException", reader, e);
+ error(monitor, "ContributionReadException", reader, e);
throw e;
} finally {
try {
@@ -239,7 +252,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
}
} catch (XMLStreamException e) {
ContributionReadException ce = new ContributionReadException(e);
- error("ContributionReadException", inputFactory, ce);
+ error(monitor, "ContributionReadException", inputFactory, ce);
throw ce;
}
}
@@ -248,17 +261,18 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
* Write a model to an OutputStream.
* @param model
* @param os
+ * @param context
* @throws ContributionWriteException
*/
- public void write(Object model, OutputStream os) throws ContributionWriteException {
+ public void write(Object model, OutputStream os, ProcessorContext context) throws ContributionWriteException {
try {
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
- write(model, writer);
+ write(model, writer, context);
writer.flush();
writer.close();
} catch (XMLStreamException e) {
ContributionWriteException cw = new ContributionWriteException(e);
- error("ContributionWriteException", outputFactory, cw);
+ error(context.getMonitor(), "ContributionWriteException", outputFactory, cw);
throw cw;
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java
index 084396f733..aa159ac629 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java
@@ -57,8 +57,6 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
private XMLInputFactory inputFactory;
private XMLOutputFactory outputFactory;
private StAXAttributeProcessorExtensionPoint processors;
- private Monitor monitor;
-
/**
* Constructs a new ExtensibleStAXArtifactProcessor.
* @param processors
@@ -67,8 +65,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
*/
public ExtensibleStAXAttributeProcessor(StAXAttributeProcessorExtensionPoint processors,
XMLInputFactory inputFactory,
- XMLOutputFactory outputFactory,
- Monitor monitor) {
+ XMLOutputFactory outputFactory) {
super();
this.processors = processors;
this.inputFactory = inputFactory;
@@ -76,7 +73,6 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
if (this.outputFactory != null) {
this.outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
}
- this.monitor = monitor;
}
/**
@@ -86,7 +82,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
* @param message
* @param model
*/
- private void warning(String message, Object model, Object... messageParameters) {
+ private void warning(Monitor monitor, String message, Object model, Object... messageParameters) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(),
@@ -106,7 +102,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
* @param message
* @param model
*/
- private void error(String message, Object model, Object... messageParameters) {
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(),
@@ -126,7 +122,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
* @param message
* @param model
*/
- private void error(String message, Object model, Exception ex) {
+ private void error(Monitor monitor, String message, Object model, Exception ex) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(),
@@ -139,7 +135,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
}
}
- public Object read(QName attributeName, XMLStreamReader source) throws ContributionReadException,
+ public Object read(QName attributeName, XMLStreamReader source, ProcessorContext context) throws ContributionReadException,
XMLStreamException {
// Delegate to the processor associated with the attribute QName
int event = source.getEventType();
@@ -158,10 +154,10 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
if (logger.isLoggable(Level.WARNING)) {
logger.warning("Attribute " + attributeName + " cannot be processed. (" + location + ")");
}
- warning("AttributeCannotBeProcessed", processors, attributeName, location);
+ warning(context.getMonitor(), "AttributeCannotBeProcessed", processors, attributeName, location);
}
} else {
- return processor.read(attributeName, source);
+ return processor.read(attributeName, source, context);
}
//handle extension attributes without processors
@@ -171,14 +167,14 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
if (logger.isLoggable(Level.WARNING)) {
logger.warning("Could not find Default Attribute processor !");
}
- warning("DefaultAttributeProcessorNotAvailable", processors, ANY_ATTRIBUTE, location);
+ warning(context.getMonitor(), "DefaultAttributeProcessorNotAvailable", processors, ANY_ATTRIBUTE, location);
}
- return processor == null ? null : processor.read(attributeName, source);
+ return processor == null ? null : processor.read(attributeName, source, context);
}
@SuppressWarnings("unchecked")
- public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
+ public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
if (model == null) {
return;
@@ -191,10 +187,10 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
if (logger.isLoggable(Level.WARNING)) {
logger.warning("No StAX processor is configured to handle " + model.getClass());
}
- warning("NoStaxProcessor", processors, model.getClass());
+ warning(context.getMonitor(), "NoStaxProcessor", processors, model.getClass());
}
} else {
- processor.write(model, outputSource);
+ processor.write(model, outputSource, context);
return;
}
@@ -204,21 +200,21 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
if (logger.isLoggable(Level.WARNING)) {
logger.warning("No Default StAX processor is configured to handle " + model.getClass());
}
- warning("NoDefaultStaxProcessor", processors, model.getClass());
+ warning(context.getMonitor(), "NoDefaultStaxProcessor", processors, model.getClass());
} else {
- processor.write(model, outputSource);
+ processor.write(model, outputSource, context);
return;
}
}
@SuppressWarnings("unchecked")
- public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
// Delegate to the processor associated with the model type
if (model != null) {
StAXAttributeProcessor processor = processors.getProcessor(model.getClass());
if (processor != null) {
- processor.resolve(model, resolver);
+ processor.resolve(model, resolver, context);
}
}
}
@@ -240,15 +236,15 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
* @param os
* @throws ContributionWriteException
*/
- public void write(Object model, OutputStream os) throws ContributionWriteException {
+ public void write(Object model, OutputStream os, ProcessorContext context) throws ContributionWriteException {
try {
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
- write(model, writer);
+ write(model, writer, context);
writer.flush();
writer.close();
} catch (XMLStreamException e) {
ContributionWriteException cw = new ContributionWriteException(e);
- error("ContributionWriteException", outputFactory, cw);
+ error(context.getMonitor(), "ContributionWriteException", outputFactory, cw);
throw cw;
}
}
@@ -258,6 +254,6 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<
}
public Class<Object> getModelType() {
- return null;
+ return Object.class;
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java
index 7b4a7cff3a..77940df5aa 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java
@@ -37,16 +37,14 @@ import org.apache.tuscany.sca.monitor.Problem.Severity;
public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Object> {
private URLArtifactProcessorExtensionPoint processors;
- private Monitor monitor;
/**
* Constructs a new ExtensibleURLArtifactProcessor.
*
* @param processors
*/
- public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors, Monitor monitor) {
+ public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors) {
this.processors = processors;
- this.monitor = monitor;
}
/**
@@ -56,7 +54,7 @@ public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Obje
* @param message
* @param model
*/
- private void error(String message, Object model, Object... messageParameters) {
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(),
@@ -70,7 +68,7 @@ public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Obje
}
@SuppressWarnings("unchecked")
- public Object read(URL contributionURL, URI sourceURI, URL sourceURL) throws ContributionReadException {
+ public Object read(URL contributionURL, URI sourceURI, URL sourceURL, ProcessorContext context) throws ContributionReadException {
URLArtifactProcessor<Object> processor = null;
if (sourceURI != null) {
//try to retrieve a processor for the specific URI
@@ -108,51 +106,40 @@ public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Obje
if (processor == null) {
return null;
}
- return processor.read(contributionURL, sourceURI, sourceURL);
+ return processor.read(contributionURL, sourceURI, sourceURL, context);
}
@SuppressWarnings("unchecked")
- public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
// Delegate to the processor associated with the model type
if (model != null) {
URLArtifactProcessor processor = processors.getProcessor(model.getClass());
if (processor != null) {
- processor.resolve(model, resolver);
+ processor.resolve(model, resolver, context);
}
}
}
- public <M> M read(URL contributionURL, URI artifactURI, URL artifactUrl, Class<M> type)
+ public <M> M read(URL contributionURL, URI artifactURI, URL artifactUrl, ProcessorContext context, Class<M> type)
throws ContributionReadException {
- Object mo = read(contributionURL, artifactURI, artifactUrl);
+ Object mo = read(contributionURL, artifactURI, artifactUrl, context);
if (type.isInstance(mo)) {
return type.cast(mo);
} else {
UnrecognizedElementException e = new UnrecognizedElementException(null);
e.setResourceURI(artifactURI.toString());
- error("UnrecognizedElementException", processors, artifactURI.toString());
+ error(context.getMonitor(), "UnrecognizedElementException", processors, artifactURI.toString());
throw e;
}
}
public String getArtifactType() {
- return null;
+ return "";
}
public Class<Object> getModelType() {
- return null;
+ return Object.class;
}
- /**
- * Returns the file name from a URL.
- * @param url
- * @return
- */
- private static String getFileName(URL url) {
- String fileName = url.getPath();
- int pos = fileName.lastIndexOf("/");
-
- return fileName.substring(pos + 1);
- }
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java
new file mode 100644
index 0000000000..16404ec78a
--- /dev/null
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java
@@ -0,0 +1,94 @@
+/*
+ * 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.processor;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+
+/**
+ * Context for contribution processors
+ */
+public class ProcessorContext {
+ protected Contribution contribution;
+ protected Monitor monitor;
+ protected Object parentModel;
+
+ /**
+ * @param contribution
+ * @param monitor
+ */
+ public ProcessorContext(Contribution contribution, Monitor monitor) {
+ super();
+ this.contribution = contribution;
+ this.monitor = monitor;
+ }
+
+ public ProcessorContext(Monitor monitor) {
+ super();
+ this.monitor = monitor;
+ }
+
+ public ProcessorContext(ExtensionPointRegistry registry) {
+ super();
+ MonitorFactory monitorFactory =
+ registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(MonitorFactory.class);
+ this.monitor = monitorFactory.createMonitor();
+ }
+
+ public ProcessorContext() {
+ super();
+ this.monitor = new DefaultMonitorFactory().createMonitor();
+ }
+
+ public Contribution getContribution() {
+ return contribution;
+ }
+
+ public Contribution setContribution(Contribution contribution) {
+ Contribution old = this.contribution;
+ this.contribution = contribution;
+ return old;
+ }
+
+ public Monitor getMonitor() {
+ return monitor;
+ }
+
+ public Monitor setMonitor(Monitor monitor) {
+ Monitor old = this.monitor;
+ this.monitor = monitor;
+ return old;
+ }
+
+ public Object getParentModel() {
+ return parentModel;
+ }
+
+ public Object setParentModel(Object parentMObject) {
+ Object old = this.parentModel;
+ this.parentModel = parentMObject;
+ return old;
+ }
+
+}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java
index 1bf9b4d494..8927acd776 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java
@@ -36,19 +36,21 @@ public interface StAXArtifactProcessor<M> extends ArtifactProcessor<M> {
* Reads a model from an XMLStreamReader.
*
* @param reader The XMLStreamReader
+ * @param context The context
* @return A model representation of the input.
*/
- M read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException;
+ M read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException;
/**
* Writes a model to an XMLStreamWriter.
*
* @param model A model representing the source
* @param writer The XML stream writer
+ * @param context TODO
* @throws ContributionWriteException
* @throws XMLStreamException
*/
- void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException;
+ void write(M model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException;
/**
* Returns the type of artifact handled by this artifact processor.
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java
index b25bf0d669..d33b2c1028 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java
@@ -35,21 +35,23 @@ public interface StAXAttributeProcessor<M> extends ArtifactProcessor<M>{
/**
* Reads a model from an XMLStreamReader.
- *
* @param reader The XMLStreamReader
+ * @param context The context
+ *
* @return A model representation of the input.
*/
- M read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException;
+ M read(QName attributeName, XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException;
/**
* Writes a model to an XMLStreamWriter.
*
* @param model A model representing the source
* @param writer The XML stream writer
+ * @param context The context
* @throws ContributionWriteException
* @throws XMLStreamException
*/
- void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException;
+ void write(M model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException;
/**
* Returns the type of artifact handled by this artifact processor.
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java
index c44ca0c66a..dd098283bc 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java
@@ -36,9 +36,10 @@ public interface URLArtifactProcessor<M> extends ArtifactProcessor<M> {
* @param contributionURL Contribution location URL
* @param artifactURI Artifact URI
* @param artifactURL Artifact location URL
+ * @param context The context
* @return A model representation of the input.
*/
- M read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException;
+ M read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context) throws ContributionReadException;
/**
* Returns the type of artifact handled by this artifact processor.
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
index c5bbe3008f..09a6b7dd80 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
@@ -37,6 +37,7 @@ import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
import org.apache.tuscany.sca.contribution.processor.ExtendedURLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
@@ -64,36 +65,20 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
private FactoryExtensionPoint modelFactories;
private URLArtifactProcessor<Object> artifactProcessor;
private StAXArtifactProcessor<Object> extensionProcessor;
- // private UtilityExtensionPoint utilities;
- private Monitor monitor;
private ContributionScannerExtensionPoint scanners;
// Marks pre-resolve phase completed
private boolean preResolved = false;
- public ContributionContentProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) {
+ public ContributionContentProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor) {
this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
this.modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
- this.monitor = monitor;
URLArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
- this.artifactProcessor = new ExtensibleURLArtifactProcessor(artifactProcessors, this.monitor);
+ this.artifactProcessor = new ExtensibleURLArtifactProcessor(artifactProcessors);
this.extensionProcessor = extensionProcessor;
this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
this.scanners = extensionPoints.getExtensionPoint(ContributionScannerExtensionPoint.class);
}
- /*
- public ContributionContentProcessor(FactoryExtensionPoint modelFactories, ModelResolverExtensionPoint modelResolvers,
- URLArtifactProcessor<Object> artifactProcessor, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) {
- this.modelFactories = modelFactories;
- this.modelResolvers = modelResolvers;
- hackResolvers(modelResolvers);
- this.artifactProcessor = artifactProcessor;
- this.extensionProcessor = extensionProcessor;
- this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
- this.monitor = monitor;
- }
- */
-
public String getArtifactType() {
return ".contribution/content";
}
@@ -116,19 +101,21 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
return null;
}
- public Contribution read(URL parentURL, URI contributionURI, URL contributionURL) throws ContributionReadException {
+ public Contribution read(URL parentURL, URI contributionURI, URL contributionURL, ProcessorContext context) throws ContributionReadException {
// Create contribution model
Contribution contribution = contributionFactory.createContribution();
contribution.setURI(contributionURI.toString());
contribution.setLocation(contributionURL.toString());
- ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories, monitor);
+ ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories);
contribution.setModelResolver(modelResolver);
contribution.setUnresolved(true);
+ Monitor monitor = context.getMonitor();
monitor.pushContext("Contribution: " + contribution.getURI());
+ Contribution old = context.setContribution(contribution);
try {
// Create a contribution scanner
ContributionScanner scanner = scanners.getContributionScanner(contributionURL.getProtocol());
@@ -153,18 +140,19 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
artifact.setURI(artifactURI);
artifact.setLocation(artifactURL.toString());
artifacts.add(artifact);
- modelResolver.addModel(artifact);
+ modelResolver.addModel(artifact, context);
monitor.pushContext("Artifact: " + artifactURI);
+ old = context.setContribution(contribution);
try {
// Read each artifact
- Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL);
+ Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL, context);
if (model != null) {
artifact.setModel(model);
// Add the loaded model to the model resolver
- modelResolver.addModel(model);
+ modelResolver.addModel(model, context);
// Merge contribution metadata into the contribution model
if (model instanceof ContributionMetadata) {
@@ -179,6 +167,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
}
} finally {
monitor.popContext();
+ context.setContribution(old);
}
}
@@ -200,6 +189,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
}
} finally {
monitor.popContext();
+ context.setContribution(old);
}
return contribution;
@@ -213,26 +203,28 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
* @param resolver - the Resolver to use
* @throws ContributionResolveException
*/
- public void preResolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException {
+ public void preResolve(Contribution contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
// Resolve the contribution model itself
ModelResolver contributionResolver = contribution.getModelResolver();
contribution.setUnresolved(false);
- contributionResolver.addModel(contribution);
+ contributionResolver.addModel(contribution, context);
// Resolve Exports
- resolveExports(contribution, contributionResolver);
+ resolveExports(contribution, contributionResolver, context);
// Resolve Imports
- resolveImports(contribution, contributionResolver);
+ resolveImports(contribution, contributionResolver, context);
preResolved = true;
} // end method preResolve
- public void resolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(Contribution contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ Monitor monitor = context.getMonitor();
+ Contribution old = context.setContribution(contribution);
try {
monitor.pushContext("Contribution: " + contribution.getURI());
- if( !preResolved ) preResolve( contribution, resolver);
+ if( !preResolved ) preResolve( contribution, resolver, context);
ModelResolver contributionResolver = contribution.getModelResolver();
// Resolve all artifact models
@@ -240,7 +232,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
Object model = artifact.getModel();
if (model != null) {
try {
- artifactProcessor.resolve(model, contributionResolver);
+ artifactProcessor.resolve(model, contributionResolver, context);
} catch (Throwable e) {
throw new ContributionResolveException(e);
}
@@ -251,13 +243,14 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
List<Composite> deployables = contribution.getDeployables();
for (int i = 0, n = deployables.size(); i < n; i++) {
Composite deployable = deployables.get(i);
- Composite resolved = (Composite)contributionResolver.resolveModel(Composite.class, deployable);
+ Composite resolved = (Composite)contributionResolver.resolveModel(Composite.class, deployable, context);
if (resolved != deployable) {
deployables.set(i, resolved);
}
} // end for
} finally {
monitor.popContext();
+ context.setContribution(old);
} // end try
} // end method resolve
@@ -266,13 +259,13 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
* @param contribution
* @param resolver
*/
- private void resolveExports(Contribution contribution, ModelResolver resolver) throws ContributionResolveException {
+ private void resolveExports(Contribution contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
for (Export export: contribution.getExports()) {
if (export instanceof DefaultExport) {
// Initialize the default export's resolver
export.setModelResolver(resolver);
} else {
- extensionProcessor.resolve(export, resolver);
+ extensionProcessor.resolve(export, resolver, context);
} // end if
} // end for
@@ -283,9 +276,9 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso
* @param contribution
* @param resolver
*/
- private void resolveImports(Contribution contribution, ModelResolver resolver) throws ContributionResolveException {
+ private void resolveImports(Contribution contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
for (Import import_: contribution.getImports()) {
- extensionProcessor.resolve(import_, resolver);
+ extensionProcessor.resolve(import_, resolver, context);
} // end for
} // end method resolveImports
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java
deleted file mode 100644
index 2bb6b59e57..0000000000
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java
+++ /dev/null
@@ -1,234 +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.processor.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-
-import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.common.java.io.IOHelper;
-import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.ContributionFactory;
-import org.apache.tuscany.sca.contribution.ContributionMetadata;
-import org.apache.tuscany.sca.contribution.DefaultExport;
-import org.apache.tuscany.sca.contribution.DefaultImport;
-import org.apache.tuscany.sca.contribution.Export;
-import org.apache.tuscany.sca.contribution.Import;
-import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
-import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.resolver.ClassReference;
-import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
-import org.apache.tuscany.sca.contribution.scanner.ContributionScanner;
-import org.apache.tuscany.sca.contribution.scanner.impl.DirectoryContributionScanner;
-import org.apache.tuscany.sca.contribution.scanner.impl.JarContributionScanner;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
-
-/**
- * URLArtifactProcessor that handles contribution files and returns a contribution
- * info model.
- *
- * @version $Rev$ $Date$
- */
-public class ContributionInfoProcessor implements URLArtifactProcessor<Contribution>{
- private ContributionFactory contributionFactory;
- private ModelResolverExtensionPoint modelResolvers;
- private FactoryExtensionPoint modelFactories;
- private URLArtifactProcessorExtensionPoint artifactProcessors;
- private URLArtifactProcessor<Object> artifactProcessor;
- private StAXArtifactProcessor<Object> extensionProcessor;
- private Monitor monitor;
-
- public ContributionInfoProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) {
- this.monitor = monitor;
- this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
- this.modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
- hackResolvers(modelResolvers);
- URLArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
- this.artifactProcessors = artifactProcessors;
- this.artifactProcessor = new ExtensibleURLArtifactProcessor(artifactProcessors, monitor);
- this.extensionProcessor = extensionProcessor;
- this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
- }
-
- public ContributionInfoProcessor(FactoryExtensionPoint modelFactories, ModelResolverExtensionPoint modelResolvers, URLArtifactProcessor<Object> artifactProcessor) {
- this.modelFactories = modelFactories;
- this.modelResolvers = modelResolvers;
- hackResolvers(modelResolvers);
- this.artifactProcessor = artifactProcessor;
- this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
- }
-
- public String getArtifactType() {
- return ".contribution/info";
- }
-
- public Class<Contribution> getModelType() {
- return null;
- }
-
- public Contribution read(URL parentURL, URI contributionURI, URL contributionURL) throws ContributionReadException {
-
- // Create contribution model
- Contribution contribution = contributionFactory.createContribution();
- contribution.setURI(contributionURI.toString());
- contribution.setLocation(contributionURL.toString());
- ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories, monitor);
- contribution.setModelResolver(modelResolver);
- contribution.setUnresolved(true);
-
- // Create a contribution scanner
- ContributionScanner scanner = null;
- if (scanner == null) {
- try {
- if ("file".equals(contributionURL.getProtocol()) && new File(contributionURL.toURI()).isDirectory()) {
- scanner = new DirectoryContributionScanner();
- } else {
- scanner = new JarContributionScanner();
- }
- } catch (URISyntaxException e) {
- throw new ContributionReadException(e);
- }
- }
-
- // Read generated and user sca-contribution.xml files
- boolean contributionMetadata = false;
- for (String path: new String[]{
- Contribution.SCA_CONTRIBUTION_GENERATED_META,
- Contribution.SCA_CONTRIBUTION_META}) {
- URL url = scanner.getArtifactURL(contribution, path);
- try {
- // Check if the file actually exists before trying to read it
- InputStream is = IOHelper.openStream(url);
- is.close();
- } catch (IOException e) {
- continue;
- }
- contributionMetadata = true;
-
- // Read the sca-contribution.xml file
- ContributionMetadata c = (ContributionMetadata)artifactProcessor.read(contributionURL, URI.create(path), url);
- contribution.getImports().addAll(c.getImports());
- contribution.getExports().addAll(c.getExports());
- contribution.getDeployables().addAll(c.getDeployables());
- contribution.getExtensions().addAll(c.getExtensions());
- contribution.getAttributeExtensions().addAll(c.getAttributeExtensions());
- }
-
- // If no sca-contribution.xml file was provided then consider
- // all composites in the contribution as deployables, and also
- // read any files that are explicitly asssigned artifact processors
- // as they are likely to provide relevant metadata info
- if (!contributionMetadata) {
- List<String> artifactURIs;
- try {
- artifactURIs = scanner.scan(contribution);
- } catch (ContributionReadException e) {
- artifactURIs = null;
- }
- if (artifactURIs != null) {
- for (String artifactURI: artifactURIs) {
- boolean read = false;
- if (artifactURI.endsWith(".composite")) {
- read = true;
- } else {
- int s= artifactURI.lastIndexOf("/");
- String fileName = artifactURI.substring(s + 1);
- if (artifactProcessors.getProcessor(fileName) != null) {
- read = true;
- }
- }
- if (read) {
- URL artifactURL = scanner.getArtifactURL(contribution, artifactURI);
-
- // Read each artifact
- Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL);
-
- // In the absence of more info, consider all composites as deployable
- if (model instanceof Composite) {
- contribution.getDeployables().add((Composite)model);
- }
- }
- }
- }
-
- // Add default contribution import and export
- DefaultImport defaultImport = contributionFactory.createDefaultImport();
- defaultImport.setModelResolver(new DefaultModelResolver());
- contribution.getImports().add(defaultImport);
- DefaultExport defaultExport = contributionFactory.createDefaultExport();
- contribution.getExports().add(defaultExport);
- }
-
- return contribution;
- }
-
- public void resolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException {
-
- // Mark the contribution model resolved
- ModelResolver contributionResolver = contribution.getModelResolver();
- contribution.setUnresolved(false);
- contributionResolver.addModel(contribution);
-
- // Resolve imports and exports
- for (Export export: contribution.getExports()) {
- if (export instanceof DefaultExport) {
-
- // Initialize the default export's resolver
- export.setModelResolver(contributionResolver);
-
- } else {
- extensionProcessor.resolve(export, contributionResolver);
- }
- }
- for (Import import_: contribution.getImports()) {
- extensionProcessor.resolve(import_, contributionResolver);
- }
-
- }
-
- /**
- * FIXME Temporary hack for testing the ClassLoaderModelResolver.
- *
- * @param modelResolvers
- */
- private static void hackResolvers(ModelResolverExtensionPoint modelResolvers) {
- Class<?> resolverClass = modelResolvers.getResolver(ClassReference.class);
- if (resolverClass==null || !resolverClass.getName().equals("org.apache.tuscany.sca.contribution.java.impl.ClassLoaderModelResolver")) {
- try {
- Class<?> loaderResolverClass = Class.forName("org.apache.tuscany.sca.contribution.java.impl.ClassLoaderModelResolver", true, ContributionContentProcessor.class.getClassLoader());
- modelResolvers.addResolver(ClassReference.class, (Class<? extends ModelResolver>)loaderResolverClass);
- } catch (ClassNotFoundException e) {
- }
- }
- }
-}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java
index 3188b1ca60..f589c6b911 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java
@@ -30,10 +30,10 @@ 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.ExtensibleStAXAttributeProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
/**
* A Policy Processor used for testing.
@@ -44,7 +44,7 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements
private AssemblyFactory assemblyFactory;
- public AnyAttributeProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ public AnyAttributeProcessor(FactoryExtensionPoint modelFactories) {
this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
}
@@ -56,7 +56,7 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements
return Extension.class;
}
- public Extension read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public Extension read(QName attributeName, XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
String attributeValue = reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart());
Extension ext = assemblyFactory.createExtension();
ext.setQName(attributeName);
@@ -65,7 +65,7 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements
return ext;
}
- public void write(Extension attributeExtension, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ public void write(Extension attributeExtension, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
writer.writeAttribute(attributeExtension.getQName().getPrefix(),
attributeExtension.getQName().getNamespaceURI(),
attributeExtension.getQName().getLocalPart(),
@@ -73,7 +73,7 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements
// are just the string representation fo the attribute
}
- public void resolve(Extension model, ModelResolver modelResolver) throws ContributionResolveException {
+ public void resolve(Extension model, ModelResolver modelResolver, ProcessorContext context) throws ContributionResolveException {
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
index 0b471d1146..db4feeec48 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java
@@ -31,25 +31,20 @@ import org.apache.tuscany.sca.common.xml.stax.StAXHelper;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
public class AnyElementProcessor implements StAXArtifactProcessor<Extension> {
private AssemblyFactory assemblyFactory;
private StAXHelper helper;
- @SuppressWarnings("unused")
- private Monitor monitor;
-
-
- public AnyElementProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) {
+ public AnyElementProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor) {
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
this.helper = StAXHelper.getInstance(extensionPoints);
- this.monitor = monitor;
}
public QName getArtifactType() {
@@ -68,7 +63,7 @@ public class AnyElementProcessor implements StAXArtifactProcessor<Extension> {
* @return
* @throws XMLStreamException
*/
- public Extension read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public Extension read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
QName name = reader.getName();
String xml = helper.saveAsString(reader);
Extension ext = assemblyFactory.createExtension();
@@ -84,7 +79,7 @@ public class AnyElementProcessor implements StAXArtifactProcessor<Extension> {
* @param model
* @param writer
*/
- public void write(Extension model, XMLStreamWriter writer) throws XMLStreamException {
+ public void write(Extension model, XMLStreamWriter writer, ProcessorContext context) throws XMLStreamException {
Object value = model.getValue();
if (!(value instanceof String)) {
return;
@@ -96,6 +91,6 @@ public class AnyElementProcessor implements StAXArtifactProcessor<Extension> {
helper.save(reader, writer);
}
- public void resolve(Extension model, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(Extension model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java
index 13c622adf0..e17dd176a6 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java
@@ -22,6 +22,7 @@ package org.apache.tuscany.sca.contribution.resolver;
import java.util.List;
import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
/**
* A model resolver implementation that delegates to a list of model resolvers.
@@ -36,22 +37,22 @@ public class DefaultDelegatingModelResolver implements ModelResolver {
this.resolvers = resolvers;
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
//TODO optimize and cache results of the resolution later
// Go over all resolvers
for (ModelResolver resolver: resolvers) {
- Object resolved = resolver.resolveModel(modelClass, unresolved);
+ Object resolved = resolver.resolveModel(modelClass, unresolved, context);
// Return the resolved model object
if (resolved instanceof Base) {
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java
index 5cbf37cf70..7745253bba 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java
@@ -25,6 +25,7 @@ import org.apache.tuscany.sca.assembly.Base;
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.processor.ProcessorContext;
/**
* A model resolver implementation that considers Exports in a list of contributions.
@@ -41,15 +42,15 @@ public class DefaultImportAllModelResolver implements ModelResolver {
this.contributions = contributions;
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
//TODO optimize and cache results of the resolution later
@@ -61,7 +62,7 @@ public class DefaultImportAllModelResolver implements ModelResolver {
// If the export matches the export, try to resolve the model object
if (import_.match(export)) {
- Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved);
+ Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved, context);
// Return the resolved model object
if (resolved instanceof Base) {
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java
index 9ae57c41d0..8a11cb42f8 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.tuscany.sca.assembly.Base;
import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
/**
* A model resolver implementation that delegates to a list of exports.
@@ -37,22 +38,22 @@ public class DefaultImportModelResolver implements ModelResolver {
this.exports = exports;
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
throw new IllegalStateException();
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
//TODO optimize and cache results of the resolution later
// Go over all exports
for (Export export: exports) {
- Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved);
+ Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved, context);
// Return the resolved model object
if (resolved instanceof Base) {
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
index 12e5543672..94b2fb0058 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
@@ -25,8 +25,8 @@ import java.util.Map;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.DefaultImport;
import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
/**
* A default implementation of a model resolver based on a map.
@@ -41,11 +41,11 @@ public class DefaultModelResolver implements ModelResolver {
public DefaultModelResolver() {
}
- public DefaultModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) {
+ public DefaultModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
this.contribution = contribution;
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
Object resolved = map.get(unresolved);
if (resolved != null) {
@@ -59,7 +59,7 @@ public class DefaultModelResolver implements ModelResolver {
if (contribution != null){
for (Import _import : contribution.getImports()){
if (_import instanceof DefaultImport){
- resolved = _import.getModelResolver().resolveModel(modelClass, unresolved);
+ resolved = _import.getModelResolver().resolveModel(modelClass, unresolved, context);
if (resolved != unresolved){
return modelClass.cast(resolved);
}
@@ -72,11 +72,11 @@ public class DefaultModelResolver implements ModelResolver {
}
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
map.put(resolved, resolved);
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
return map.remove(resolved);
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java
index 1e6c0f7a18..72e4b03c7f 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java
@@ -24,8 +24,8 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
/**
* An implementation of an extensible model resolver which delegates to the
@@ -42,31 +42,6 @@ public class ExtensibleModelResolver implements ModelResolver {
private final Map<Class<?>, ModelResolver> resolversByImplementationClass = new HashMap<Class<?>, ModelResolver>();
private Map<Object, Object> map = new HashMap<Object, Object>();
private Object lastUnresolved;
- private Monitor monitor;
-
- /**
- * Constructs an extensible model resolver
- *
- * @param contribution
- * @param resolverExtensions
- * @param modelFactories
- * @param defaultResolver
- */
- @Deprecated
- public ExtensibleModelResolver(Contribution contribution,
- ModelResolverExtensionPoint resolverExtensions,
- FactoryExtensionPoint modelFactories,
- ModelResolver defaultResolver,
- Monitor monitor) {
- this.contribution = contribution;
- this.resolverExtensions = resolverExtensions;
- this.modelFactories = modelFactories;
- //FIXME Remove this default resolver, this is currently used to resolve policy declarations
- // but they should be handled by the contribution import/export mechanism instead of this
- // defaultResolver hack.
- this.defaultResolver = defaultResolver;
- this.monitor = monitor;
- }
/**
* Constructs an extensible model resolver
@@ -77,12 +52,10 @@ public class ExtensibleModelResolver implements ModelResolver {
*/
public ExtensibleModelResolver(Contribution contribution,
ModelResolverExtensionPoint resolverExtensions,
- FactoryExtensionPoint modelFactories,
- Monitor monitor) {
+ FactoryExtensionPoint modelFactories) {
this.contribution = contribution;
this.resolverExtensions = resolverExtensions;
this.modelFactories = modelFactories;
- this.monitor = monitor;
}
/**
@@ -123,10 +96,10 @@ public class ExtensibleModelResolver implements ModelResolver {
try {
Constructor<? extends ModelResolver> constructor =
resolverClass
- .getConstructor(new Class[] {Contribution.class, FactoryExtensionPoint.class, Monitor.class});
+ .getConstructor(new Class[] {Contribution.class, FactoryExtensionPoint.class});
if (constructor != null) {
- resolverInstance = constructor.newInstance(contribution, modelFactories, monitor);
+ resolverInstance = constructor.newInstance(contribution, modelFactories);
resolversByImplementationClass.put(resolverClass, resolverInstance);
resolversByModelType.put(c, resolverInstance);
return resolverInstance;
@@ -140,25 +113,25 @@ public class ExtensibleModelResolver implements ModelResolver {
return null;
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
ModelResolver resolver = getModelResolverInstance(resolved.getClass());
if (resolver != null) {
- resolver.addModel(resolved);
+ resolver.addModel(resolved, context);
} else {
map.put(resolved, resolved);
}
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
ModelResolver resolver = getModelResolverInstance(resolved.getClass());
if (resolver != null) {
- return resolver.removeModel(resolved);
+ return resolver.removeModel(resolved, context);
} else {
return map.remove(resolved);
}
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
// Protect against dependency cycles causing infinite recursion
// Save the current unresolved object and check later if we are trying
// to resolve the same object again
@@ -169,7 +142,7 @@ public class ExtensibleModelResolver implements ModelResolver {
ModelResolver resolver = getModelResolverInstance(unresolved.getClass());
if (resolver != null) {
- Object resolved = resolver.resolveModel(modelClass, unresolved);
+ Object resolved = resolver.resolveModel(modelClass, unresolved, context);
if (resolved != null && resolved != unresolved) {
lastUnresolved = null;
return modelClass.cast(resolved);
@@ -179,7 +152,7 @@ public class ExtensibleModelResolver implements ModelResolver {
// but they should be handled by the contribution import/export mechanism instead of this
// defaultResolver hack.
if (defaultResolver != null) {
- Object resolved = defaultResolver.resolveModel(modelClass, unresolved);
+ Object resolved = defaultResolver.resolveModel(modelClass, unresolved, context);
if (resolved != null && resolved != unresolved) {
lastUnresolved = null;
return modelClass.cast(resolved);
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java
index 2831bebbc4..ec8495d1d2 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java
@@ -19,6 +19,8 @@
package org.apache.tuscany.sca.contribution.resolver;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+
/**
* A model resolver, responsible for resolving models in the scope of an
* SCA contribution.
@@ -47,23 +49,26 @@ public interface ModelResolver {
*
* @param modelClass the type of artifact
* @param unresolved the unresolved model
+ * @param context The context
* @return the resolved model
*/
- <T> T resolveModel(Class<T> modelClass, T unresolved);
+ <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context);
/**
* Add a resolved model.
*
* @param resolved The model
+ * @param context
*/
- void addModel(Object resolved);
+ void addModel(Object resolved, ProcessorContext context);
/**
* Remove a resolved model.
*
* @param resolved
+ * @param context
* @return The removed model, or null if the model was not removed
*/
- Object removeModel(Object resolved);
+ Object removeModel(Object resolved, ProcessorContext context);
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java
index 0035f360ab..2a36d4fd54 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java
@@ -22,7 +22,6 @@ import javax.xml.stream.XMLInputFactory;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
/**
* URLArtifactProcessor that handles sca-contribution-generated.xml files.
@@ -32,15 +31,13 @@ import org.apache.tuscany.sca.monitor.Monitor;
public class ContributionGeneratedMetadataDocumentProcessor extends ContributionMetadataDocumentProcessor {
public ContributionGeneratedMetadataDocumentProcessor(XMLInputFactory inputFactory,
- StAXArtifactProcessor staxProcessor,
- Monitor monitor) {
- super(inputFactory, staxProcessor, monitor);
+ StAXArtifactProcessor staxProcessor) {
+ super(inputFactory, staxProcessor);
}
public ContributionGeneratedMetadataDocumentProcessor(FactoryExtensionPoint modelFactories,
- StAXArtifactProcessor staxProcessor,
- Monitor monitor) {
- super(modelFactories, staxProcessor, monitor);
+ StAXArtifactProcessor staxProcessor) {
+ super(modelFactories, staxProcessor);
}
@Override
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
index 0ab817e1bc..69cd29ea2e 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
@@ -31,6 +31,7 @@ import org.apache.tuscany.sca.common.java.io.IOHelper;
import org.apache.tuscany.sca.contribution.ContributionMetadata;
import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory;
@@ -48,22 +49,17 @@ import org.apache.tuscany.sca.monitor.Problem.Severity;
public class ContributionMetadataDocumentProcessor implements URLArtifactProcessor<ContributionMetadata>{
private final StAXArtifactProcessor staxProcessor;
private final XMLInputFactory inputFactory;
- private final Monitor monitor;
public ContributionMetadataDocumentProcessor(XMLInputFactory inputFactory,
- StAXArtifactProcessor staxProcessor,
- Monitor monitor) {
+ StAXArtifactProcessor staxProcessor) {
this.inputFactory = inputFactory;
this.staxProcessor = staxProcessor;
- this.monitor = monitor;
}
public ContributionMetadataDocumentProcessor(FactoryExtensionPoint modelFactories,
- StAXArtifactProcessor staxProcessor,
- Monitor monitor) {
+ StAXArtifactProcessor staxProcessor) {
this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
this.staxProcessor = staxProcessor;
- this.monitor = monitor;
}
/**
@@ -73,7 +69,7 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess
* @param message
* @param model
*/
- private void error(String message, Object model, Exception ex) {
+ private void error(Monitor monitor, String message, Object model, Exception ex) {
if (monitor != null) {
Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-xml-validation-messages", Severity.ERROR, model, message, ex);
monitor.problem(problem);
@@ -88,7 +84,7 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess
return ContributionMetadata.class;
}
- public ContributionMetadata read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ public ContributionMetadata read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException {
InputStream urlStream = null;
try {
@@ -98,17 +94,17 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess
reader.nextTag();
// Read the contribution model
- ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader);
+ ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context);
return contribution;
} catch (XMLStreamException e) {
ContributionReadException ex = new ContributionReadException(e);
- error("XMLStreamException", inputFactory, ex);
+ error(context.getMonitor(), "XMLStreamException", inputFactory, ex);
throw ex;
} catch (IOException e) {
ContributionReadException ex = new ContributionReadException(e);
- error("IOException", inputFactory, ex);
+ error(context.getMonitor(), "IOException", inputFactory, ex);
throw ex;
} finally {
try {
@@ -122,8 +118,8 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess
}
}
- public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException {
- staxProcessor.resolve(contribution, resolver);
+ public void resolve(ContributionMetadata contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ staxProcessor.resolve(contribution, resolver, context);
}
}
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
index 7218a0fb73..4700041775 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
@@ -38,6 +38,7 @@ import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
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.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
@@ -62,17 +63,15 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
private final ContributionFactory contributionFactory;
private final StAXArtifactProcessor<Object> extensionProcessor;
private final StAXAttributeProcessor<Object> attributeProcessor;
- private Monitor monitor;
+
public ContributionMetadataProcessor(FactoryExtensionPoint modelFactories,
StAXArtifactProcessor<Object> extensionProcessor,
- StAXAttributeProcessor<Object> attributeProcessor,
- Monitor monitor) {
+ StAXAttributeProcessor<Object> attributeProcessor) {
this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
this.extensionProcessor = extensionProcessor;
this.attributeProcessor = attributeProcessor;
- this.monitor = monitor;
}
/**
@@ -82,7 +81,7 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
* @param message
* @param model
*/
- private void error(String message, Object model, Object... messageParameters) {
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(),
@@ -102,7 +101,7 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
* @param message
* @param model
*/
- private void error(String message, Object model, Exception ex) {
+ private void error(Monitor monitor, String message, Object model, Exception ex) {
if (monitor != null) {
Problem problem =
monitor.createProblem(this.getClass().getName(), "contribution-xml-validation-messages", Severity.ERROR,
@@ -119,7 +118,7 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
return ContributionMetadata.class;
}
- public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException {
+ public ContributionMetadata read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
ContributionMetadata contribution = null;
QName name = null;
@@ -135,14 +134,14 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
// Read <contribution>
contribution = this.contributionFactory.createContributionMetadata();
contribution.setUnresolved(true);
- readExtendedAttributes(reader, contribution, attributeProcessor, assemblyFactory);
+ readExtendedAttributes(reader, contribution, attributeProcessor, assemblyFactory, context);
} else if (DEPLOYABLE_QNAME.equals(name)) {
// Read <deployable>
QName compositeName = getQName(reader, "composite");
if (compositeName == null) {
- error("AttributeCompositeMissing", reader);
+ error(context.getMonitor(), "AttributeCompositeMissing", reader);
//throw new ContributionReadException("Attribute 'composite' is missing");
} else {
if (contribution != null) {
@@ -155,7 +154,7 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
} else {
// Read an extension element
- Object extension = extensionProcessor.read(reader);
+ Object extension = extensionProcessor.read(reader, context);
if (extension != null && contribution != null) {
if (extension instanceof Import) {
contribution.getImports().add((Import)extension);
@@ -182,27 +181,27 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
}
} catch (XMLStreamException e) {
ContributionReadException ex = new ContributionReadException(e);
- error("XMLStreamException", reader, ex);
+ error(context.getMonitor(), "XMLStreamException", reader, ex);
}
return contribution;
}
- public void write(ContributionMetadata contribution, XMLStreamWriter writer) throws ContributionWriteException,
+ public void write(ContributionMetadata contribution, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException,
XMLStreamException {
// Write <contribution>
writeStartDocument(writer, CONTRIBUTION_QNAME.getNamespaceURI(), CONTRIBUTION_QNAME.getLocalPart());
- writeExtendedAttributes(writer, contribution, attributeProcessor);
+ writeExtendedAttributes(writer, contribution, attributeProcessor, context);
// Write <import>
for (Import imp : contribution.getImports()) {
- extensionProcessor.write(imp, writer);
+ extensionProcessor.write(imp, writer, context);
}
// Write <export>
for (Export export : contribution.getExports()) {
- extensionProcessor.write(export, writer);
+ extensionProcessor.write(export, writer, context);
}
// Write <deployable>
@@ -217,28 +216,28 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp
writeEndDocument(writer);
}
- public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(ContributionMetadata contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
// Resolve imports and exports
for (Export export : contribution.getExports()) {
- extensionProcessor.resolve(export, resolver);
+ extensionProcessor.resolve(export, resolver, context);
}
for (Import import_ : contribution.getImports()) {
- extensionProcessor.resolve(import_, resolver);
+ extensionProcessor.resolve(import_, resolver, context);
}
// Resolve deployable composites
List<Composite> deployables = contribution.getDeployables();
for (int i = 0, n = deployables.size(); i < n; i++) {
Composite deployable = deployables.get(i);
- Composite resolved = (Composite)resolver.resolveModel(Composite.class, deployable);
+ Composite resolved = (Composite)resolver.resolveModel(Composite.class, deployable, context);
if (resolved != deployable) {
deployables.set(i, resolved);
}
}
for (Object ext : contribution.getExtensions()) {
- extensionProcessor.resolve(ext, resolver);
+ extensionProcessor.resolve(ext, resolver, context);
}
contribution.setUnresolved(false);
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java
index 91e74edf47..916630939e 100644
--- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java
+++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java
@@ -23,9 +23,9 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
/**
* A Model Resolver for Contribution models.
@@ -36,19 +36,19 @@ public class ContributionModelResolver implements ModelResolver {
private Map<String, Contribution> map = new HashMap<String, Contribution>();
- public ContributionModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) {
+ public ContributionModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
Contribution contribution = (Contribution)resolved;
map.put(contribution.getURI(), contribution);
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
return map.remove(((Contribution)resolved).getURI());
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
// Lookup a contribution for the given URI
String uri = ((Contribution)unresolved).getURI();
diff --git a/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
index 560bf9abcb..f831bf061c 100644
--- a/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
+++ b/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
@@ -19,4 +19,3 @@
org.apache.tuscany.sca.contribution.xml.ContributionMetadataDocumentProcessor;type=/META-INF/sca-contribution.xml,model=org.apache.tuscany.sca.contribution.ContributionMetadata
org.apache.tuscany.sca.contribution.xml.ContributionGeneratedMetadataDocumentProcessor;type=/META-INF/sca-contribution-generated.xml
org.apache.tuscany.sca.contribution.processor.impl.ContributionContentProcessor;type=.contribution/content,model=org.apache.tuscany.sca.contribution.Contribution
-org.apache.tuscany.sca.contribution.processor.impl.ContributionInfoProcessor;type=.contribution/info
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java
deleted file mode 100644
index 13945eac24..0000000000
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java
+++ /dev/null
@@ -1,75 +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 org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.tuscany.sca.contribution.resolver.ClassReference;
-import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
-import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Test ClassReferenceArtifactResolver.
- *
- * @version $Rev$ $Date$
- */
-public class ClassReferenceArtifactResolverTestCase {
- private static ExtensibleModelResolver resolver;
-
- @BeforeClass
- public static void setUp() throws Exception {
- ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
-
- ModelResolverExtensionPoint resolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
- resolvers.addResolver(ClassReference.class, ClassReferenceModelResolver.class);
- FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
- resolver = new ExtensibleModelResolver(null, resolvers, modelFactories, null);
- }
-
- /**
- * Test ClassReference resolution
- *
- */
- @Test
- public void testResolveClass() {
- ClassReference ref = new ClassReference(getClass().getName());
- ClassReference clazz = resolver.resolveModel(ClassReference.class, ref);
- assertFalse(clazz.isUnresolved());
- assertTrue(clazz.getJavaClass() == getClass());
- }
-
- /**
- * Test ClassReference resolution of inexistent class
- *
- */
- @Test
- public void testUnresolvedClass() {
- ClassReference ref = new ClassReference("NonExistentClass");
- ClassReference clazz = resolver.resolveModel(ClassReference.class, ref);
- assertTrue(clazz.isUnresolved());
- assertTrue(clazz.getJavaClass() == null);
- }
-}
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java
index c6bd430e96..f25fb5d981 100644
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java
+++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java
@@ -29,14 +29,12 @@ import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.contribution.java.JavaExport;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -60,20 +58,17 @@ public class JavaExportProcessorTestCase {
private static XMLInputFactory inputFactory;
private static StAXArtifactProcessor<Object> staxProcessor;
private static Monitor monitor;
+ private static ProcessorContext context;
+
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ monitor = context.getMonitor();
inputFactory = XMLInputFactory.newInstance();
- // Create a monitor
- UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = new DefaultMonitorFactory();
- if (monitorFactory != null) {
- monitor = monitorFactory.createMonitor();
- utilities.addUtility(monitorFactory);
- }
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
}
/**
@@ -83,7 +78,7 @@ public class JavaExportProcessorTestCase {
@Test
public void testLoad() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
- JavaExport javaExport = (JavaExport)staxProcessor.read(reader);
+ JavaExport javaExport = (JavaExport)staxProcessor.read(reader, context);
Assert.assertEquals("org.apache.tuscany.sca.contribution.java", javaExport.getPackage());
}
@@ -100,7 +95,7 @@ public class JavaExportProcessorTestCase {
} catch (ContributionReadException e) {
assertTrue(true);
}*/
- staxProcessor.read(reader);
+ staxProcessor.read(reader, context);
Problem problem = monitor.getLastProblem();
assertNotNull(problem);
assertEquals("AttributePackageMissing", problem.getMessageId());
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java
index 7bcafd6c48..f3b52117bb 100644
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java
+++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java
@@ -29,14 +29,12 @@ import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.contribution.java.JavaImport;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -60,19 +58,18 @@ public class JavaImportProcessorTestCase {
private static StAXArtifactProcessor<Object> staxProcessor;
private static Monitor monitor;
+ private static ProcessorContext context;
+
+
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ monitor = context.getMonitor();
inputFactory = XMLInputFactory.newInstance();
- // Create a monitor
- UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = new DefaultMonitorFactory();
- if (monitorFactory != null) {
- monitor = monitorFactory.createMonitor();
- utilities.addUtility(monitorFactory);
- }
+
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
}
/**
@@ -82,7 +79,7 @@ public class JavaImportProcessorTestCase {
@Test
public void testLoad() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
- JavaImport javaImport = (JavaImport)staxProcessor.read(reader);
+ JavaImport javaImport = (JavaImport)staxProcessor.read(reader, context);
assertEquals("org.apache.tuscany.sca.contribution.java", javaImport.getPackage());
assertEquals("sca://contributions/001", javaImport.getLocation());
@@ -101,7 +98,7 @@ public class JavaImportProcessorTestCase {
} catch (ContributionReadException e) {
assertTrue(true);
}*/
- staxProcessor.read(reader);
+ staxProcessor.read(reader, context);
Problem problem = monitor.getLastProblem();
assertNotNull(problem);
assertEquals("AttributePackageMissing", problem.getMessageId());
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java
index a1c5189767..cec66b23c3 100644
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java
+++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java
@@ -29,14 +29,12 @@ import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.contribution.namespace.NamespaceExport;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -60,21 +58,18 @@ public class NamespaceExportProcessorTestCase {
private static XMLInputFactory inputFactory;
private static StAXArtifactProcessor<Object> staxProcessor;
private static Monitor monitor;
+ private static ProcessorContext context;
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ monitor = context.getMonitor();
inputFactory = XMLInputFactory.newInstance();
- // Create a monitor
- UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = new DefaultMonitorFactory();
- if (monitorFactory != null) {
- monitor = monitorFactory.createMonitor();
- utilities.addUtility(monitorFactory);
- }
+
StAXArtifactProcessorExtensionPoint staxProcessors =
extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
}
/**
@@ -84,7 +79,7 @@ public class NamespaceExportProcessorTestCase {
@Test
public void testLoad() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
- NamespaceExport namespaceExport = (NamespaceExport)staxProcessor.read(reader);
+ NamespaceExport namespaceExport = (NamespaceExport)staxProcessor.read(reader, context);
assertEquals("http://foo", namespaceExport.getNamespace());
assertEquals(1, namespaceExport.getAttributeExtensions().size());
assertEquals(1, namespaceExport.getExtensions().size());
@@ -103,7 +98,7 @@ public class NamespaceExportProcessorTestCase {
} catch (ContributionReadException e) {
assertTrue(true);
}*/
- staxProcessor.read(reader);
+ staxProcessor.read(reader, context);
Problem problem = monitor.getLastProblem();
assertNotNull(problem);
assertEquals("AttributeNameSpaceMissing", problem.getMessageId());
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java
index 676437042d..03407f9065 100644
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java
+++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java
@@ -31,14 +31,12 @@ import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -63,20 +61,17 @@ public class NamespaceImportProcessorTestCase {
private static XMLInputFactory inputFactory;
private static StAXArtifactProcessor<Object> staxProcessor;
private static Monitor monitor;
+ private static ProcessorContext context;
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ monitor = context.getMonitor();
inputFactory = XMLInputFactory.newInstance();
- // Create a monitor
- UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = new DefaultMonitorFactory();
- if (monitorFactory != null) {
- monitor = monitorFactory.createMonitor();
- utilities.addUtility(monitorFactory);
- }
+
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
}
/**
@@ -86,7 +81,7 @@ public class NamespaceImportProcessorTestCase {
@Test
public void testLoad() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
- NamespaceImport namespaceImport = (NamespaceImport)staxProcessor.read(reader);
+ NamespaceImport namespaceImport = (NamespaceImport)staxProcessor.read(reader, context);
assertEquals("http://foo", namespaceImport.getNamespace());
assertEquals("sca://contributions/001", namespaceImport.getLocation());
@@ -107,7 +102,7 @@ public class NamespaceImportProcessorTestCase {
} catch (ContributionReadException e) {
assertTrue(true);
}*/
- staxProcessor.read(reader);
+ staxProcessor.read(reader, context);
Problem problem = monitor.getLastProblem();
assertNotNull(problem);
assertEquals("AttributeNameSpaceMissing", problem.getMessageId());
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java
index 3a18e2b987..9587d3c024 100644
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java
+++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java
@@ -77,11 +77,11 @@ public class URLartifactProcessorExtensionPointTestCase {
public FileTypeArtifactProcessor() {
}
- public M1 read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ public M1 read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException {
return null;
}
- public void resolve(M1 m1, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(M1 m1, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
}
public String getArtifactType() {
@@ -97,11 +97,11 @@ public class URLartifactProcessorExtensionPointTestCase {
public FileNameArtifactProcessor() {
}
- public M2 read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ public M2 read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException {
return null;
}
- public void resolve(M2 m2, ModelResolver resolver) throws ContributionResolveException {
+ public void resolve(M2 m2, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
}
public String getArtifactType() {
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java
index b778167217..58d1616aa2 100644
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java
+++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.junit.Before;
import org.junit.Test;
@@ -45,28 +46,30 @@ public class DefaultModelResolverTestCase {
@Test
public void testResolved() {
+ ProcessorContext context = new ProcessorContext();
Model a = new Model("a");
- resolver.addModel(a);
+ resolver.addModel(a, context);
Model x = new Model("a");
- x = resolver.resolveModel(Model.class, x);
+ x = resolver.resolveModel(Model.class, x, context);
assertTrue(x == a);
}
@Test
public void testUnresolved() {
Model x = new Model("a");
- Model y = resolver.resolveModel(Model.class, x);
+ Model y = resolver.resolveModel(Model.class, x, new ProcessorContext());
assertTrue(x == y);
}
@Test
public void testResolvedArtifact() {
+ ProcessorContext context = new ProcessorContext();
Artifact artifact = factory.createArtifact();
artifact.setURI("foo/bar");
- resolver.addModel(artifact);
+ resolver.addModel(artifact, context);
Artifact x = factory.createArtifact();
x.setURI("foo/bar");
- x = resolver.resolveModel(Artifact.class, x);
+ x = resolver.resolveModel(Artifact.class, x, context);
assertTrue(x == artifact);
}
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java
index b5cfa6f63d..d6461bd094 100644
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java
+++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java
@@ -24,10 +24,10 @@ import static org.junit.Assert.assertTrue;
import org.apache.tuscany.sca.contribution.Artifact;
import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
import org.junit.Before;
import org.junit.Test;
@@ -40,16 +40,17 @@ public class ExtensibleModelResolverTestCase {
private ExtensibleModelResolver resolver;
private ContributionFactory factory;
+ private ProcessorContext context;
@Before
public void setUp() throws Exception {
ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint();
resolvers.addResolver(Model.class, TestModelResolver.class);
-
+ context = new ProcessorContext();
FactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry());
- resolver = new ExtensibleModelResolver(null, resolvers, factories, (Monitor)null);
+ resolver = new ExtensibleModelResolver(null, resolvers, factories);
factory = new DefaultContributionFactory();
}
@@ -57,32 +58,32 @@ public class ExtensibleModelResolverTestCase {
@Test
public void testResolvedDefault() {
OtherModel a = new OtherModel("a");
- resolver.addModel(a);
+ resolver.addModel(a, context);
OtherModel x = new OtherModel("a");
- x = resolver.resolveModel(OtherModel.class, x);
+ x = resolver.resolveModel(OtherModel.class, x, context);
assertTrue(x == a);
}
@Test
public void testResolvedRegisteredClass() {
Model a = new Model("a");
- resolver.addModel(a);
+ resolver.addModel(a, context);
Model x = new Model("a");
- x = resolver.resolveModel(Model.class, x);
+ x = resolver.resolveModel(Model.class, x, context);
assertTrue(x == a);
}
@Test
public void testUnresolvedDefault() {
OtherModel x = new OtherModel("a");
- OtherModel y = resolver.resolveModel(OtherModel.class, x);
+ OtherModel y = resolver.resolveModel(OtherModel.class, x, context);
assertTrue(x == y);
}
@Test
public void testUnresolved() {
Model x = new Model("a");
- Model y = resolver.resolveModel(Model.class, x);
+ Model y = resolver.resolveModel(Model.class, x, context);
assertTrue(x == y);
}
@@ -90,10 +91,10 @@ public class ExtensibleModelResolverTestCase {
public void testResolvedArtifact() {
Artifact artifact = factory.createArtifact();
artifact.setURI("foo/bar");
- resolver.addModel(artifact);
+ resolver.addModel(artifact, context);
Artifact x = factory.createArtifact();
x.setURI("foo/bar");
- x = resolver.resolveModel(Artifact.class, x);
+ x = resolver.resolveModel(Artifact.class, x, context);
assertTrue(x == artifact);
}
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java
index 2782e9b318..c04d56cafe 100644
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java
+++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java
@@ -23,8 +23,8 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
/**
* A test implementation of a model resolver, based on a map.
@@ -35,10 +35,10 @@ public class TestModelResolver implements ModelResolver {
private Map<Object, Object> map = new HashMap<Object, Object>();
- public TestModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) {
+ public TestModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
}
- public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
Object resolved = map.get(unresolved);
if (resolved != null) {
// Return the resolved object
@@ -48,11 +48,11 @@ public class TestModelResolver implements ModelResolver {
return unresolved;
}
- public void addModel(Object resolved) {
+ public void addModel(Object resolved, ProcessorContext context) {
map.put(resolved, resolved);
}
- public Object removeModel(Object resolved) {
+ public Object removeModel(Object resolved, ProcessorContext context) {
return map.remove(resolved);
}
diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java
index b72c476267..1d0ea5dc8a 100644
--- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java
+++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java
@@ -33,14 +33,12 @@ import javax.xml.stream.XMLStreamWriter;
import org.apache.tuscany.sca.contribution.ContributionMetadata;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.monitor.Problem;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -71,31 +69,25 @@ public class ContributionMetadataProcessorTestCase {
private static XMLOutputFactory outputFactory;
private static StAXArtifactProcessor<Object> staxProcessor;
private static Monitor monitor;
-
+ private static ProcessorContext context;
+
@BeforeClass
public static void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
-
+ context = new ProcessorContext(extensionPoints);
+ monitor = context.getMonitor();
inputFactory = XMLInputFactory.newInstance();
outputFactory = XMLOutputFactory.newInstance();
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
-
- // Create a monitor
- UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = new DefaultMonitorFactory();
- if (monitorFactory != null) {
- monitor = monitorFactory.createMonitor();
- utilities.addUtility(monitorFactory);
- }
StAXArtifactProcessorExtensionPoint staxProcessors =
extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory);
}
@Test
public void testRead() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
- ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader);
+ ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context);
assertNotNull(contribution);
assertEquals(2, contribution.getDeployables().size());
assertEquals(1, contribution.getAttributeExtensions().size());
@@ -111,7 +103,7 @@ public class ContributionMetadataProcessorTestCase {
} catch (ContributionReadException e) {
assertTrue(true);
}*/
- staxProcessor.read(reader);
+ staxProcessor.read(reader, context);
Problem problem = monitor.getLastProblem();
assertNotNull(problem);
assertEquals("AttributeCompositeMissing", problem.getMessageId());
@@ -120,18 +112,18 @@ public class ContributionMetadataProcessorTestCase {
@Test
public void testWrite() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
- ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader);
+ ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context);
validateContribution(contribution);
//write the contribution metadata contents
StringWriter stringWriter = new StringWriter();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stringWriter);
- staxProcessor.write(contribution, writer);
+ staxProcessor.write(contribution, writer, context);
stringWriter.close();
reader = inputFactory.createXMLStreamReader(new StringReader(stringWriter.toString()));
- contribution = (ContributionMetadata)staxProcessor.read(reader);
+ contribution = (ContributionMetadata)staxProcessor.read(reader, context);
validateContribution(contribution);
}