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/21 08:46:07 UTC

svn commit: r520786 - in /incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml: ./ BuildCompositeXMLTestCase.java util/ util/Attr.java util/Base.java util/Element.java util/ElementWriter.java

Author: jsdelfino
Date: Wed Mar 21 00:46:06 2007
New Revision: 520786

URL: http://svn.apache.org/viewvc?view=rev&rev=520786
Log:
Added xml builder test case

Added:
    incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/
    incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/BuildCompositeXMLTestCase.java   (with props)
    incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/
    incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Attr.java   (with props)
    incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Base.java   (with props)
    incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Element.java   (with props)
    incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/ElementWriter.java   (with props)

Added: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/BuildCompositeXMLTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/BuildCompositeXMLTestCase.java?view=auto&rev=520786
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/BuildCompositeXMLTestCase.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/BuildCompositeXMLTestCase.java Wed Mar 21 00:46:06 2007
@@ -0,0 +1,73 @@
+/*
+ * 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.xml;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.tuscany.assembly.xml.util.Attr;
+import org.apache.tuscany.assembly.xml.util.Element;
+import org.apache.tuscany.assembly.xml.util.ElementWriter;
+
+import junit.framework.TestCase;
+
+public class BuildCompositeXMLTestCase extends TestCase {
+	
+	public void testBuildComposite() throws Exception {
+		
+		Element element = new Element("http://www.osoa.org/xmlns/sca/1.0", "composite",
+				
+			new Element("service",
+				new Attr("name", "AccountService"),
+				new Attr("promote", "AccountServiceComponent/AccountService")),
+				
+			new Element("component",
+				new Attr("name", "AccountServiceComponent"),
+				new Element("service",
+					new Attr("name", "AccountService"),
+					new Element("interface.java",
+						new Attr("interface", "bigbank.account.AccountService")
+					)
+				),
+				new Element("reference",
+					new Attr("name", "stockQuoteService"),
+					new Element("interface.java",
+						new Attr("interface", "bigbank.stockquote.StockQuoteService")
+					)
+				),
+				new Element("implementation.java",
+					new Attr("class", "bigbank.account.AccountServiceImpl")
+				)
+			)
+		);
+		
+		ElementWriter writer = new ElementWriter(element);
+		
+        Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        transformer.setOutputProperty("indent", "yes");
+        System.out.println();
+        transformer.transform(new SAXSource(writer, null), new StreamResult(System.out));
+        System.out.println();
+		
+	}
+
+}

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/BuildCompositeXMLTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/BuildCompositeXMLTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Attr.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Attr.java?view=auto&rev=520786
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Attr.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Attr.java Wed Mar 21 00:46:06 2007
@@ -0,0 +1,73 @@
+/*
+ * 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.xml.util;
+
+import javax.xml.namespace.QName;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.helpers.AttributesImpl;
+
+public class Attr extends Base {
+	
+	String uri;
+	String name;
+	Object value;
+	
+	public Attr(String uri, String name, String value) {
+		this.uri = uri;
+		this.name = name;
+		this.value = value;
+	}
+
+	public Attr(String name, String value) {
+		this.name = name;
+		this.value = value;
+	}
+
+	public Attr(String uri, String name, boolean value) {
+		this.uri = uri;
+		this.name = name;
+		this.value = value;
+	}
+
+	public Attr(String name, boolean value) {
+		this.name = name;
+		this.value = value;
+	}
+	
+	public Attr(String uri, String name, QName value) {
+		this.uri = uri;
+		this.name = name;
+		this.value = value;
+	}
+
+	public Attr(String name, QName value) {
+		this.name = name;
+		this.value = value;
+	}
+	
+	void write(AttributesImpl attrs) {
+		attrs.addAttribute(uri, null, name, "CDATA", String.valueOf(value));
+	}
+	
+	public void write(ContentHandler out) {
+	}
+	
+}

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Attr.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Attr.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Base.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Base.java?view=auto&rev=520786
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Base.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Base.java Wed Mar 21 00:46:06 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.xml.util;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+public abstract class Base {
+
+	abstract void write(AttributesImpl attrs) throws SAXException;
+	
+	public abstract void write(ContentHandler out) throws SAXException;
+	
+}

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Base.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Base.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Element.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Element.java?view=auto&rev=520786
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Element.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Element.java Wed Mar 21 00:46:06 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.xml.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+public class Element extends Base {
+
+	private String uri;
+	private String name;
+	private List<Base> children = new ArrayList<Base>();
+	
+	public Element(String uri, String name, Base... children) {
+		this.uri = uri;
+		this.name = name;
+		this.children.addAll(Arrays.asList(children));
+	}
+
+	public Element(String name, Base... children) {
+		this.name =name;
+		this.children.addAll(Arrays.asList(children));
+	}
+	
+	public void add(Base... children) {
+		this.children.addAll(Arrays.asList(children));
+	}
+	
+	void write(AttributesImpl attrs) {
+	}
+	
+	public void write(ContentHandler out) throws SAXException {
+		AttributesImpl attrs = new AttributesImpl();
+		for (Base child: children) {
+			if (child != null)
+				child.write(attrs);
+		}
+		out.startElement(uri, null, name, attrs);
+		for (Base child: children) {
+			if (child != null)
+				child.write(out);
+		}
+		out.endElement(uri, null, name);
+	}
+
+}

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Element.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/Element.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/ElementWriter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/ElementWriter.java?view=auto&rev=520786
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/ElementWriter.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/ElementWriter.java Wed Mar 21 00:46:06 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.xml.util;
+
+import java.io.IOException;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+/**
+ * A test writer to test the usability of the assembly model API when writing SCDL
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ElementWriter extends XMLFilterImpl {
+
+	private Element element;
+    private ContentHandler out;
+
+    public ElementWriter(Element element) {
+    	this.element = element;
+	}
+    
+    public void parse(InputSource input) throws SAXException, IOException {
+    	out.startDocument();
+    	element.write(out);
+    	out.endDocument();
+    }
+    
+    public void setContentHandler(ContentHandler handler) {
+    	super.setContentHandler(handler);
+    	out = handler;
+    }
+    
+}

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/ElementWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/sebastien/java/sca/scdl/src/test/java/org/apache/tuscany/assembly/xml/util/ElementWriter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org