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 23:12:10 UTC
svn commit: r521022 [2/2] - in /incubator/tuscany/sandbox/sebastien/java/sca:
assembly-builder/src/main/java/org/apache/tuscany/assembly/builder/
assembly-builder/src/main/java/org/apache/tuscany/assembly/builder/impl/
assembly-builder/src/test/java/or...
Added: incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Attr.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Attr.java?view=auto&rev=521022
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Attr.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Attr.java Wed Mar 21 15:12:08 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.scdl.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/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Attr.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Attr.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Base.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Base.java?view=auto&rev=521022
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Base.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Base.java Wed Mar 21 15:12:08 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.scdl.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/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Base.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Base.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Element.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Element.java?view=auto&rev=521022
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Element.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Element.java Wed Mar 21 15:12:08 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.scdl.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/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Element.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/Element.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/ElementWriter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/ElementWriter.java?view=auto&rev=521022
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/ElementWriter.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/ElementWriter.java Wed Mar 21 15:12:08 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.scdl.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/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/ElementWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/sebastien/java/sca/assembly-scdl/src/test/java/org/apache/tuscany/scdl/xml/util/ElementWriter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/sandbox/sebastien/java/sca/assembly/src/main/java/org/apache/tuscany/assembly/util/PrintUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/sebastien/java/sca/assembly/src/main/java/org/apache/tuscany/assembly/util/PrintUtil.java?view=auto&rev=521022
==============================================================================
--- incubator/tuscany/sandbox/sebastien/java/sca/assembly/src/main/java/org/apache/tuscany/assembly/util/PrintUtil.java (added)
+++ incubator/tuscany/sandbox/sebastien/java/sca/assembly/src/main/java/org/apache/tuscany/assembly/util/PrintUtil.java Wed Mar 21 15:12:08 2007
@@ -0,0 +1,114 @@
+/*
+ * 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.util;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * A simple print utility class to help print the assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PrintUtil {
+
+ PrintWriter out;
+ Set<Object> objs = new HashSet<Object>();
+ int level;
+
+ public PrintUtil(OutputStream out) {
+ this.out = new PrintWriter(new OutputStreamWriter(out), true);
+ }
+
+ void indent(int level) {
+ for (int i=0; i<level; i++) {
+ out.print(" ");
+ }
+ }
+
+ public void print(Object obj) {
+ if (objs.contains(obj)) {
+ indent(level);
+ out.println(obj.getClass().getName()+"@"+System.identityHashCode(obj));
+ }
+ else {
+ objs.add(obj);
+ try {
+ indent(level);
+ out.println(obj.getClass().getSimpleName() + " {");
+ BeanInfo bi = Introspector.getBeanInfo(obj.getClass());
+ for (PropertyDescriptor pd: bi.getPropertyDescriptors()) {
+ try {
+ Object pv = pd.getReadMethod().invoke(obj);
+ if (pv != null) {
+ if (pv.getClass().isArray()) {
+ pv = Arrays.asList((Object[])pv);
+ }
+ if (pv instanceof List) {
+ if (!((List)pv).isEmpty()) {
+ level++;
+ indent(level);
+ out.println(pd.getName() + "= [");
+ for (Object e: (List)pv) {
+ level++;
+ print(e);
+ level--;
+ }
+ indent(level);
+ out.println( " ]");
+ level--;
+ }
+ }
+ else {
+ Class<?> pvc = pv.getClass();
+ if (pvc.isPrimitive() || pvc.getName().startsWith("java.") || pvc.getName().startsWith("javax.") || pvc.isEnum()) {
+ if (!pd.getName().equals("class")) {
+ if (!(Boolean.FALSE.equals(pv))) {
+ indent(level+1);
+ out.println(pd.getName() + "=" + pv.toString());
+ }
+ }
+ } else {
+ level++;
+ print(pv);
+ level--;
+ }
+ }
+ }
+ } catch (Exception e) {}
+ }
+ indent(level);
+ out.println("}");
+ } catch (IntrospectionException e) {
+ indent(level);
+ out.println(e);
+ }
+ }
+ }
+
+}
Propchange: incubator/tuscany/sandbox/sebastien/java/sca/assembly/src/main/java/org/apache/tuscany/assembly/util/PrintUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/sandbox/sebastien/java/sca/assembly/src/main/java/org/apache/tuscany/assembly/util/PrintUtil.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