summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-java
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-16 05:42:26 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-16 05:42:26 +0000
commit4ae4002366ded3f4b19cd96f403d8b418fcf00a1 (patch)
tree9179891f11c9add734a777713cabf7e39a980908 /java/sca/modules/implementation-java
parentd4cc9a0bdd43477858b8ac67b69a4cdd615ec741 (diff)
This is to change the Monitor to be request scoped for most of the cases:
Refactor the ArtifactProcessor/ModelResolver to take a ProcessorContext that holds context such as Monitor, Contribution for the contribution/artifact processing methods Refactor the Builder to take a BuilderContext that holds context such as Monitor, Definitions, Base binding mapping for the building methods Change the processor/resolver/builder implementation classes to not cache the Monitor git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@825773 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-java')
-rw-r--r--java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java34
-rw-r--r--java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java36
-rw-r--r--java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java7
-rw-r--r--java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java9
4 files changed, 49 insertions, 37 deletions
diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
index 173a37cd77..1653e935dc 100644
--- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
+++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
@@ -45,6 +45,7 @@ import org.apache.tuscany.sca.assembly.xml.PolicySubjectProcessor;
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.ClassReference;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
@@ -72,14 +73,13 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
private AssemblyFactory assemblyFactory;
private PolicyFactory policyFactory;
private PolicySubjectProcessor policyProcessor;
- private Monitor monitor;
+
- public JavaImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
+ public JavaImplementationProcessor(FactoryExtensionPoint modelFactories) {
this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
this.javaFactory = modelFactories.getFactory(JavaImplementationFactory.class);
this.policyProcessor = new PolicySubjectProcessor(policyFactory);
- this.monitor = monitor;
}
/**
@@ -89,7 +89,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
* @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(),
@@ -109,7 +109,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
* @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(),
@@ -122,7 +122,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
}
}
- public JavaImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ public JavaImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
// Read an <implementation.java>
JavaImplementation javaImplementation = javaFactory.createJavaImplementation();
@@ -149,7 +149,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
return javaImplementation;
}
- public void write(JavaImplementation javaImplementation, XMLStreamWriter writer) throws ContributionWriteException,
+ public void write(JavaImplementation javaImplementation, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException,
XMLStreamException {
// Write an <implementation.java>
@@ -163,15 +163,15 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
writer.writeEndElement();
}
- public void resolve(JavaImplementation javaImplementation, ModelResolver resolver)
+ public void resolve(JavaImplementation javaImplementation, ModelResolver resolver, ProcessorContext context)
throws ContributionResolveException {
-
+ Monitor monitor = context.getMonitor();
try {
ClassReference classReference = new ClassReference(javaImplementation.getName());
- classReference = resolver.resolveModel(ClassReference.class, classReference);
+ classReference = resolver.resolveModel(ClassReference.class, classReference, context);
Class<?> javaClass = classReference.getJavaClass();
if (javaClass == null) {
- error("ClassNotFoundException", resolver, javaImplementation.getName());
+ error(monitor, "ClassNotFoundException", resolver, javaImplementation.getName());
//throw new ContributionResolveException(new ClassNotFoundException(javaImplementation.getName()));
return;
}
@@ -182,13 +182,13 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
javaFactory.createJavaImplementation(javaImplementation, javaImplementation.getJavaClass());
} catch (IntrospectionException e) {
ContributionResolveException ce = new ContributionResolveException(e);
- error("ContributionResolveException", javaFactory, ce);
+ error(monitor, "ContributionResolveException", javaFactory, ce);
//throw ce;
return;
}
javaImplementation.setUnresolved(false);
- mergeComponentType(resolver, javaImplementation);
+ mergeComponentType(resolver, javaImplementation, context);
// FIXME the introspector should always create at least one service
if (javaImplementation.getServices().isEmpty()) {
@@ -227,9 +227,9 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
* @param resolver
* @param impl
*/
- private void mergeComponentType(ModelResolver resolver, JavaImplementation impl) {
+ private void mergeComponentType(ModelResolver resolver, JavaImplementation impl, ProcessorContext context) {
// FIXME: Need to clarify how to merge
- ComponentType componentType = getComponentType(resolver, impl);
+ ComponentType componentType = getComponentType(resolver, impl, context);
if (componentType != null && !componentType.isUnresolved()) {
Map<String, Reference> refMap = new HashMap<String, Reference>();
for (Reference ref : impl.getReferences()) {
@@ -284,13 +284,13 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
}
}
- private ComponentType getComponentType(ModelResolver resolver, JavaImplementation impl) {
+ private ComponentType getComponentType(ModelResolver resolver, JavaImplementation impl, ProcessorContext context) {
String className = impl.getJavaClass().getName();
String componentTypeURI = className.replace('.', '/') + ".componentType";
ComponentType componentType = assemblyFactory.createComponentType();
componentType.setUnresolved(true);
componentType.setURI(componentTypeURI);
- componentType = resolver.resolveModel(ComponentType.class, componentType);
+ componentType = resolver.resolveModel(ComponentType.class, componentType, context);
if (!componentType.isUnresolved()) {
return componentType;
}
diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java
index 260b3d09a9..635b491b06 100644
--- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java
+++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java
@@ -32,9 +32,11 @@ import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.BuilderContext;
import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
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.contribution.processor.URLArtifactProcessor;
@@ -64,13 +66,17 @@ public class ReadTestCase {
private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor;
private static CompositeBuilder compositeBuilder;
private static Monitor monitor;
+ private static ProcessorContext context;
+ private static BuilderContext builderContext;
@BeforeClass
public static void setUp() throws Exception {
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ builderContext = new BuilderContext(extensionPoints);
inputFactory = XMLInputFactory.newInstance();
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
@@ -86,10 +92,10 @@ public class ReadTestCase {
public void testReadComposite() throws Exception {
InputStream is = getClass().getResourceAsStream("Calculator.composite");
XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
assertNotNull(composite);
- compositeBuilder.build(composite, null, monitor);
+ compositeBuilder.build(composite, builderContext);
}
@@ -100,17 +106,18 @@ public class ReadTestCase {
URL url = getClass().getResource("definitions.xml");
URI uri = URI.create("definitions.xml");
- Definitions scaDefns = policyDefinitionsProcessor.read(null, uri, url);
+ Definitions scaDefns = policyDefinitionsProcessor.read(null, uri, url, context);
InputStream is = getClass().getResourceAsStream("Calculator.composite");
XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
assertNotNull(composite);
- staxProcessor.resolve(scaDefns, resolver);
- staxProcessor.resolve(composite, resolver);
+ staxProcessor.resolve(scaDefns, resolver, context);
+ staxProcessor.resolve(composite, resolver, context);
- compositeBuilder.build(composite, null, monitor);
+ builderContext.setDefinitions(scaDefns);
+ compositeBuilder.build(composite, builderContext);
//intents are computed and aggregate intents from ancestor elements
assertEquals(((PolicySubject)composite.getComponents().get(0)).getRequiredIntents().size(), 3);
@@ -168,11 +175,11 @@ public class ReadTestCase {
URL url = getClass().getResource("definitions_with_policysets.xml");
URI uri = URI.create("definitions_with_policysets.xml");
- Definitions policyDefinitions = policyDefinitionsProcessor.read(null, uri, url);
+ Definitions policyDefinitions = policyDefinitionsProcessor.read(null, uri, url, context);
InputStream is = getClass().getResourceAsStream("Calculator.composite");
XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
assertNotNull(composite);
for ( Component component : composite.getComponents() ) {
@@ -181,10 +188,11 @@ public class ReadTestCase {
}
}
- staxProcessor.resolve(policyDefinitions, resolver);
- staxProcessor.resolve(composite, resolver);
+ staxProcessor.resolve(policyDefinitions, resolver, context);
+ staxProcessor.resolve(composite, resolver, context);
- compositeBuilder.build(composite, null, monitor);
+ builderContext.setDefinitions(policyDefinitions);
+ compositeBuilder.build(composite, builderContext);
//test for determination of policysets for implementation
assertEquals(((PolicySubject)composite.getComponents().get(0)).getPolicySets().size(), 1);
diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java
index 085b21a652..6be50d138f 100644
--- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java
+++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java
@@ -23,6 +23,7 @@ import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.resolver.ClassReference;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
@@ -43,7 +44,7 @@ public class TestModelResolver implements ModelResolver {
this.classLoader = new WeakReference<ClassLoader>(classLoader);
}
- 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) {
@@ -77,11 +78,11 @@ public class TestModelResolver 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/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java
index c45f8ccaa7..fdd606c58e 100644
--- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java
+++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java
@@ -27,6 +27,7 @@ import javax.xml.stream.XMLOutputFactory;
import org.apache.tuscany.sca.assembly.Composite;
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;
@@ -44,24 +45,26 @@ public class WriteTestCase {
private static StAXArtifactProcessor<Object> staxProcessor;
private static XMLInputFactory inputFactory;
private static XMLOutputFactory outputFactory;
+ private static ProcessorContext context;
@BeforeClass
public static void setUp() throws Exception {
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
inputFactory = XMLInputFactory.newInstance();
outputFactory = XMLOutputFactory.newInstance();
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory);
}
@Test
public void testReadWriteComposite() throws Exception {
InputStream is = getClass().getResourceAsStream("Calculator.composite");
- Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is));
+ Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is), context);
Assert.assertNotNull(composite);
StringWriter sw = new StringWriter();
- staxProcessor.write(composite, outputFactory.createXMLStreamWriter(sw));
+ staxProcessor.write(composite, outputFactory.createXMLStreamWriter(sw), context);
System.out.println(sw.toString());
}