You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/03/20 05:55:46 UTC
svn commit: r520276 - in
/incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer:
ComponentTypeWriter.java CompositeWriter.java ConstrainingTypeWriter.java
WriteTestCase.java util/BaseWriter.java
Author: jsdelfino
Date: Mon Mar 19 21:55:45 2007
New Revision: 520276
URL: http://svn.apache.org/viewvc?view=rev&rev=520276
Log:
More test cases exercising the assembly model spi.
Added:
incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/CompositeWriter.java (with props)
incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ConstrainingTypeWriter.java (with props)
Modified:
incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ComponentTypeWriter.java
incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/WriteTestCase.java
incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/util/BaseWriter.java
Modified: incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ComponentTypeWriter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ComponentTypeWriter.java?view=diff&rev=520276&r1=520275&r2=520276
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ComponentTypeWriter.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ComponentTypeWriter.java Mon Mar 19 21:55:45 2007
@@ -39,36 +39,39 @@
public ComponentTypeWriter(ComponentType componentType) {
this.componentType = componentType;
}
-
+
protected void write() throws SAXException {
- out.startElement(sca10, "componentType", "componentType",
- attrs(
- new Attr("constrainingType", getConstrainingType(componentType))
- ));
+ start("componentType", new Attr("constrainingType", getConstrainingType(componentType)));
for (Service service: componentType.getServices()) {
- out.startElement(sca10, "service", "service", attrs(
- new Attr("name", service.getName())
- ));
+ start("service", new Attr("name", service.getName()));
+ if (service.getCallback() != null) {
+ start("callback");
+ end("callback");
+ }
+ end("service");
}
for (Reference reference: componentType.getReferences()) {
//TODO handle multivalued target attribute
String target = reference.getTargets().isEmpty()? null: reference.getTargets().get(0).getName();
- out.startElement(sca10, "reference", "reference", attrs(
+ start("reference",
new Attr("name", reference.getName()),
- new Attr("target", target)
- ));
+ new Attr("target", target));
+ if (reference.getCallback() != null) {
+ start("callback");
+ end("callback");
+ }
+ end("reference");
}
for (Property property: componentType.getProperties()) {
- out.startElement(sca10, "property", "property", attrs(
- new Attr("name", property.getName())
- ));
+ start("property", new Attr("name", property.getName()));
+ end("property");
}
- out.endElement(sca10, "componentType", "componentType");
+ end("componentType");
}
}
Added: incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/CompositeWriter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/CompositeWriter.java?view=auto&rev=520276
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/CompositeWriter.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/CompositeWriter.java Mon Mar 19 21:55:45 2007
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.assembly.writer;
+
+import org.apache.tuscany.assembly.model.Component;
+import org.apache.tuscany.assembly.model.ComponentProperty;
+import org.apache.tuscany.assembly.model.ComponentReference;
+import org.apache.tuscany.assembly.model.ComponentService;
+import org.apache.tuscany.assembly.model.Composite;
+import org.apache.tuscany.assembly.model.CompositeReference;
+import org.apache.tuscany.assembly.model.CompositeService;
+import org.apache.tuscany.assembly.model.Property;
+import org.apache.tuscany.assembly.model.Reference;
+import org.apache.tuscany.assembly.model.Service;
+import org.apache.tuscany.assembly.writer.util.Attr;
+import org.apache.tuscany.assembly.writer.util.BaseWriter;
+import org.xml.sax.SAXException;
+
+/**
+ * A test handler to test the usability of the assembly model API when writing SCDL
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeWriter extends BaseWriter {
+
+ private Composite composite;
+
+ public CompositeWriter(Composite composite) {
+ this.composite = composite;
+ }
+
+ protected void write() throws SAXException {
+
+ start("composite", new Attr("constrainingType", getConstrainingType(composite)));
+
+ for (Service service: composite.getServices()) {
+ CompositeService compositeService = (CompositeService)service;
+ ComponentService promotedService = compositeService.getPromotedService();
+ String promote = promotedService != null? promotedService.getName():null;
+ start("service",
+ new Attr("name", service.getName()),
+ new Attr("promote", promote));
+ if (service.getCallback() != null) {
+ start("callback");
+ end("callback");
+ }
+ end("service");
+ }
+
+ for (Component component: composite.getComponents()) {
+ start("component",
+ new Attr("name", component.getName()));
+
+ for (ComponentService service: component.getServices()) {
+ start("service",
+ new Attr("name", service.getName()));
+ end("service");
+ if (service.getCallback() != null) {
+ start("callback");
+ end("callback");
+ }
+ }
+
+ for (ComponentReference reference: component.getReferences()) {
+ //TODO handle multivalued target attribute
+ String target = reference.getTargets().isEmpty()? null: reference.getTargets().get(0).getName();
+ start("reference",
+ new Attr("name", reference.getName()),
+ new Attr("target", target));
+ if (reference.getCallback() != null) {
+ start("callback");
+ end("callback");
+ }
+ end("reference");
+ }
+
+ for (ComponentProperty property: component.getProperties()) {
+ start("property", new Attr("name", property.getName()));
+ end("property");
+ }
+
+ end("component");
+ }
+
+ for (Reference reference: composite.getReferences()) {
+ //TODO handle multivalued promote attribute
+ CompositeReference compositeReference = (CompositeReference)reference;
+ String promote;
+ if (!compositeReference.getPromotedReferences().isEmpty())
+ promote = compositeReference.getPromotedReferences().get(0).getName();
+ else
+ promote = null;
+ start("reference",
+ new Attr("name", reference.getName()),
+ new Attr("promote", promote));
+ if (reference.getCallback() != null) {
+ start("callback");
+ end("callback");
+ }
+ end("reference");
+ }
+
+ for (Property property: composite.getProperties()) {
+ start("property", new Attr("name", property.getName()));
+ end("property");
+ }
+
+ end("composite");
+ }
+
+}
Propchange: incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/CompositeWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/CompositeWriter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ConstrainingTypeWriter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ConstrainingTypeWriter.java?view=auto&rev=520276
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ConstrainingTypeWriter.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ConstrainingTypeWriter.java Mon Mar 19 21:55:45 2007
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.assembly.writer;
+
+import org.apache.tuscany.assembly.model.AbstractProperty;
+import org.apache.tuscany.assembly.model.AbstractReference;
+import org.apache.tuscany.assembly.model.AbstractService;
+import org.apache.tuscany.assembly.model.ConstrainingType;
+import org.apache.tuscany.assembly.writer.util.Attr;
+import org.apache.tuscany.assembly.writer.util.BaseWriter;
+import org.xml.sax.SAXException;
+
+/**
+ * A test handler to test the usability of the assembly model API when writing SCDL
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConstrainingTypeWriter extends BaseWriter {
+
+ private ConstrainingType constrainingType;
+
+ public ConstrainingTypeWriter(ConstrainingType constrainingType) {
+ this.constrainingType = constrainingType;
+ }
+
+ protected void write() throws SAXException {
+
+ start("constrainingType");
+
+ for (AbstractService service: constrainingType.getServices()) {
+ start("service", new Attr("name", service.getName()));
+ end("service");
+ }
+
+ for (AbstractReference reference: constrainingType.getReferences()) {
+ //TODO handle multivalued target attribute
+ start("reference", new Attr("name", reference.getName()));
+ end("reference");
+ }
+
+ for (AbstractProperty property: constrainingType.getProperties()) {
+ start("property", new Attr("name", property.getName()));
+ end("property");
+ }
+
+ end("constrainingType");
+ }
+
+}
Propchange: incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ConstrainingTypeWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/ConstrainingTypeWriter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/WriteTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/WriteTestCase.java?view=diff&rev=520276&r1=520275&r2=520276
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/WriteTestCase.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/WriteTestCase.java Mon Mar 19 21:55:45 2007
@@ -45,7 +45,6 @@
public class WriteTestCase extends TestCase {
AssemblyFactory factory;
-
XMLReader reader;
Transformer transformer;
@@ -57,6 +56,7 @@
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty("indent", "yes");
}
public void tearDown() throws Exception {
@@ -84,20 +84,30 @@
System.out.println();
}
- public void testWriteConstrainingType() throws Exception {
+ public void testWriteComposite() throws Exception {
InputStream is = getClass().getClassLoader().getResourceAsStream("Calculator.composite");
CompositeHandler handler = new CompositeHandler(factory, reader);
reader.setContentHandler(handler);
reader.parse(new InputSource(is));
assertNotNull(handler.getComposite());
+
+ CompositeWriter writer = new CompositeWriter(handler.getComposite());
+ System.out.println();
+ transformer.transform(new SAXSource(writer, null), new StreamResult(System.out));
+ System.out.println();
}
- public void testWriteComposite() throws Exception {
+ public void testWriteConstrainingType() throws Exception {
InputStream is = getClass().getClassLoader().getResourceAsStream("CalculatorComponent.constrainingType");
ConstrainingTypeHandler handler = new ConstrainingTypeHandler(factory, reader);
reader.setContentHandler(handler);
reader.parse(new InputSource(is));
assertNotNull(handler.getConstrainingType());
+
+ ConstrainingTypeWriter writer = new ConstrainingTypeWriter(handler.getConstrainingType());
+ System.out.println();
+ transformer.transform(new SAXSource(writer, null), new StreamResult(System.out));
+ System.out.println();
}
}
Modified: incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/util/BaseWriter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/util/BaseWriter.java?view=diff&rev=520276&r1=520275&r2=520276
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/util/BaseWriter.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/scdl/src/test/java/org/apache/tuscany/assembly/writer/util/BaseWriter.java Mon Mar 19 21:55:45 2007
@@ -61,7 +61,23 @@
out = handler;
}
- protected Attributes attrs(Attr... attrs) {
+ protected void start(String uri, String name, Attr... attrs) throws SAXException {
+ out.startElement(uri, null, name, attributes(attrs));
+ }
+
+ protected void start(String name, Attr... attrs) throws SAXException {
+ out.startElement(sca10, null, name, attributes(attrs));
+ }
+
+ protected void end(String uri, String name) throws SAXException {
+ out.endElement(uri, null, name);
+ }
+
+ protected void end(String name) throws SAXException {
+ out.endElement(sca10, null, name);
+ }
+
+ protected Attributes attributes(Attr... attrs) {
AttributesImpl attributes = new AttributesImpl();
for (Attr attr: attrs) {
if (attr != null)
@@ -79,7 +95,7 @@
}
protected Attributes abstractPropertyAttributes(AbstractProperty prop) {
- Attributes attributes = attrs(
+ Attributes attributes = attributes(
new Attr("name", prop.getName()),
new Attr("many", prop.isMany()),
new Attr("mustSupply", prop.isMustSupply()),
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org