summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-25 23:40:38 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-25 23:40:38 +0000
commit1eafab3193550a62edf9a9c7c60c119796a9e7e8 (patch)
tree3b9da17022bb79565b4e24748ce8c34e87821cee /java
parent6b71f86309fc1c20aaac34c205fe783664a48477 (diff)
Match the document using wildcards against the artifact URI
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@758464 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/BuildPolicyTestCase.java38
-rw-r--r--java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ReadDocumentTestCase.java62
-rw-r--r--java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ResolvePolicyTestCase.java52
-rw-r--r--java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java93
-rw-r--r--java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java78
-rw-r--r--java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java52
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java8
-rw-r--r--java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java221
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java16
-rw-r--r--java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java28
-rw-r--r--java/sca/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor10
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java204
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java141
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java197
-rw-r--r--java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java3
-rw-r--r--java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java15
-rw-r--r--java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java89
17 files changed, 750 insertions, 557 deletions
diff --git a/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/BuildPolicyTestCase.java b/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/BuildPolicyTestCase.java
index 4262571a9a..938cc7750d 100644
--- a/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/BuildPolicyTestCase.java
+++ b/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/BuildPolicyTestCase.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.assembly.xml.osoa;
@@ -56,13 +56,13 @@ import org.junit.Test;
/**
* Test reading SCA XML assembly documents.
- *
+ *
* @version $Rev$ $Date$
*/
-public class BuildPolicyTestCase {
+public class BuildPolicyTestCase {
private static URLArtifactProcessor<Object> documentProcessor;
private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor;
- private static ModelResolver resolver;
+ private static ModelResolver resolver;
private static CompositeBuilder compositeBuilder;
private static Composite composite;
private static Monitor monitor;
@@ -77,20 +77,20 @@ public class BuildPolicyTestCase {
List<Definitions> policyDefinitions = new ArrayList<Definitions>();
resolver = new DefaultModelResolver();
-
+
MonitorFactory monitorFactory = new DefaultMonitorFactory();
monitor = monitorFactory.createMonitor();
-
+
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
-
+
URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints);
documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class);
-
+
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
-
+
URL url = BuildPolicyTestCase.class.getResource("CalculatorComponent.constrainingType");
URI uri = URI.create("CalculatorComponent.constrainingType");
ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
@@ -98,19 +98,19 @@ public class BuildPolicyTestCase {
resolver.addModel(constrainingType);
url = BuildPolicyTestCase.class.getResource("TestAllPolicyCalculator.composite");
- uri = URI.create("TestAllCalculator.constrainingType");
+ uri = URI.create("TestAllCalculator.composite");
composite = (Composite)documentProcessor.read(null, uri, url);
assertNotNull(composite);
-
+
url = BuildPolicyTestCase.class.getResource("another_test_definitions.xml");
uri = URI.create("another_test_definitions.xml");
Definitions definitions = (Definitions)policyDefinitionsProcessor.read(null, uri, url);
assertNotNull(definitions);
policyDefinitions.add(definitions);
-
+
documentProcessor.resolve(definitions, resolver);
documentProcessor.resolve(composite, resolver);
-
+
compositeBuilder.build(composite, null, monitor);
}
@@ -118,18 +118,18 @@ public class BuildPolicyTestCase {
@Ignore("The inheritance will be calculated differently in OASIS SCA")
public void testPolicyIntentInheritance() throws Exception {
String namespaceUri = "http://test";
-
+
PolicySubject policiedComposite = (PolicySubject)composite;
assertEquals(policiedComposite.getRequiredIntents().size(), 1);
assertEquals(policiedComposite.getRequiredIntents().get(0).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
-
+
//1 defined for composite, 2 defined for the service, 1 defined and 3 inherited for the promoted service (4)
assertEquals(composite.getServices().get(0).getRequiredIntents().size(), 7);
- //1 from the operation defined in this service and 2 from the operation defined in the promoted service
+ //1 from the operation defined in this service and 2 from the operation defined in the promoted service
assertEquals(composite.getServices().get(0).getRequiredIntents().get(3).getName(), new QName(namespaceUri, "tuscanyIntent_3"));
//bindings will have only 2 intents since duplications will be cut out
assertEquals(((PolicySubject)composite.getServices().get(0).getBindings().get(0)).getRequiredIntents().size(), 3);
-
+
assertEquals(composite.getReferences().get(0).getRequiredIntents().size(), 5);
assertEquals(composite.getReferences().get(0).getRequiredIntents().get(1).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
assertEquals(((PolicySubject)composite.getReferences().get(0).getBindings().get(0)).getRequiredIntents().size(), 3);
diff --git a/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ReadDocumentTestCase.java b/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ReadDocumentTestCase.java
index e3f35d6f9b..94036c50cb 100644
--- a/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ReadDocumentTestCase.java
+++ b/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ReadDocumentTestCase.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.assembly.xml.osoa;
@@ -55,7 +55,7 @@ import org.xml.sax.XMLReader;
/**
* Test reading SCA XML assembly documents.
- *
+ *
* @version $Rev$ $Date$
*/
public class ReadDocumentTestCase {
@@ -64,24 +64,24 @@ public class ReadDocumentTestCase {
private static URLArtifactProcessor<Object> documentProcessor;
private static ModelResolver resolver;
private static XMLInputFactory inputFactory;
- private static StAXArtifactProcessor<Object> staxProcessor;
+ private static StAXArtifactProcessor<Object> staxProcessor;
@BeforeClass
public static void setUp() throws Exception {
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
- documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
-
+ documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
+
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
inputFactory = XMLInputFactory.newInstance();
staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
-
+
resolver = new DefaultModelResolver();
}
@Test
public void testValidateAssembly() throws Exception {
-
+
SchemaFactory schemaFactory;
try {
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@@ -94,19 +94,19 @@ public class ReadDocumentTestCase {
}
Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource(TUSCANY_10_XSD));
ValidatorHandler handler = schema.newValidatorHandler();
-
+
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
URL url = getClass().getResource("Calculator.composite");
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
reader.setFeature("http://xml.org/sax/features/namespaces", true);
reader.setContentHandler(handler);
reader.parse(new InputSource(url.openStream()));
-
+
}
@Test
public void testValidateImplementation() throws Exception {
-
+
SchemaFactory schemaFactory;
try {
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@@ -119,7 +119,7 @@ public class ReadDocumentTestCase {
}
Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource(TUSCANY_10_XSD));
ValidatorHandler handler = schema.newValidatorHandler();
-
+
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
URL url = getClass().getResource("JavaScriptReference.composite");
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
@@ -127,27 +127,27 @@ public class ReadDocumentTestCase {
reader.setContentHandler(handler);
reader.parse(new InputSource(url.openStream()));
}
-
+
@Test
- public void testReadImplementation() throws Exception {
-
+ public void testReadImplementation() throws Exception {
+
ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_10_XSD).toString());
XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null);
DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry());
factories.addFactory(validatingInputFactory);
-
+
CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(factories , staxProcessor, null);
-
+
URL url = getClass().getResource("JavaScriptReference.composite");
URI uri = URI.create("JavaScriptReference.composite");
Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url);
assertNotNull(composite);
}
-
+
@Test
public void testValidateBinding() throws Exception {
-
+
SchemaFactory schemaFactory;
try {
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@@ -160,7 +160,7 @@ public class ReadDocumentTestCase {
}
Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource(TUSCANY_10_XSD));
ValidatorHandler handler = schema.newValidatorHandler();
-
+
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
URL url = getClass().getResource("RMIBindingTest.composite");
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
@@ -168,26 +168,26 @@ public class ReadDocumentTestCase {
reader.setContentHandler(handler);
reader.parse(new InputSource(url.openStream()));
}
-
+
@Test
public void testReadBinding() throws Exception {
-
+
ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_10_XSD).toString());
XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null);
DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry());
factories.addFactory(validatingInputFactory);
CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(factories , staxProcessor, null);
-
+
URL url = getClass().getResource("RMIBindingTest.composite");
URI uri = URI.create("RMIBindingTest.composite");
Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url);
assertNotNull(composite);
}
-
+
@Test
public void testResolveConstrainingType() throws Exception {
-
+
URL url = getClass().getResource("CalculatorComponent.constrainingType");
URI uri = URI.create("CalculatorComponent.constrainingType");
ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
@@ -195,12 +195,12 @@ public class ReadDocumentTestCase {
resolver.addModel(constrainingType);
url = getClass().getResource("TestAllCalculator.composite");
- uri = URI.create("TestAllCalculator.constrainingType");
+ uri = URI.create("TestAllCalculator.composite");
Composite composite = (Composite)documentProcessor.read(null, uri, url);
assertNotNull(composite);
-
+
documentProcessor.resolve(composite, resolver);
-
+
assertEquals(composite.getConstrainingType(), constrainingType);
assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
}
@@ -216,9 +216,9 @@ public class ReadDocumentTestCase {
url = getClass().getResource("TestAllCalculator.composite");
uri = URI.create("TestAllCalculator.composite");
Composite composite = (Composite)documentProcessor.read(null, uri, url);
-
+
documentProcessor.resolve(composite, resolver);
-
+
assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
}
diff --git a/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ResolvePolicyTestCase.java b/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ResolvePolicyTestCase.java
index 2d2a703bcc..c242ce33fd 100644
--- a/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ResolvePolicyTestCase.java
+++ b/java/sca/modules/assembly-xml-osoa/src/test/java/org/apache/tuscany/sca/assembly/xml/osoa/ResolvePolicyTestCase.java
@@ -6,18 +6,18 @@
* 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.
+ * under the License.
*/
-package org.apache.tuscany.sca.assembly.xml.osoa;
+package org.apache.tuscany.sca.assembly.xml.osoa;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -44,24 +44,24 @@ import org.junit.Test;
/**
* Test reading SCA XML assembly documents.
- *
+ *
* @version $Rev$ $Date$
*/
public class ResolvePolicyTestCase {
private static URLArtifactProcessor<Object> documentProcessor;
- private static ModelResolver resolver;
+ private static ModelResolver resolver;
private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor;
@BeforeClass
public static void setUp() throws Exception {
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
resolver = new DefaultModelResolver();
-
+
URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class);
-
+
// Create StAX processors
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
@@ -69,7 +69,7 @@ public class ResolvePolicyTestCase {
@Test
public void testResolveConstrainingType() throws Exception {
-
+
URL url = getClass().getResource("CalculatorComponent.constrainingType");
URI uri = URI.create("CalculatorComponent.constrainingType");
ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
@@ -77,60 +77,60 @@ public class ResolvePolicyTestCase {
resolver.addModel(constrainingType);
url = getClass().getResource("TestAllCalculator.composite");
- uri = URI.create("TestAllCalculator.constrainingType");
+ uri = URI.create("TestAllCalculator.composite");
Composite composite = (Composite)documentProcessor.read(null, uri, url);
assertNotNull(composite);
-
+
url = getClass().getResource("test_definitions.xml");
uri = URI.create("test_definitions.xml");
Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url);
assertNotNull(scaDefns);
-
+
preResolvePolicyTests(composite);
documentProcessor.resolve(scaDefns, resolver);
documentProcessor.resolve(composite, resolver);
-
+
// Comment out the post resolving test
// postResolvePolicyTests(composite);
-
+
assertEquals(composite.getConstrainingType(), constrainingType);
assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
}
-
+
private void preResolvePolicyTests(Composite composite) {
assertNull(((PolicySubject)composite).getRequiredIntents().get(0).getDescription());
assertTrue(((PolicySubject)composite).getPolicySets().get(0).getProvidedIntents().isEmpty());
-
+
assertNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription());
assertTrue(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
-
+
assertNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNull(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
-
+
assertNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription());
assertTrue(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
}
-
+
private void postResolvePolicyTests(Composite composite) {
assertNotNull(((PolicySubject)composite).getRequiredIntents().get(0).getDescription());
assertFalse(((PolicySubject)composite).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(((PolicySubject)composite).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
-
+
assertNotNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription());
assertFalse(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
assertNotNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription());
assertFalse(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
-
+
assertNotNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription());
assertFalse(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
@@ -140,15 +140,15 @@ public class ResolvePolicyTestCase {
assertNotNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription());
assertFalse(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
-
+
assertNotNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription());
assertFalse(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
assertNotNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription());
assertFalse(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
-
-
+
+
}
@Test
@@ -162,9 +162,9 @@ public class ResolvePolicyTestCase {
url = getClass().getResource("TestAllCalculator.composite");
uri = URI.create("TestAllCalculator.composite");
Composite composite = (Composite)documentProcessor.read(null, uri, url);
-
+
documentProcessor.resolve(composite, resolver);
-
+
assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
}
diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java
index f624f77b81..7db6d964c4 100644
--- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java
+++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.assembly.xml;
@@ -29,8 +29,11 @@ import java.util.List;
import javax.xml.namespace.QName;
+import org.apache.tuscany.sca.assembly.Component;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Endpoint2;
+import org.apache.tuscany.sca.assembly.EndpointReference2;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint;
@@ -46,53 +49,53 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.definitions.Definitions;
import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
-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.policy.PolicySubject;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
/**
* Test reading SCA XML assembly documents.
- *
+ *
* @version $Rev: 561254 $ $Date: 2007-07-31 13:16:27 +0530 (Tue, 31 Jul 2007) $
*/
-public class BuildPolicyTestCase {
+public class BuildPolicyTestCase {
private static URLArtifactProcessor<Object> documentProcessor;
private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor;
- private static ModelResolver resolver;
+ private static ModelResolver resolver;
private static CompositeBuilder compositeBuilder;
private static Composite composite;
private static Monitor monitor;
-
@BeforeClass
public static void setUp() throws Exception {
- /*
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl();
modelFactories.addFactory(scaBindingFactory);
- compositeBuilder = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
+ compositeBuilder =
+ extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class)
+ .getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
List<Definitions> policyDefinitions = new ArrayList<Definitions>();
resolver = new DefaultModelResolver();
-
- MonitorFactory monitorFactory = new DefaultMonitorFactory();
- monitor = monitorFactory.createMonitor();
-
+
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ monitor = monitorFactory.createMonitor();
+
InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
-
- URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints);
+
+ URLArtifactProcessorExtensionPoint documentProcessors =
+ new DefaultURLArtifactProcessorExtensionPoint(extensionPoints);
documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class);
-
- StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
-
+
URL url = BuildPolicyTestCase.class.getResource("CalculatorComponent.constrainingType");
URI uri = URI.create("CalculatorComponent.constrainingType");
ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
@@ -100,52 +103,38 @@ public class BuildPolicyTestCase {
resolver.addModel(constrainingType);
url = BuildPolicyTestCase.class.getResource("TestAllPolicyCalculator.composite");
- uri = URI.create("TestAllCalculator.constrainingType");
+ uri = URI.create("TestAllCalculator.composite");
composite = (Composite)documentProcessor.read(null, uri, url);
assertNotNull(composite);
-
+
url = BuildPolicyTestCase.class.getResource("another_test_definitions.xml");
uri = URI.create("another_test_definitions.xml");
Definitions definitions = (Definitions)policyDefinitionsProcessor.read(null, uri, url);
assertNotNull(definitions);
policyDefinitions.add(definitions);
-
+
documentProcessor.resolve(definitions, resolver);
documentProcessor.resolve(composite, resolver);
-
- compositeBuilder.build(composite, null, monitor);
- */
+
+ compositeBuilder.build(composite, definitions, monitor);
}
- //@Test
- @Ignore("The inheritance will be calculated differently in OASIS SCA")
+ @Test
+ // @Ignore("The inheritance will be calculated differently in OASIS SCA")
public void testPolicyIntentInheritance() throws Exception {
String namespaceUri = "http://test";
-
- PolicySubject policiedComposite = (PolicySubject)composite;
+
+ PolicySubject policiedComposite = composite;
assertEquals(policiedComposite.getRequiredIntents().size(), 1);
- assertEquals(policiedComposite.getRequiredIntents().get(0).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
-
- //1 defined for composite, 2 defined for the service, 1 defined and 3 inherited for the promoted service (4)
- assertEquals(composite.getServices().get(0).getRequiredIntents().size(), 7);
- //1 from the operation defined in this service and 2 from the operation defined in the promoted service
- assertEquals(composite.getServices().get(0).getRequiredIntents().get(3).getName(), new QName(namespaceUri, "tuscanyIntent_3"));
- //bindings will have only 2 intents since duplications will be cut out
- assertEquals(((PolicySubject)composite.getServices().get(0).getBindings().get(0)).getRequiredIntents().size(), 3);
-
- assertEquals(composite.getReferences().get(0).getRequiredIntents().size(), 5);
- assertEquals(composite.getReferences().get(0).getRequiredIntents().get(1).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
- assertEquals(((PolicySubject)composite.getReferences().get(0).getBindings().get(0)).getRequiredIntents().size(), 3);
-
- assertEquals(composite.getComponents().get(0).getRequiredIntents().size(), 3);
- assertEquals(composite.getComponents().get(0).getRequiredIntents().get(2).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
- assertEquals(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().size(), 4);
- assertEquals(composite.getComponents().get(0).getServices().get(0).getCallback().getRequiredIntents().size(), 4);
- assertEquals(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().size(), 5);
- }
+ assertEquals(policiedComposite.getRequiredIntents().get(0).getName(),
+ new QName(namespaceUri, "tuscanyIntent_1"));
- @Test
- public void testDummy() throws Exception {
-
+ Component component = composite.getComponents().get(0);
+ Endpoint2 ep = component.getServices().get(0).getEndpoints().get(0);
+ EndpointReference2 epr = component.getReferences().get(0).getEndpointReferences().get(0);
+
+ System.out.println(ep.getRequiredIntents());
+ System.out.println(epr.getRequiredIntents());
}
+
}
diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java
index e1d1794f3c..e792fd2afd 100644
--- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java
+++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.assembly.xml;
@@ -54,33 +54,35 @@ import org.xml.sax.XMLReader;
/**
* Test reading SCA XML assembly documents.
- *
+ *
* @version $Rev$ $Date$
*/
public class ReadDocumentTestCase {
- private static final String TUSCANY_11_XSD = "tuscany-sca-1.1.xsd";
+ private static final String TUSCANY_11_XSD = "tuscany-sca-1.1.xsd";
private static URLArtifactProcessor<Object> documentProcessor;
private static ModelResolver resolver;
private static XMLInputFactory inputFactory;
- private static StAXArtifactProcessor<Object> staxProcessor;
+ private static StAXArtifactProcessor<Object> staxProcessor;
@BeforeClass
public static void setUp() throws Exception {
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
- URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
- documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
-
- StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ URLArtifactProcessorExtensionPoint documentProcessors =
+ extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
+
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
inputFactory = XMLInputFactory.newInstance();
staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
-
+
resolver = new DefaultModelResolver();
}
@Test
public void testValidateAssembly() throws Exception {
-
+
SchemaFactory schemaFactory;
try {
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@@ -93,19 +95,19 @@ public class ReadDocumentTestCase {
}
Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD));
ValidatorHandler handler = schema.newValidatorHandler();
-
+
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
URL url = getClass().getResource("Calculator.composite");
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
reader.setFeature("http://xml.org/sax/features/namespaces", true);
reader.setContentHandler(handler);
reader.parse(new InputSource(url.openStream()));
-
+
}
@Test
public void testValidateImplementation() throws Exception {
-
+
SchemaFactory schemaFactory;
try {
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@@ -118,7 +120,7 @@ public class ReadDocumentTestCase {
}
Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD));
ValidatorHandler handler = schema.newValidatorHandler();
-
+
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
URL url = getClass().getResource("Calculator.composite");
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
@@ -126,27 +128,28 @@ public class ReadDocumentTestCase {
reader.setContentHandler(handler);
reader.parse(new InputSource(url.openStream()));
}
-
+
@Test
- public void testReadImplementation() throws Exception {
-
+ public void testReadImplementation() throws Exception {
+
ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD).toString());
XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null);
DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry());
factories.addFactory(validatingInputFactory);
-
- CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(factories , staxProcessor, null);
-
+
+ CompositeDocumentProcessor compositeDocumentProcessor =
+ new CompositeDocumentProcessor(factories, staxProcessor, null);
+
URL url = getClass().getResource("Calculator.composite");
URI uri = URI.create("Calculator.composite");
Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url);
assertNotNull(composite);
}
-
+
@Test
public void testValidateBinding() throws Exception {
-
+
SchemaFactory schemaFactory;
try {
schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@@ -159,7 +162,7 @@ public class ReadDocumentTestCase {
}
Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD));
ValidatorHandler handler = schema.newValidatorHandler();
-
+
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
URL url = getClass().getResource("RMIBindingTest.composite");
XMLReader reader = parserFactory.newSAXParser().getXMLReader();
@@ -167,26 +170,27 @@ public class ReadDocumentTestCase {
reader.setContentHandler(handler);
reader.parse(new InputSource(url.openStream()));
}
-
+
@Test
public void testReadBinding() throws Exception {
-
+
ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD).toString());
XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null);
DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry());
factories.addFactory(validatingInputFactory);
- CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(factories , staxProcessor, null);
-
+ CompositeDocumentProcessor compositeDocumentProcessor =
+ new CompositeDocumentProcessor(factories, staxProcessor, null);
+
URL url = getClass().getResource("RMIBindingTest.composite");
URI uri = URI.create("RMIBindingTest.composite");
Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url);
assertNotNull(composite);
}
-
+
@Test
public void testResolveConstrainingType() throws Exception {
-
+
URL url = getClass().getResource("CalculatorComponent.constrainingType");
URI uri = URI.create("CalculatorComponent.constrainingType");
ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
@@ -194,13 +198,13 @@ public class ReadDocumentTestCase {
resolver.addModel(constrainingType);
url = getClass().getResource("TestAllCalculator.composite");
- uri = URI.create("TestAllCalculator.constrainingType");
+ uri = URI.create("TestAllCalculator.composite");
Composite composite = (Composite)documentProcessor.read(null, uri, url);
assertNotNull(composite);
-
+
documentProcessor.resolve(composite, resolver);
-
- assertEquals(composite.getConstrainingType(), constrainingType);
+
+ assertEquals(composite.getConstrainingType(), constrainingType);
assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
}
@@ -215,9 +219,9 @@ public class ReadDocumentTestCase {
url = getClass().getResource("TestAllCalculator.composite");
uri = URI.create("TestAllCalculator.composite");
Composite composite = (Composite)documentProcessor.read(null, uri, url);
-
+
documentProcessor.resolve(composite, resolver);
-
+
assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
}
diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java
index c4519ef338..d9be1dff90 100644
--- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java
+++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java
@@ -6,18 +6,18 @@
* 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.
+ * under the License.
*/
-package org.apache.tuscany.sca.assembly.xml;
+package org.apache.tuscany.sca.assembly.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -44,24 +44,24 @@ import org.junit.Test;
/**
* Test reading SCA XML assembly documents.
- *
+ *
* @version $Rev: 561254 $ $Date: 2007-07-31 13:16:27 +0530 (Tue, 31 Jul 2007) $
*/
public class ResolvePolicyTestCase {
private static URLArtifactProcessor<Object> documentProcessor;
- private static ModelResolver resolver;
+ private static ModelResolver resolver;
private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor;
@BeforeClass
public static void setUp() throws Exception {
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
resolver = new DefaultModelResolver();
-
+
URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class);
-
+
// Create StAX processors
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
@@ -69,7 +69,7 @@ public class ResolvePolicyTestCase {
@Test
public void testResolveConstrainingType() throws Exception {
-
+
URL url = getClass().getResource("CalculatorComponent.constrainingType");
URI uri = URI.create("CalculatorComponent.constrainingType");
ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
@@ -77,60 +77,60 @@ public class ResolvePolicyTestCase {
resolver.addModel(constrainingType);
url = getClass().getResource("TestAllCalculator.composite");
- uri = URI.create("TestAllCalculator.constrainingType");
+ uri = URI.create("TestAllCalculator.composite");
Composite composite = (Composite)documentProcessor.read(null, uri, url);
assertNotNull(composite);
-
+
url = getClass().getResource("test_definitions.xml");
uri = URI.create("test_definitions.xml");
Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url);
assertNotNull(scaDefns);
-
+
preResolvePolicyTests(composite);
documentProcessor.resolve(scaDefns, resolver);
documentProcessor.resolve(composite, resolver);
-
+
// Comment out the post resolving test
// postResolvePolicyTests(composite);
-
+
assertEquals(composite.getConstrainingType(), constrainingType);
assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
}
-
+
private void preResolvePolicyTests(Composite composite) {
assertNull(((PolicySubject)composite).getRequiredIntents().get(0).getDescription());
assertTrue(((PolicySubject)composite).getPolicySets().get(0).getProvidedIntents().isEmpty());
-
+
assertNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription());
assertTrue(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
-
+
assertNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNull(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
-
+
assertNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription());
assertTrue(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription());
assertTrue(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
}
-
+
private void postResolvePolicyTests(Composite composite) {
assertNotNull(((PolicySubject)composite).getRequiredIntents().get(0).getDescription());
assertFalse(((PolicySubject)composite).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(((PolicySubject)composite).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
-
+
assertNotNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription());
assertFalse(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
assertNotNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription());
assertFalse(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
-
+
assertNotNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription());
assertFalse(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
@@ -140,15 +140,15 @@ public class ResolvePolicyTestCase {
assertNotNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription());
assertFalse(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
-
+
assertNotNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription());
assertFalse(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
assertNotNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription());
assertFalse(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
assertNotNull(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
-
-
+
+
}
@Test
@@ -162,9 +162,9 @@ public class ResolvePolicyTestCase {
url = getClass().getResource("TestAllCalculator.composite");
uri = URI.create("TestAllCalculator.composite");
Composite composite = (Composite)documentProcessor.read(null, uri, url);
-
+
documentProcessor.resolve(composite, resolver);
-
+
assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
}
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
index bd904ede10..9624955ce8 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
@@ -152,9 +152,6 @@ public class CompositeBuilderImpl implements CompositeBuilder {
// Connect composite services/references to promoted services/references
compositePromotionBuilder.build(composite, definitions, monitor);
- // Compute the policies across the model hierarchy
- compositePolicyBuilder.build(composite, definitions, monitor);
-
// Configure composite services by copying bindings up the promotion
// hierarchy overwriting automatic bindings with those added manually
compositeServiceConfigurationBuilder.build(composite, definitions, monitor);
@@ -206,7 +203,10 @@ public class CompositeBuilderImpl implements CompositeBuilder {
// Perform and reference binding related build activities. The binding
// will provide the builder.
- componentReferenceBindingBuilder.build(composite, definitions, monitor);
+ componentReferenceBindingBuilder.build(composite, definitions, monitor);
+
+ // Compute the policies across the model hierarchy
+ compositePolicyBuilder.build(composite, definitions, monitor);
}
}
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java
index 1fc00705e7..5b3c570db7 100644
--- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java
+++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java
@@ -6,20 +6,21 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.assembly.builder.impl;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
@@ -41,6 +42,7 @@ import org.apache.tuscany.sca.definitions.Definitions;
import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
import org.apache.tuscany.sca.policy.PolicySubject;
/**
@@ -52,8 +54,7 @@ import org.apache.tuscany.sca.policy.PolicySubject;
*/
public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements CompositeBuilder {
- public CompositePolicyBuilderImpl(AssemblyFactory assemblyFactory,
- InterfaceContractMapper interfaceContractMapper) {
+ public CompositePolicyBuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper) {
super(assemblyFactory, null, null, null, interfaceContractMapper);
}
@@ -62,7 +63,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
}
public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException {
- computePolicies(composite, monitor);
+ computePolicies(composite, definitions, monitor);
}
/**
@@ -82,7 +83,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
}
/**
- * Check if two policy subjects requires multually exclusive intents
+ * Check if two policy subjects requires multually exclusive intents
* @param subject1
* @param subject2
* @return
@@ -101,27 +102,67 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
return false;
}
- private void inheritFromService(PolicySubject subject, Service service) {
+ /**
+ * Inherit the policySets and intents from the implementation hierarchy
+ * @param subject
+ * @param composite
+ * @param component
+ * @param service
+ */
+ private void inheritFromService(PolicySubject subject, Composite composite, Component component, Service service) {
+ if (service == null) {
+ return;
+ }
if (service instanceof ComponentService) {
- inheritFromService(subject, ((ComponentService)service).getService());
+ // component!=null
+ if (component.getImplementation() instanceof Composite) {
+ composite = (Composite)component.getImplementation();
+ }
+ inheritFromService(subject, composite, component, ((ComponentService)service).getService());
+ // Component service also inherits the intents/policySets from composite/component
+ inherit(subject, composite, component);
} else if (service instanceof CompositeService) {
+ // composite!=null, component is not used
CompositeService compositeService = (CompositeService)service;
- inherit(subject, compositeService.getPromotedComponent());
- inheritFromService(subject, compositeService.getPromotedService());
+ // Handle the promoted component service
+ inheritFromService(subject, composite, compositeService.getPromotedComponent(), compositeService
+ .getPromotedService());
}
- inherit(subject, service);
+ // For atomic service, the composite is not used
+ inherit(subject, component.getImplementation(), service);
}
- private void inheritFromReference(PolicySubject subject, Reference reference) {
+ /**
+ * Inherit the policySets and intents from the implementation hierarchy
+ * @param subject
+ * @param composite
+ * @param component
+ * @param reference
+ */
+ private void inheritFromReference(PolicySubject subject,
+ Composite composite,
+ Component component,
+ Reference reference) {
+ if (reference == null) {
+ return;
+ }
if (reference instanceof ComponentReference) {
- inheritFromReference(subject, ((ComponentReference)reference).getReference());
+ // component!=null
+ if (component.getImplementation() instanceof Composite) {
+ composite = (Composite)component.getImplementation();
+ }
+ inheritFromReference(subject, composite, component, ((ComponentReference)reference).getReference());
} else if (reference instanceof CompositeReference) {
CompositeReference compositeReference = (CompositeReference)reference;
- for (ComponentReference componentReference : compositeReference.getPromotedReferences()) {
- inheritFromReference(subject, componentReference);
+ for (int i = 0, n = compositeReference.getPromotedReferences().size(); i < n; i++) {
+ inheritFromReference(subject,
+ composite,
+ compositeReference.getPromotedComponents().get(i),
+ compositeReference.getPromotedReferences().get(i));
}
}
- inherit(subject, reference);
+ // Inherit from the componentType/reference
+ inherit(subject, component.getImplementation(), reference);
}
/**
@@ -141,8 +182,20 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
}
}
- private void validate(PolicySubject subject) {
- Set<Intent> intents = new HashSet<Intent>(subject.getRequiredIntents());
+ private void resolveAndNormalize(PolicySubject subject, Definitions definitions, Monitor monitor) {
+
+ Set<Intent> intents = new HashSet<Intent>();
+ if (definitions != null) {
+ for (Intent i : subject.getRequiredIntents()) {
+ int index = definitions.getIntents().indexOf(i);
+ if (index != -1) {
+ intents.add(definitions.getIntents().get(index));
+ } else {
+ warning(monitor, "intent-not-found", subject, i.getName().toString());
+ // Intent cannot be resolved
+ }
+ }
+ }
// Replace profile intents with their required intents
boolean profileIntentsFound = false;
@@ -179,15 +232,35 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
}
}
+ subject.getRequiredIntents().clear();
+ subject.getRequiredIntents().addAll(intents);
+
+ Set<PolicySet> policySets = new HashSet<PolicySet>();
+ if (definitions != null) {
+ for (PolicySet policySet : subject.getPolicySets()) {
+ int index = definitions.getPolicySets().indexOf(policySet);
+ if (index != -1) {
+ policySets.add(definitions.getPolicySets().get(index));
+ } else {
+ // PolicySet cannot be resolved
+ }
+ }
+ }
+
+ for (PolicySet policySet : policySets) {
+ List<Intent> provided = policySet.getProvidedIntents();
+ // FIXME: Check if required intents are provided by the policy sets
+ }
+
}
- protected void computePolicies(Composite composite, Monitor monitor) {
+ protected void computePolicies(Composite composite, Definitions definitions, Monitor monitor) {
// compute policies recursively
for (Component component : composite.getComponents()) {
Implementation implementation = component.getImplementation();
if (implementation instanceof Composite) {
- computePolicies((Composite)implementation, monitor);
+ computePolicies((Composite)implementation, definitions, monitor);
}
}
@@ -206,27 +279,36 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
for (Endpoint2 ep : componentService.getEndpoints()) {
// Inherit from the componentType.service.interface
- inherit(ep, componentService.getService().getInterfaceContract().getInterface());
- // Inherit from the component.service.interface
- inherit(ep, componentService.getInterfaceContract().getInterface());
- // Inherit from the componentType/service
- inherit(ep, component.getImplementation(), componentService.getService());
+ if (componentService.getService() != null && componentService.getService().getInterfaceContract() != null) {
+ inherit(ep, componentService.getService().getInterfaceContract().getInterface());
+ }
+ if (componentService.getInterfaceContract() != null) {
+ // Inherit from the component.service.interface
+ inherit(ep, componentService.getInterfaceContract().getInterface());
+ }
+ // Inherit from the componentType/service
+ inheritFromService(ep, composite, component, componentService.getService());
// Find the corresponding binding in the componentType and inherit the intents/policySets
- for (Binding binding : componentService.getService().getBindings()) {
- if (isEqual(ep.getBinding().getName(), binding.getName()) && (binding instanceof PolicySubject)) {
- isMutualExclusive((PolicySubject)ep.getBinding(), (PolicySubject)binding);
- // Inherit from componentType.service.binding
- inherit(ep, binding);
- break;
+ if (componentService.getService() != null) {
+ for (Binding binding : componentService.getService().getBindings()) {
+ if (isEqual(ep.getBinding().getName(), binding.getName()) && (binding instanceof PolicySubject)) {
+ isMutualExclusive((PolicySubject)ep.getBinding(), (PolicySubject)binding);
+ // Inherit from componentType.service.binding
+ inherit(ep, binding);
+ break;
+ }
}
}
- // Inherit from composite/component/service/binding
- inherit(ep, composite, ep.getComponent(), ep.getService(), ep.getBinding());
+ // Inherit from composite/component/service
+ inheritFromService(ep, composite, ep.getComponent(), ep.getService());
+ // Inherit from binding
+ inherit(ep, ep.getBinding());
// Replace profile intents with their required intents
// Remove the intents whose @contraints do not include the current element
// Replace unqualified intents if there is a qualified intent in the list
// Replace qualifiable intents with the default qualied intent
+ resolveAndNormalize(ep, definitions, monitor);
}
}
@@ -242,68 +324,41 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo
for (EndpointReference2 epr : componentReference.getEndpointReferences()) {
// Inherit from the componentType.reference.interface
- inherit(epr, componentReference.getReference().getInterfaceContract().getInterface());
+ if (componentReference.getReference() != null && componentReference.getReference()
+ .getInterfaceContract() != null) {
+ inherit(epr, componentReference.getReference().getInterfaceContract().getInterface());
+ }
// Inherit from the component.reference.interface
- inherit(epr, componentReference.getInterfaceContract().getInterface());
- // Inherit from the componentType/reference
- inherit(epr, component.getImplementation(), componentReference.getReference());
+ if (componentReference.getInterfaceContract() != null) {
+ inherit(epr, componentReference.getInterfaceContract().getInterface());
+ }
+ // Inherit from the componentType/reference
+ inheritFromReference(epr, composite, component, componentReference.getReference());
// Find the corresponding binding in the componentType and inherit the intents/policySets
- for (Binding binding : componentReference.getReference().getBindings()) {
- if (isEqual(epr.getBinding().getName(), binding.getName()) && (binding instanceof PolicySubject)) {
- isMutualExclusive((PolicySubject)epr.getBinding(), (PolicySubject)binding);
- // Inherit from componentType.reference.binding
- inherit(epr, binding);
- break;
+ if (componentReference.getReference() != null) {
+ for (Binding binding : componentReference.getReference().getBindings()) {
+ if (isEqual(epr.getBinding().getName(), binding.getName()) && (binding instanceof PolicySubject)) {
+ isMutualExclusive((PolicySubject)epr.getBinding(), (PolicySubject)binding);
+ // Inherit from componentType.reference.binding
+ inherit(epr, binding);
+ break;
+ }
}
}
// Inherit from composite/component/reference/binding
- inherit(epr, composite, epr.getComponent(), epr.getReference(), epr.getBinding());
+ inheritFromReference(epr, composite, epr.getComponent(), epr.getReference());
+ inherit(epr, epr.getBinding());
// Replace profile intents with their required intents
// Remove the intents whose @contraints do not include the current element
// Replace unqualified intents if there is a qualified intent in the list
// Replace qualifiable intents with the default qualied intent
+ resolveAndNormalize(epr, definitions, monitor);
}
}
- Implementation implemenation = component.getImplementation();
- try {
- PolicyConfigurationUtil.computeImplementationIntentsAndPolicySets(implemenation, component);
- } catch (Exception e) {
- error(monitor, "PolicyRelatedException", implemenation, e);
- //throw new RuntimeException(e);
- }
- }
-
- //compute policies for composite service bindings
- for (Service service : composite.getServices()) {
- CompositeService compositeService = (CompositeService)service;
-
- // Composite service inherits the policySets and intents from the promoted component service
- Component promotedComponent = compositeService.getPromotedComponent();
- // Promoted component service inherits from the component type service
- // as well as the structural hierarchy, i.e., composite/promotedComponent
- ComponentService promotedService = compositeService.getPromotedService();
- // We need to calculate the inherited intents/policySets for the promoted
- // service first
- isMutualExclusive(compositeService, promotedService);
- }
-
- //compute policies for composite reference bindings
- for (Reference reference : composite.getReferences()) {
- CompositeReference compositeReference = (CompositeReference)reference;
-
- // Composite reference inherits the policySets and intents from the promoted component references
- for (ComponentReference promotedReference : compositeReference.getPromotedReferences()) {
-
- // Promoted component reference inherits from the component type reference
- // as well as the structural hierarchy, i.e., composite/promotedComponent
- // We need to calculate the inherited intents/policySets for the promoted
- // reference first
- isMutualExclusive(compositeReference, promotedReference);
-
- }
+ Implementation implementation = component.getImplementation();
+ // How to deal with implementation level policySets/intents
}
-
}
}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java
index ff7bf7068a..0035f360ab 100644
--- a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.contribution.xml;
@@ -26,18 +26,18 @@ import org.apache.tuscany.sca.monitor.Monitor;
/**
* URLArtifactProcessor that handles sca-contribution-generated.xml files.
- *
+ *
* @version $Rev$ $Date$
*/
public class ContributionGeneratedMetadataDocumentProcessor extends ContributionMetadataDocumentProcessor {
- public ContributionGeneratedMetadataDocumentProcessor(XMLInputFactory inputFactory,
+ public ContributionGeneratedMetadataDocumentProcessor(XMLInputFactory inputFactory,
StAXArtifactProcessor staxProcessor,
Monitor monitor) {
super(inputFactory, staxProcessor, monitor);
}
-
- public ContributionGeneratedMetadataDocumentProcessor(FactoryExtensionPoint modelFactories,
+
+ public ContributionGeneratedMetadataDocumentProcessor(FactoryExtensionPoint modelFactories,
StAXArtifactProcessor staxProcessor,
Monitor monitor) {
super(modelFactories, staxProcessor, monitor);
@@ -45,6 +45,6 @@ public class ContributionGeneratedMetadataDocumentProcessor extends Contribution
@Override
public String getArtifactType() {
- return "sca-contribution-generated.xml";
+ return "/META-INF/sca-contribution-generated.xml";
}
}
diff --git a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
index f080f23797..d5fa606997 100644
--- a/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
+++ b/java/sca/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.contribution.xml;
@@ -42,7 +42,7 @@ import org.apache.tuscany.sca.monitor.Problem.Severity;
/**
* URLArtifactProcessor that handles sca-contribution.xml files.
- *
+ *
* @version $Rev$ $Date$
*/
public class ContributionMetadataDocumentProcessor implements URLArtifactProcessor<ContributionMetadata>{
@@ -65,10 +65,10 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess
this.staxProcessor = staxProcessor;
this.monitor = monitor;
}
-
+
/**
* Report a exception.
- *
+ *
* @param problems
* @param message
* @param model
@@ -79,31 +79,31 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess
monitor.problem(problem);
}
}
-
+
public String getArtifactType() {
- return "sca-contribution.xml";
+ return "/META-INF/sca-contribution.xml";
}
-
+
public Class<ContributionMetadata> getModelType() {
return ContributionMetadata.class;
}
-
+
public ContributionMetadata read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
InputStream urlStream = null;
try {
-
+
// Create a stream reader
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
urlStream = connection.getInputStream();
XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
reader.nextTag();
-
+
// Read the contribution model
ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader);
return contribution;
-
+
} catch (XMLStreamException e) {
ContributionReadException ex = new ContributionReadException(e);
error("XMLStreamException", inputFactory, ex);
@@ -123,7 +123,7 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess
}
}
}
-
+
public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException {
staxProcessor.resolve(contribution, resolver);
}
diff --git a/java/sca/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/java/sca/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
index 23adab56b9..cdaca4d786 100644
--- a/java/sca/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
+++ b/java/sca/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
@@ -5,16 +5,16 @@
# 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.
+# under the License.
# Implementation class for the artifact processor extension
-org.apache.tuscany.sca.contribution.xml.ContributionMetadataDocumentProcessor;type=sca-contribution.xml,model=org.apache.tuscany.sca.contribution.ContributionMetadata
-org.apache.tuscany.sca.contribution.xml.ContributionGeneratedMetadataDocumentProcessor;type=sca-contribution-generated.xml
+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
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 86206d4ab2..99b5b3d8b0 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
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.contribution.processor;
@@ -24,6 +24,7 @@ import java.net.URI;
import java.net.URL;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
@@ -39,16 +40,14 @@ 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.
- *
+ *
* @version $Rev$ $Date$
*/
-public class DefaultURLArtifactProcessorExtensionPoint
- extends DefaultArtifactProcessorExtensionPoint<URLArtifactProcessor>
- implements URLArtifactProcessorExtensionPoint {
-
+public class DefaultURLArtifactProcessorExtensionPoint extends
+ DefaultArtifactProcessorExtensionPoint<URLArtifactProcessor> implements URLArtifactProcessorExtensionPoint {
+
private ExtensionPointRegistry extensionPoints;
private StAXArtifactProcessor<?> staxProcessor;
private boolean loaded;
@@ -64,54 +63,132 @@ public class DefaultURLArtifactProcessorExtensionPoint
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);
+ 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);
- }
+ Problem problem =
+ monitor.createProblem(this.getClass().getName(),
+ "contribution-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ ex);
+ monitor.problem(problem);
+ }
}
-
+
public void addArtifactProcessor(URLArtifactProcessor artifactProcessor) {
if (artifactProcessor.getArtifactType() != null) {
- processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor);
+ Pattern pattern = Pattern.compile(wildcard2regex(artifactProcessor.getArtifactType()));
+ processorsByArtifactType.put(pattern, artifactProcessor);
}
if (artifactProcessor.getModelType() != null) {
processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor);
}
}
-
+
public void removeArtifactProcessor(URLArtifactProcessor artifactProcessor) {
if (artifactProcessor.getArtifactType() != null) {
+ String regex = wildcard2regex(artifactProcessor.getArtifactType());
+ for (Object key : processorsByArtifactType.keySet()) {
+ if ((key instanceof Pattern) && ((Pattern)key).pattern().equals(regex)) {
+ processorsByArtifactType.remove(key);
+ }
+ }
processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType());
}
if (artifactProcessor.getModelType() != null) {
processorsByModelType.remove(artifactProcessor.getModelType());
}
}
-
+
@Override
public URLArtifactProcessor getProcessor(Class<?> modelType) {
loadProcessors();
return super.getProcessor(modelType);
}
-
+
@Override
public URLArtifactProcessor getProcessor(Object artifactType) {
loadProcessors();
- return super.getProcessor(artifactType);
+ URLArtifactProcessor processor = null;
+ String uri = (String)artifactType;
+ if (uri.endsWith("/")) {
+ // Ignore directories
+ return null;
+ }
+ if (!uri.startsWith("/")) {
+ uri = "/" + uri;
+ }
+ for (Object key : processorsByArtifactType.keySet()) {
+ Pattern pattern = (Pattern)key;
+ if (pattern.matcher(uri).matches()) {
+ return processorsByArtifactType.get(key);
+ }
+ }
+ return processor;
+ }
+
+ private String wildcard2regex(String wildcard) {
+ if (wildcard.startsWith(".")) {
+ // File extension
+ wildcard = "**/*" + wildcard;
+ } else if (wildcard.indexOf('/') == -1) {
+ // file name
+ wildcard = "**/" + wildcard;
+ } else if (!(wildcard.startsWith("/") || wildcard.startsWith("**"))) {
+ wildcard = '/' + wildcard;
+ }
+ StringBuffer regex = new StringBuffer();
+ char[] chars = wildcard.toCharArray();
+ for (int i = 0; i < chars.length; i++) {
+ switch (chars[i]) {
+ case '*':
+ if (i < chars.length - 1 && chars[i + 1] == '*') {
+ regex.append(".*");
+ i++; // Skip next *
+ } else {
+ regex.append("[^/]*");
+ }
+ break;
+ case '?':
+ regex.append("[^/]");
+ break;
+ case '\\':
+ case '|':
+ case '(':
+ case ')':
+ // case '[':
+ // case ']':
+ // case '{':
+ // case '}':
+ case '^':
+ case '$':
+ case '+':
+ case '.':
+ case '<':
+ case '>':
+ regex.append("\\").append(chars[i]);
+ break;
+ default:
+ regex.append(chars[i]);
+ break;
+ }
+ }
+ return regex.toString();
}
/**
@@ -122,27 +199,29 @@ public class DefaultURLArtifactProcessorExtensionPoint
return;
// Get the processor service declarations
- Set<ServiceDeclaration> processorDeclarations;
+ Set<ServiceDeclaration> processorDeclarations;
try {
- processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class.getName());
+ processorDeclarations =
+ ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class.getName());
} catch (IOException e) {
- IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", staxProcessor, ie);
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", staxProcessor, ie);
throw ie;
}
-
- for (ServiceDeclaration processorDeclaration: processorDeclarations) {
+
+ for (ServiceDeclaration processorDeclaration : processorDeclarations) {
Map<String, String> attributes = processorDeclaration.getAttributes();
// Load a URL artifact processor
String artifactType = attributes.get("type");
String modelTypeName = attributes.get("model");
-
+
// Create a processor wrapper and register it
- URLArtifactProcessor processor = new LazyURLArtifactProcessor(artifactType, modelTypeName,
- processorDeclaration, extensionPoints, staxProcessor, monitor);
+ URLArtifactProcessor processor =
+ new LazyURLArtifactProcessor(artifactType, modelTypeName, processorDeclaration, extensionPoints,
+ staxProcessor, monitor);
addArtifactProcessor(processor);
}
-
+
loaded = true;
}
@@ -160,13 +239,13 @@ public class DefaultURLArtifactProcessorExtensionPoint
private Class<?> modelType;
private StAXArtifactProcessor<?> staxProcessor;
private Monitor monitor;
-
- LazyURLArtifactProcessor(String artifactType,
- String modelTypeName,
- ServiceDeclaration processorDeclaration,
- ExtensionPointRegistry extensionPoints,
- StAXArtifactProcessor<?> staxProcessor,
- Monitor monitor) {
+
+ LazyURLArtifactProcessor(String artifactType,
+ String modelTypeName,
+ ServiceDeclaration processorDeclaration,
+ ExtensionPointRegistry extensionPoints,
+ StAXArtifactProcessor<?> staxProcessor,
+ Monitor monitor) {
this.artifactType = artifactType;
this.modelTypeName = modelTypeName;
this.processorDeclaration = processorDeclaration;
@@ -178,35 +257,50 @@ public class DefaultURLArtifactProcessorExtensionPoint
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);
- }
+ 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) {
try {
- FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
- Class<URLArtifactProcessor> processorClass = (Class<URLArtifactProcessor>)processorDeclaration.loadClass();
+ FactoryExtensionPoint modelFactories =
+ extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ Class<URLArtifactProcessor> processorClass =
+ (Class<URLArtifactProcessor>)processorDeclaration.loadClass();
try {
- Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class);
+ Constructor<URLArtifactProcessor> constructor =
+ processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class);
processor = constructor.newInstance(modelFactories, monitor);
} catch (NoSuchMethodException e) {
try {
- Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class);
+ Constructor<URLArtifactProcessor> constructor =
+ processorClass.getConstructor(FactoryExtensionPoint.class,
+ StAXArtifactProcessor.class,
+ Monitor.class);
processor = constructor.newInstance(modelFactories, staxProcessor, monitor);
} catch (NoSuchMethodException e2) {
- Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class);
+ Constructor<URLArtifactProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class,
+ StAXArtifactProcessor.class,
+ Monitor.class);
processor = constructor.newInstance(extensionPoints, staxProcessor, monitor);
}
}
} catch (Exception e) {
- IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", processor, ie);
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", processor, ie);
throw ie;
}
}
@@ -216,14 +310,14 @@ public class DefaultURLArtifactProcessorExtensionPoint
public Object read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException {
return getProcessor().read(contributionURL, artifactURI, artifactURL);
}
-
+
public Class<?> getModelType() {
if (modelTypeName != null && modelType == null) {
try {
modelType = processorDeclaration.loadClass(modelTypeName);
} catch (ClassNotFoundException e) {
- IllegalStateException ie = new IllegalStateException(e);
- error("IllegalStateException", processorDeclaration, ie);
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", processorDeclaration, ie);
throw ie;
}
}
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 7578a24ea8..35793899c0 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
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.contribution.processor;
@@ -41,16 +41,16 @@ import org.apache.tuscany.sca.monitor.Problem.Severity;
/**
* Implementation of an extensible StAX artifact processor.
- *
+ *
* Takes a StAXArtifactProcessorExtensionPoint and delegates to the proper
* StAXArtifactProcessor by element QName
- *
+ *
* @version $Rev$ $Date$
*/
public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Object> {
- private static final Logger logger = Logger.getLogger(ExtensibleStAXArtifactProcessor.class.getName());
-
- private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, "anyElement");
+ private static final Logger logger = Logger.getLogger(ExtensibleStAXArtifactProcessor.class.getName());
+
+ private static final QName ANY_ELEMENT = new QName(Constants.XMLSCHEMA_NS, "anyElement");
private XMLInputFactory inputFactory;
private XMLOutputFactory outputFactory;
@@ -63,10 +63,10 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
* @param inputFactory
* @param outputFactory
*/
- public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors,
- XMLInputFactory inputFactory,
- XMLOutputFactory outputFactory,
- Monitor monitor) {
+ public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors,
+ XMLInputFactory inputFactory,
+ XMLOutputFactory outputFactory,
+ Monitor monitor) {
super();
this.processors = processors;
this.inputFactory = inputFactory;
@@ -76,52 +76,69 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
}
this.monitor = monitor;
}
-
+
/**
* Report a warning.
- *
+ *
* @param problems
* @param message
* @param model
*/
- private void warning(String message, Object model, Object... messageParameters) {
- if (monitor != null) {
- Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
- monitor.problem(problem);
- }
- }
-
- /**
- * Report a error.
- *
- * @param problems
- * @param message
- * @param model
- */
- private void error(String message, Object model, Object... messageParameters) {
- if (monitor != null) {
- Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
- monitor.problem(problem);
- }
- }
-
+ private void warning(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(this.getClass().getName(),
+ "contribution-validation-messages",
+ Severity.WARNING,
+ model,
+ message,
+ (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
/**
- * Report a exception.
- *
+ * Report a error.
+ *
* @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);
- }
- }
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(this.getClass().getName(),
+ "contribution-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+ /**
+ * 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);
+ }
+ }
public Object read(XMLStreamReader source) throws ContributionReadException, XMLStreamException {
-
+
// Delegate to the processor associated with the element QName
int event = source.getEventType();
if (event == XMLStreamConstants.START_DOCUMENT) {
@@ -130,25 +147,25 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
QName name = source.getName();
StAXArtifactProcessor<?> processor = (StAXArtifactProcessor<?>)processors.getProcessor(name);
if (processor == null) {
- Location location = source.getLocation();
- if (logger.isLoggable(Level.WARNING)) {
+ Location location = source.getLocation();
+ if (logger.isLoggable(Level.WARNING)) {
logger.warning("Element " + name + " cannot be processed. (" + location + ")");
}
warning("ElementCannotBeProcessed", processors, name, location);
StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT);
- if(anyElementProcessor != null) {
- return anyElementProcessor.read(source);
+ if (anyElementProcessor != null) {
+ return anyElementProcessor.read(source);
} else {
- return null;
+ return null;
}
}
return processor.read(source);
}
-
+
@SuppressWarnings("unchecked")
public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
-
+
// Delegate to the processor associated with the model type
if (model != null) {
StAXArtifactProcessor processor = processors.getProcessor(model.getClass());
@@ -158,15 +175,17 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
if (logger.isLoggable(Level.WARNING)) {
logger.warning("No StAX processor is configured to handle " + model.getClass());
}
- warning("NoStaxProcessor", processors, model.getClass());
+ if (!XMLStreamReader.class.isInstance(model)) {
+ warning("NoStaxProcessor", processors, model.getClass());
+ }
StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT);
- if(anyElementProcessor != null) {
- anyElementProcessor.write(model, outputSource);
+ if (anyElementProcessor != null) {
+ anyElementProcessor.write(model, outputSource);
}
}
}
}
-
+
@SuppressWarnings("unchecked")
public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
@@ -178,7 +197,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
}
}
}
-
+
/**
* Read a model from an InputStream.
* @param is The artifact InputStream
@@ -198,8 +217,8 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
if (type.isInstance(mo)) {
return type.cast(mo);
} else {
- error("UnrecognizedElementException", reader, name);
- UnrecognizedElementException e = new UnrecognizedElementException(name);
+ error("UnrecognizedElementException", reader, name);
+ UnrecognizedElementException e = new UnrecognizedElementException(name);
throw e;
}
} catch (ContributionReadException e) {
@@ -242,8 +261,8 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
writer.flush();
writer.close();
} catch (XMLStreamException e) {
- ContributionWriteException cw = new ContributionWriteException(e);
- error("ContributionWriteException", outputFactory, cw);
+ ContributionWriteException cw = new ContributionWriteException(e);
+ error("ContributionWriteException", outputFactory, cw);
throw cw;
}
}
@@ -251,7 +270,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob
public QName getArtifactType() {
return null;
}
-
+
public Class<Object> getModelType() {
return null;
}
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 c336cb3431..9a7ba07261 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
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.contribution.processor;
@@ -32,6 +32,7 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import org.apache.tuscany.sca.assembly.Extension;
import org.apache.tuscany.sca.contribution.Constants;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.monitor.Monitor;
@@ -40,19 +41,18 @@ import org.apache.tuscany.sca.monitor.Problem.Severity;
/**
* Implementation of an extensible StAX attribute processor.
- *
+ *
* Takes a StAXAttributeProcessorExtensionPoint and delegates to the proper
* StAXAttributeProcessor by attribute QName
- *
+ *
* @version $Rev$ $Date$
*/
-public class ExtensibleStAXAttributeProcessor
- implements StAXAttributeProcessor<Object> {
+public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor<Object> {
+
+ private static final Logger logger = Logger.getLogger(ExtensibleStAXAttributeProcessor.class.getName());
- private static final Logger logger = Logger.getLogger(ExtensibleStAXAttributeProcessor.class.getName());
-
private static final QName ANY_ATTRIBUTE = new QName(Constants.XMLSCHEMA_NS, "anyAttribute");
-
+
private XMLInputFactory inputFactory;
private XMLOutputFactory outputFactory;
private StAXAttributeProcessorExtensionPoint processors;
@@ -64,10 +64,10 @@ public class ExtensibleStAXAttributeProcessor
* @param inputFactory
* @param outputFactory
*/
- public ExtensibleStAXAttributeProcessor(StAXAttributeProcessorExtensionPoint processors,
- XMLInputFactory inputFactory,
- XMLOutputFactory outputFactory,
- Monitor monitor) {
+ public ExtensibleStAXAttributeProcessor(StAXAttributeProcessorExtensionPoint processors,
+ XMLInputFactory inputFactory,
+ XMLOutputFactory outputFactory,
+ Monitor monitor) {
super();
this.processors = processors;
this.inputFactory = inputFactory;
@@ -77,51 +77,69 @@ public class ExtensibleStAXAttributeProcessor
}
this.monitor = monitor;
}
-
+
/**
* Report a warning.
- *
+ *
* @param problems
* @param message
* @param model
*/
- private void warning(String message, Object model, Object... messageParameters) {
- if (monitor != null) {
- Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
- monitor.problem(problem);
- }
- }
-
- /**
- * Report a error.
- *
- * @param problems
- * @param message
- * @param model
- */
- private void error(String message, Object model, Object... messageParameters) {
- if (monitor != null) {
- Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
- monitor.problem(problem);
- }
- }
-
+ private void warning(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(this.getClass().getName(),
+ "contribution-validation-messages",
+ Severity.WARNING,
+ model,
+ message,
+ (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
/**
- * Report a exception.
- *
+ * Report a error.
+ *
* @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);
- }
- }
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(this.getClass().getName(),
+ "contribution-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+ /**
+ * 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);
+ }
+ }
- public Object read(QName attributeName, XMLStreamReader source) throws ContributionReadException, XMLStreamException {
+ public Object read(QName attributeName, XMLStreamReader source) throws ContributionReadException,
+ XMLStreamException {
// Delegate to the processor associated with the attribute QName
int event = source.getEventType();
if (event == XMLStreamConstants.START_DOCUMENT) {
@@ -129,79 +147,78 @@ public class ExtensibleStAXAttributeProcessor
}
StAXAttributeProcessor<?> processor = null;
-
+
//lookup for registered attribute processors
processor = (StAXAttributeProcessor<?>)processors.getProcessor(attributeName);
if (processor == null) {
- Location location = source.getLocation();
- if (logger.isLoggable(Level.WARNING)) {
+ Location location = source.getLocation();
+ if (logger.isLoggable(Level.WARNING)) {
logger.warning("Attribute " + attributeName + " cannot be processed. (" + location + ")");
}
- warning("AttributeCannotBeProcessed", processors, attributeName, location);
+ warning("AttributeCannotBeProcessed", processors, attributeName, location);
} else {
- return processor.read(attributeName, source);
+ return processor.read(attributeName, source);
}
-
-
+
//handle extension attributes without processors
processor = (StAXAttributeProcessor<?>)processors.getProcessor(ANY_ATTRIBUTE);
if (processor == null) {
- Location location = source.getLocation();
- if (logger.isLoggable(Level.WARNING)) {
+ Location location = source.getLocation();
+ if (logger.isLoggable(Level.WARNING)) {
logger.warning("Could not find Default Attribute processor !");
}
- warning("DefaultAttributeProcessorNotAvailable", processors, ANY_ATTRIBUTE, location);
- }
-
+ warning("DefaultAttributeProcessorNotAvailable", processors, ANY_ATTRIBUTE, location);
+ }
+
return processor == null ? null : processor.read(attributeName, source);
}
-
+
@SuppressWarnings("unchecked")
public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
- if(model == null) {
- return;
- }
-
+ if (model == null) {
+ return;
+ }
+
// Delegate to the processor associated with the model type
- StAXAttributeProcessor processor = processors.getProcessor(model.getClass());
- if(processor == null) {
- if (logger.isLoggable(Level.WARNING)) {
- logger.warning("No StAX processor is configured to handle " + model.getClass());
- }
- warning("NoStaxProcessor", processors, model.getClass());
- } else {
- processor.write(model, outputSource);
- return;
- }
-
- //handle extension attributes without processors
+ StAXAttributeProcessor processor = processors.getProcessor(model.getClass());
+ if (processor == null) {
+ if (!Extension.class.isInstance(model)) {
+ if (logger.isLoggable(Level.WARNING)) {
+ logger.warning("No StAX processor is configured to handle " + model.getClass());
+ }
+ warning("NoStaxProcessor", processors, model.getClass());
+ }
+ } else {
+ processor.write(model, outputSource);
+ return;
+ }
+
+ //handle extension attributes without processors
processor = (StAXAttributeProcessor<?>)processors.getProcessor(ANY_ATTRIBUTE);
- if(processor == null) {
- if (logger.isLoggable(Level.WARNING)) {
- logger.warning("No Default StAX processor is configured to handle " + model.getClass());
- }
- warning("NoDefaultStaxProcessor", processors, model.getClass());
+ if (processor == null) {
+ if (logger.isLoggable(Level.WARNING)) {
+ logger.warning("No Default StAX processor is configured to handle " + model.getClass());
+ }
+ warning("NoDefaultStaxProcessor", processors, model.getClass());
} else {
- processor.write(model, outputSource);
- return;
+ processor.write(model, outputSource);
+ return;
}
}
-
-
-
+
@SuppressWarnings("unchecked")
public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
// Delegate to the processor associated with the model type
if (model != null) {
- StAXAttributeProcessor processor = processors.getProcessor(model.getClass());
+ StAXAttributeProcessor processor = processors.getProcessor(model.getClass());
if (processor != null) {
processor.resolve(model, resolver);
}
}
}
-
+
/**
* Read a model from an InputStream.
* @param is The artifact InputStream
@@ -226,8 +243,8 @@ public class ExtensibleStAXAttributeProcessor
writer.flush();
writer.close();
} catch (XMLStreamException e) {
- ContributionWriteException cw = new ContributionWriteException(e);
- error("ContributionWriteException", outputFactory, cw);
+ ContributionWriteException cw = new ContributionWriteException(e);
+ error("ContributionWriteException", outputFactory, cw);
throw cw;
}
}
@@ -235,7 +252,7 @@ public class ExtensibleStAXAttributeProcessor
public QName getArtifactType() {
return null;
}
-
+
public Class<Object> getModelType() {
return null;
}
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 d867667eae..7b4a7cff3a 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
@@ -81,6 +81,8 @@ public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Obje
// Register the URI as the artifact type starts with /
processor = (URLArtifactProcessor<Object>)processors.getProcessor(uri);
}
+
+ /*
if (processor == null) {
// Delegate to the processor associated with file extension
String fileName = getFileName(sourceURL);
@@ -101,6 +103,7 @@ public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Obje
processor = (URLArtifactProcessor<Object>)processors.getProcessor(extension);
}
}
+ */
if (processor == null) {
return null;
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 3b99cc0312..3a18e2b987 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
@@ -6,20 +6,21 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.contribution.processor;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.net.URI;
import java.net.URL;
@@ -33,7 +34,7 @@ import org.junit.Test;
/**
* URL Artifact Processor Extension Point test case
* Verifies the right registration and lookup for processors that handle filename and file types
- *
+ *
* @version $Rev$ $Date$
*/
public class URLartifactProcessorExtensionPointTestCase {
@@ -50,13 +51,15 @@ public class URLartifactProcessorExtensionPointTestCase {
@Test
public final void testFileTypeProcessor() {
- assertNotNull(artifactProcessors.getProcessor(".m1"));
+ assertNotNull(artifactProcessors.getProcessor("dir1/file1.m1"));
+ assertNotNull(artifactProcessors.getProcessor("file1.m1"));
}
@Test
public final void testFileNameProcessor() {
assertNotNull(artifactProcessors.getProcessor("file.m2"));
-
+ assertNotNull(artifactProcessors.getProcessor("dir1/file.m2"));
+ assertNull(artifactProcessors.getProcessor("onefile.m2"));
}
/**
diff --git a/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java b/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
index b0a46d0577..a39e387b5f 100644
--- a/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
+++ b/java/sca/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
@@ -59,6 +59,7 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.ExtensionType;
import org.apache.tuscany.sca.policy.PolicyFactory;
/**
@@ -71,7 +72,6 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
private AssemblyFactory assemblyFactory;
private PolicyFactory policyFactory;
private PolicySubjectProcessor policyProcessor;
- private PolicyFactory intentAttachPointTypeFactory;
private Monitor monitor;
public JavaImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) {
@@ -79,10 +79,9 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
this.javaFactory = modelFactories.getFactory(JavaImplementationFactory.class);
this.policyProcessor = new PolicySubjectProcessor(policyFactory);
- this.intentAttachPointTypeFactory = modelFactories.getFactory(PolicyFactory.class);
this.monitor = monitor;
}
-
+
/**
* Report a error.
*
@@ -90,39 +89,49 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
* @param message
* @param model
*/
- private void error(String message, Object model, Object... messageParameters) {
- if (monitor != null) {
- Problem problem = monitor.createProblem(this.getClass().getName(), "impl-javaxml-validation-messages", Severity.ERROR, model, message,(Object[])messageParameters);
- monitor.problem(problem);
- }
- }
-
- /**
- * 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(), "impl-javaxml-validation-messages", Severity.ERROR, model, message, ex);
- monitor.problem(problem);
- }
- }
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(this.getClass().getName(),
+ "impl-javaxml-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * 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(),
+ "impl-javaxml-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ ex);
+ monitor.problem(problem);
+ }
+ }
public JavaImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
// Read an <implementation.java>
JavaImplementation javaImplementation = javaFactory.createJavaImplementation();
-
- /*if ( javaImplementation instanceof PolicySubject ) {
- ExtensionType implType = intentAttachPointTypeFactory.createImplementationType();
- implType.setName(getArtifactType());
- implType.setUnresolved(true);
- ((PolicySubject)javaImplementation).setType(implType);
- }*/
-
+
+ ExtensionType implType = policyFactory.createImplementationType();
+ implType.setType(getArtifactType());
+ implType.setUnresolved(true);
+ javaImplementation.setType(implType);
+
javaImplementation.setUnresolved(true);
javaImplementation.setName(reader.getAttributeValue(null, CLASS));
@@ -162,22 +171,22 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
classReference = resolver.resolveModel(ClassReference.class, classReference);
Class<?> javaClass = classReference.getJavaClass();
if (javaClass == null) {
- error("ClassNotFoundException", resolver, javaImplementation.getName());
+ error("ClassNotFoundException", resolver, javaImplementation.getName());
//throw new ContributionResolveException(new ClassNotFoundException(javaImplementation.getName()));
- return;
+ return;
}
-
- javaImplementation.setJavaClass(javaClass);
+
+ javaImplementation.setJavaClass(javaClass);
try {
javaFactory.createJavaImplementation(javaImplementation, javaImplementation.getJavaClass());
} catch (IntrospectionException e) {
- ContributionResolveException ce = new ContributionResolveException(e);
- error("ContributionResolveException", javaFactory, ce);
+ ContributionResolveException ce = new ContributionResolveException(e);
+ error("ContributionResolveException", javaFactory, ce);
//throw ce;
- return;
+ return;
}
-
+
javaImplementation.setUnresolved(false);
mergeComponentType(resolver, javaImplementation);
@@ -201,7 +210,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
field = impl.getJavaClass().getDeclaredField(name);
int mod = field.getModifiers();
if ((Modifier.isPublic(mod) || Modifier.isProtected(mod)) && (!Modifier.isStatic(mod))) {
- return new JavaElementImpl(field);
+ return new JavaElementImpl(field);
}
} catch (NoSuchFieldException e1) {
// Ignore