You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by vi...@apache.org on 2006/02/07 11:24:13 UTC

svn commit: r375561 - in /incubator/synapse/trunk/scratch/infravio/synapse-SO: ./ lib/ src/ src/com/ src/com/infravio/ src/com/infravio/core/ src/com/infravio/utils/

Author: vikas
Date: Tue Feb  7 02:24:10 2006
New Revision: 375561

URL: http://svn.apache.org/viewcvs?rev=375561&view=rev
Log:
The prototype of synapse object for property and parameter handling!

Added:
    incubator/synapse/trunk/scratch/infravio/synapse-SO/
    incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt
    incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml
    incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/
    incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/xercesImpl.jar   (with props)
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java
    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt?rev=375561&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt (added)
+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt Tue Feb  7 02:24:10 2006
@@ -0,0 +1,12 @@
+Features:
+1) Create SynapseObject from SynapseObject-XML
+2) Create SynapseObject from any xml using BO xslt
+3) SynapseObject can have a SynapseObject (self aggregation)
+4) SynapseObject can have 0 or more attributes
+5) To set attribute for a SynapseMediatorObject there are setters/getters
+   methods such as setString(String name,String value), setLong(String name,String value),etc.
+   eg. SetString(foo,value)
+6) SynapseObject has a getXMLFragment method which spits out an xml
+   representing the BO itself
+7) SynapseObject have finder methods based on attribute names, values as
+   well as businessObjects.
\ No newline at end of file

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml?rev=375561&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml (added)
+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml Tue Feb  7 02:24:10 2006
@@ -0,0 +1,85 @@
+<?xml version = '1.0' encoding = 'windows-1252'?>
+
+<project name="Test" default="usage" basedir=".">
+
+
+   <!--Set the output directories-->
+   <property name="compile.outdir" value="classes"/>
+   <property name="javadoc.outdir" value="javadoc"/>
+
+   <!--Set the classpath-->
+   <path id="classpath">
+      <pathelement location="lib/xercesImpl.jar"/>
+      <pathelement location="${compile.outdir}"/>
+   </path>
+
+   <!--Set the source path-->
+   <property name="src.dir" value="src"/>
+   <path id="srcpath">
+      <pathelement location="${src.dir}"/>
+   </path>
+
+   <target name="usage">
+    <echo>
+        ant compile
+            Compiles the source code and creates a classes directory at the same level as src
+        ant Sample
+            Runs the com.infravio.core.Sample which demonstrates building a SynapseObject through 
+            API and displays the its xml fragment.
+        ant TestSample
+            Runs the com.infravio.utils.TestSample which creates a SynapseObject from an xml fragment. Displays the xml fragment for that synapse object.
+    </echo>
+   </target>
+
+   <target name="Sample">
+       <java classname="com.infravio.core.Sample">
+               <classpath refid="classpath"/>
+       </java>
+   </target>
+
+   <target name="TestSample">
+       <java classname="com.infravio.utils.TestSample">
+           <classpath refid="classpath"/>
+        </java>
+   </target>
+
+   <target name="init">
+      <tstamp/>
+   </target>
+
+   <target name="compile" depends="init">
+      <mkdir dir="${compile.outdir}"/>
+      <!--Compile Java source files-->
+      <javac destdir="${compile.outdir}" debug="on" encoding="Cp1252">
+         <classpath refid="classpath"/>
+         <src refid="srcpath"/>
+         <include name="com/infravio/utils/TestSample.java"/>
+         <include name="com/infravio/utils/UtilConstants.java"/>
+         <include name="com/infravio/core/SynapseObjectArray.java"/>
+         <include name="com/infravio/utils/Utils.java"/>
+         <include name="com/infravio/core/Sample.java"/>
+         <include name="com/infravio/core/GenericObject.java"/>
+         <include name="com/infravio/core/SynapseObject.java"/>
+      </javac>
+   </target>
+
+   <target name="doc" depends="init">
+      <mkdir dir="${javadoc.outdir}"/>
+      <!--Create Javadoc-->
+      <javadoc sourcepathref="srcpath" classpathref="classpath" destdir="${javadoc.outdir}" version="false" author="false" encoding="Cp1252" additionalparam="-J-Xmx32m">
+         <package name="com.infravio.utils"/>
+         <package name="com.infravio.core"/>
+      </javadoc>
+   </target>
+
+   <target name="clean">
+      <!--Delete output directories-->
+      <delete dir="${compile.outdir}"/>
+      <delete dir="${javadoc.outdir}"/>
+   </target>
+
+   <target name="rebuild" depends="clean,compile"/>
+
+   <target name="all" depends="compile,doc"/>
+
+</project>

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/xercesImpl.jar
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/xercesImpl.jar?rev=375561&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/xercesImpl.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java?rev=375561&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java (added)
+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java Tue Feb  7 02:24:10 2006
@@ -0,0 +1,30 @@
+package com.infravio.core;
+
+import java.io.Serializable;
+
+/**
+ * @author
+ */
+public class GenericObject implements Serializable {
+    String name;
+    String type;
+    String value;
+
+    public GenericObject(String name, String type, String value) {
+        this.name = name;
+        this.type = type;
+        this.value = value;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+     public String getValue() {
+        return value;
+    }
+}
\ No newline at end of file

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java?rev=375561&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java (added)
+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java Tue Feb  7 02:24:10 2006
@@ -0,0 +1,27 @@
+package com.infravio.core;
+
+/**
+ * @author
+ */
+public class Sample {
+    public Sample() {
+    }
+
+    public static void main(String[] args) {
+        SynapseObject slaConfig = new SynapseObject("slaConfig");
+        SynapseObject slaRequest = new SynapseObject("slaRequest");
+        SynapseObject serviceURL = new SynapseObject("serviceURL");
+        slaRequest.setString("ip", "192.168.1.127");
+        slaRequest.setBoolean("enabled", "true");
+        serviceURL.setString("url", "http://www.webservicex.net/stockquote.asmx");
+        serviceURL.setBoolean("enabled", "true");
+        serviceURL.setInteger("priority", "0");
+        slaConfig.addChild(slaRequest);
+        slaRequest.addChild(serviceURL);
+        SynapseObject serviceURL1 = new SynapseObject("serviceURL1");
+        serviceURL1.setString("url", "http://www.webservicex.net/stockquote.asmx");
+        slaRequest.addChild(serviceURL1);
+        System.out.println(slaConfig.getXMLFragment());
+
+    }
+}
\ No newline at end of file

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java?rev=375561&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java (added)
+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java Tue Feb  7 02:24:10 2006
@@ -0,0 +1,264 @@
+package com.infravio.core;
+
+import org.w3c.dom.Document;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.*;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * @author
+ */
+public class SynapseObject extends Hashtable implements Serializable {
+    SynapseObjectArray object = new SynapseObjectArray();
+    String objectName;
+    String createdBy;
+    String creationDate;
+
+    public SynapseObject(String objectName) {
+        this.objectName = objectName;
+    }
+
+    public String translate(String xsl) {
+        String out_xml = "";
+        String xml = this.getXMLFragment();
+        TransformerFactory tFactory = TransformerFactory.newInstance();
+        try {
+            Transformer transformer = tFactory.newTransformer(new StreamSource(new StringReader(xsl)));
+            try {
+                ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
+                transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(byteArrayOutput));
+                out_xml = byteArrayOutput.toString();
+            } catch (TransformerException e) {
+                e.printStackTrace();
+            }
+        } catch (TransformerConfigurationException e) {
+            e.printStackTrace();
+        }
+        return out_xml;
+    }
+
+    public String getBOName() {
+        return this.objectName;
+    }
+
+    /**
+     * Get contained object
+     *
+     * @return SynapseObject
+     */
+    public SynapseObject[] getChildren() {
+        return this.object.getSynapseObjects();
+    }
+
+    /**
+     * Set object
+     *
+     * @param SynapseObject
+     */
+    public void addChild(SynapseObject SynapseObject) {
+
+        this.object.add(SynapseObject);
+    }
+
+    public void setLong(String attributeName, String attributeValue) {
+        GenericObject go = new GenericObject(attributeName, (Long.TYPE).getName(), attributeValue);
+        this.put(attributeName, go);
+    }
+
+    public void setInteger(String attributeName, String attributeValue) {
+        GenericObject go = new GenericObject(attributeName, (Integer.TYPE).getName(), attributeValue);
+        this.put(attributeName, go);
+    }
+
+    public void setFloat(String attributeName, String attributeValue) {
+        GenericObject go = new GenericObject(attributeName, (Float.TYPE).getName(), attributeValue);
+        this.put(attributeName, go);
+    }
+
+    public void setString(String attributeName, String attributeValue) {
+        GenericObject go = new GenericObject(attributeName, "STRING", attributeValue);
+        this.put(attributeName, go);
+    }
+
+    public void setBoolean(String attributeName, String attributeValue) {
+        GenericObject go = new GenericObject(attributeName, (Boolean.TYPE).getName(), attributeValue);
+        this.put(attributeName, go);
+    }
+
+    public Long getLong(String attributeName) {
+        GenericObject go = (GenericObject) this.get(attributeName);
+        return new Long(go.getValue());
+    }
+
+    public String getXMLFragment() {
+        String xmlFragStart = "";
+        String xmlFragEnd = "</SynapseObject>";
+        String x3 = recurse(this, xmlFragStart);
+        xmlFragStart += xmlFragEnd;
+        return x3;
+    }
+    private String recurse(SynapseObject bo, String xmlFrag) {
+
+        xmlFrag = xmlFrag + "<SynapseObject name=\"" + bo.getBOName() + "\">\n";
+        xmlFrag = bo.getAttributes(bo, xmlFrag);
+        Enumeration enumeration = bo.object.elements();
+        while (enumeration.hasMoreElements()) {
+            SynapseObject boj = (SynapseObject)enumeration.nextElement();
+            xmlFrag = boj.recurse(boj, xmlFrag);
+        }
+        xmlFrag += "</SynapseObject>\n";
+        return xmlFrag;
+    }
+
+    private String getAttributes(SynapseObject bo, String xmlReturn) {
+
+        Enumeration enumeration = bo.elements();
+        while (enumeration.hasMoreElements()) {
+            GenericObject go = (GenericObject) enumeration.nextElement();
+            String name = go.getName();
+            String type = go.getType();
+            String value = go.getValue();
+            xmlReturn += "<attribute name=\"" + name + "\" " + "type=\"" + type + "\">" + value + "</attribute>\n";
+        }
+        return xmlReturn;
+    }
+
+    public SynapseObject findSynapseObjectByAttributeValue(String attributeValue) {
+        SynapseObject bo = new SynapseObject("Not Found");
+        if (this.hasAttributeValue(attributeValue)) {
+            return this;
+        } else {
+            Enumeration enumeration = this.object.elements();
+            while (enumeration.hasMoreElements()) {
+                SynapseObject boj = (SynapseObject)enumeration.nextElement();
+                bo = boj.findSynapseObjectByAttributeValue(attributeValue);
+            }
+        }
+        return bo;
+    }
+
+    public boolean hasAttributeValue(String attr) {
+        SynapseObject bo = this;
+        Enumeration enumeration = bo.elements();
+        while (enumeration.hasMoreElements()) {
+            GenericObject go = (GenericObject) enumeration.nextElement();
+            String value = go.getValue();
+            if (attr.equals(value)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public SynapseObject findSynapseObjectByName(String name) {
+        SynapseObject bo = new SynapseObject("Not Found");
+        if (this.getBOName().equalsIgnoreCase(name)) {
+            return this;
+        } else {
+            Enumeration enumeration = this.object.elements();
+            while (enumeration.hasMoreElements()) {
+                SynapseObject boj = (SynapseObject)enumeration.nextElement();
+                bo = boj.findSynapseObjectByName(name);
+            }
+        }
+        return bo;
+    }
+
+    public SynapseObject[] findSynapseObjectsByAttributeName(String attributeName) {
+
+        SynapseObjectArray boArray = new SynapseObjectArray();
+
+        if (this.findChildrenWithAttributeName(attributeName) != null)
+            boArray.addSynapseObjects(this.findChildrenWithAttributeName(attributeName));
+
+        Enumeration enumeration = this.object.elements();
+        while (enumeration.hasMoreElements()) {
+            SynapseObject bo = (SynapseObject)enumeration.nextElement();
+            if (bo.findSynapseObjectsByAttributeName(attributeName) != null) {
+                boArray.addSynapseObjects(bo.findSynapseObjectsByAttributeName(attributeName));
+            }
+        }
+
+        if (boArray.size() > 0) {
+            return boArray.getSynapseObjects();
+        } else {
+            return null;
+        }
+    }
+
+    public SynapseObject[] findChildrenWithAttributeName(String attributeName) {
+        SynapseObjectArray boa = new SynapseObjectArray();
+        Enumeration enumeration = this.object.elements();
+        while (enumeration.hasMoreElements()) {
+            SynapseObject bo = (SynapseObject)enumeration.nextElement();
+            if (bo.hasAttribute(attributeName)) {
+                boa.addSynapseObject(bo);
+            }
+        }
+        if (boa.size() > 0) {
+            return boa.getSynapseObjects();
+        } else {
+            return null;
+        }
+    }
+
+
+    public SynapseObject[] findSynapseObjectsByAttributeValue(String attributeValue) {
+
+        SynapseObjectArray boArray = new SynapseObjectArray();
+
+        if (this.findChildrenWithAttributeName(attributeValue) != null)
+            boArray.addSynapseObjects(this.findChildrenWithAttributeName(attributeValue));
+
+        Enumeration enumeration = this.object.elements();
+        while (enumeration.hasMoreElements()) {
+            SynapseObject bo = (SynapseObject)enumeration.nextElement();
+            if (bo.findSynapseObjectsByAttributeName(attributeValue) != null) {
+                boArray.addSynapseObjects(bo.findSynapseObjectsByAttributeName(attributeValue));
+            }
+        }
+
+        if (boArray.size() > 0) {
+            return boArray.getSynapseObjects();
+        } else {
+            return null;
+        }
+    }
+
+    public SynapseObject[] findChildrenWithAttributeValue(String attributeValue) {
+        SynapseObjectArray boa = new SynapseObjectArray();
+        Enumeration enumeration = this.object.elements();
+        while (enumeration.hasMoreElements()) {
+            SynapseObject bo = (SynapseObject)enumeration.nextElement();
+            if (bo.hasAttributeValue(attributeValue)) {
+                boa.addSynapseObject(bo);
+            }
+        }
+        if (boa.size() > 0) {
+            return boa.getSynapseObjects();
+        } else {
+            return null;
+        }
+    }
+
+
+    public boolean hasAttribute(String attr) {
+        SynapseObject bo = this;
+        Enumeration enumeration = bo.elements();
+        while (enumeration.hasMoreElements()) {
+            GenericObject go = (GenericObject) enumeration.nextElement();
+            String name = go.getName();
+            if (attr.equals(name)) {
+                return true;
+            }
+        }
+        return false;
+  }
+}
\ No newline at end of file

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java?rev=375561&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java (added)
+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java Tue Feb  7 02:24:10 2006
@@ -0,0 +1,32 @@
+package com.infravio.core;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+public class SynapseObjectArray extends Vector {
+    public SynapseObjectArray() {
+    }
+
+    public void addSynapseObject(SynapseObject bo) {
+        this.add(bo);
+    }
+
+    public void addSynapseObjects(SynapseObject[] bos) {
+        int length = bos.length;
+        int i;
+        for (i = 0; i < length; i++) {
+            this.add(bos[i]);
+        }
+    }
+
+    public SynapseObject[] getSynapseObjects() {
+        int count = this.size();
+        int index = 0;
+        SynapseObject[] children = new SynapseObject[count];
+        Enumeration enumeration = this.elements();
+        while (enumeration.hasMoreElements()) {
+            children[index++] = (SynapseObject)enumeration.nextElement();
+        }
+        return children;
+    }
+}
\ No newline at end of file

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java?rev=375561&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java (added)
+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java Tue Feb  7 02:24:10 2006
@@ -0,0 +1,21 @@
+package com.infravio.utils;
+
+import com.infravio.core.SynapseObject;
+
+public class TestSample {
+    public static void main(String[] args) {
+        String xml = "<SynapseObject name=\"SLA\">\n" +
+                "    <attribute name=\"service\" type=\"String\">http://myhost:myport/Service</attribute>\n" +
+                "    <SynapseObject name=\"consumer\">\n" +
+                "        <attribute name=\"ip\" type=\"string\">192.9.2.11</attribute>\n" +
+                "    </SynapseObject>\n" +
+                "</SynapseObject>";
+        SynapseObject so = Utils.xmlToSynapseObject(xml);
+        System.out.println("The XML Frag : \n" + so.getXMLFragment());
+        SynapseObject result[] = so.findSynapseObjectsByAttributeName("ip");
+        System.out.println("The XML for SynapseObject with 'ip' : \n" + result[0].getXMLFragment());
+        boolean hasAttrib = so.hasAttribute("service");
+        System.out.println("Has Attrib service : \n" + hasAttrib);
+
+    }
+}

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java?rev=375561&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java (added)
+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java Tue Feb  7 02:24:10 2006
@@ -0,0 +1,9 @@
+package com.infravio.utils;
+
+public class UtilConstants {
+
+    public static String NODE = "SynapseObject";
+    public static String LEAF = "attribute";
+    public static String NAME_ATTRIB = "name";
+    public static String TYPE_ATTRIB = "type";
+}

Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java?rev=375561&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java (added)
+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java Tue Feb  7 02:24:10 2006
@@ -0,0 +1,198 @@
+package com.infravio.utils;
+
+import com.infravio.core.SynapseObject;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+
+public class Utils {
+
+    private static Document xmlDocument;
+
+    public static SynapseObject xmlToSynapseObject(String xml) {
+        SynapseObject businessObj;
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+        try {
+            InputSource inputSource = new InputSource(new StringReader(xml));
+            DocumentBuilder parser = factory.newDocumentBuilder();
+            xmlDocument = parser.parse(inputSource);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        businessObj = createSynapseObject(xmlDocument);
+        return businessObj;
+    }
+
+    public static SynapseObject createSynapseObject(Document xmlDocument) {
+
+        SynapseObject businessObj = null;
+        NodeList node = xmlDocument.getChildNodes();
+        int len = node.getLength();
+        int i;
+
+        for (i = 0; i < len; i++) {
+
+            String nodeName = node.item(i).getNodeName();
+            if (nodeName.equalsIgnoreCase(UtilConstants.NODE)) {
+                businessObj = processBONode(node.item(i));
+            }
+        }
+        return businessObj;
+    }
+
+    private static SynapseObject processBONode(Node boNode) {
+
+        String name = "";
+        SynapseObject tempObj;
+        NamedNodeMap namedNodeMap = boNode.getAttributes();
+        int attributeCount = namedNodeMap.getLength();
+        for (int counter = 0; counter < attributeCount; counter++) {
+            Node attribName = namedNodeMap.item(counter);
+            if (attribName.getNodeName().equals(UtilConstants.NAME_ATTRIB)) {
+                name = namedNodeMap.getNamedItem(UtilConstants.NAME_ATTRIB).getNodeValue();
+            }
+
+        }
+        tempObj = new SynapseObject(name);
+        NodeList nodeList = boNode.getChildNodes();
+        int len = nodeList.getLength();
+        int i;
+
+        for (i = 0; i < len; i++) {
+            String nodeName = nodeList.item(i).getNodeName();
+            if (nodeName.equalsIgnoreCase(UtilConstants.LEAF)) {
+                try {
+                    tempObj = processGONode(nodeList.item(i), tempObj);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+            if (nodeName.equalsIgnoreCase(UtilConstants.NODE)) {
+                SynapseObject bObj = processBONode(nodeList.item(i));
+                tempObj.addChild(bObj);
+            }
+        }
+        return tempObj;
+    }
+
+    private static SynapseObject processGONode(Node goNode, SynapseObject parent) throws Exception {
+
+        String goName = "", goType = "", goValue = "";
+        NamedNodeMap namedNodeMap = goNode.getAttributes();
+        int attributeCount = namedNodeMap.getLength();
+        for (int counter = 0; counter < attributeCount; counter++) {
+            Node attribName = namedNodeMap.item(counter);
+            if (attribName.getNodeName().equals(UtilConstants.NAME_ATTRIB)) {
+                goName = namedNodeMap.getNamedItem(UtilConstants.NAME_ATTRIB).getNodeValue();
+            } else if (attribName.getNodeName().equals(UtilConstants.TYPE_ATTRIB)) {
+                goType = namedNodeMap.getNamedItem(UtilConstants.TYPE_ATTRIB).getNodeValue();
+            }
+        }
+        if (goNode.hasChildNodes()) {
+            if (goNode.getFirstChild().getNodeType() == Node.TEXT_NODE) {
+                goValue = goNode.getFirstChild().getNodeValue();
+            }
+        }
+        if (goType.equalsIgnoreCase("Boolean")) {
+            parent.setBoolean(goName, goValue);
+        } else if (goType.equalsIgnoreCase("Float")) {
+            parent.setFloat(goName, goValue);
+        } else if (goType.equalsIgnoreCase("Integer")) {
+            parent.setInteger(goName, goValue);
+        } else if (goType.equalsIgnoreCase("Long")) {
+            parent.setLong(goName, goValue);
+        } else if (goType.equalsIgnoreCase("String")) {
+            parent.setString(goName, goValue);
+        } else {
+            throw new Exception("TYPE NOT SUPPORTED!");
+        }
+        return parent;
+    }
+
+    public static String transform(String xml, String xsl) {
+        /*String xsl = "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n" +
+         "<xsl:output method=\"text\" /> \n" +
+         "<xsl:template match=\"/\">\n" +
+         "<xsl:apply-templates /> \n" +
+         "</xsl:template>\n" +
+         "<xsl:template match=\"student_list\">\n" +
+         "Student Directory for example.edu \n" +
+         "<xsl:apply-templates /> \n" +
+         "</xsl:template>\n" +
+         "<xsl:template match=\"name\">\n" +
+         "Name: \n" +
+         "<xsl:apply-templates /> \n" +
+         "</xsl:template>\n" +
+         "<xsl:template match=\"major\">\n" +
+         "Major: \n" +
+         "<xsl:apply-templates /> \n" +
+         "</xsl:template>\n" +
+         "<xsl:template match=\"phone\">\n" +
+         "Phone: \n" +
+         "<xsl:apply-templates /> \n" +
+         "</xsl:template>\n" +
+         "<xsl:template match=\"email\">\n" +
+         "Email: \n" +
+         "<xsl:apply-templates /> \n" +
+         "</xsl:template>\n" +
+         "</xsl:stylesheet>";
+
+  String xml = "<student_list>\n" +
+          "<student>\n" +
+          "<name>George Washington</name> \n" +
+          "<major>Politics</major> \n" +
+          "<phone>312-123-4567</phone> \n" +
+          "<email>gw@example.edu</email> \n" +
+          "</student>\n" +
+          "<student>\n" +
+          "<name>Janet Jones</name> \n" +
+          "<major>Undeclared</major> \n" +
+          "<phone>311-122-2233</phone> \n" +
+          "<email>janetj@example.edu</email> \n" +
+          "</student>\n" +
+          "<student>\n" +
+          "<name>Joe Taylor</name> \n" +
+          "<major>Engineering</major> \n" +
+          "<phone>211-111-2333</phone> \n" +
+          "<email>joe@example.edu</email> \n" +
+          "</student>\n" +
+          "</student_list>";
+        */
+        String out_xml = "";
+        TransformerFactory tFactory = TransformerFactory.newInstance();
+        try {
+            Transformer transformer = tFactory.newTransformer(new StreamSource(new StringReader(xsl)));
+            try {
+                ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
+                transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(byteArrayOutput));
+                out_xml = byteArrayOutput.toString();
+            } catch (TransformerException e) {
+                e.printStackTrace();
+            }
+        } catch (TransformerConfigurationException e) {
+            e.printStackTrace();
+        }
+        return out_xml;
+    }
+
+    public static SynapseObject transformToSynapseObject(String xml, String xsl){
+        String BOXml = Utils.transform(xml,xsl);
+        SynapseObject bObject = Utils.xmlToSynapseObject(BOXml);
+        return bObject;
+    }
+}



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


Re: svn commit: r375561 - in /incubator/synapse/trunk/scratch/infravio/synapse-SO: ./ lib/ src/ src/com/ src/com/infravio/ src/com/infravio/core/ src/com/infravio/utils/

Posted by Deepal jayasinghe <de...@gmail.com>.
vikas@apache.org wrote:

>Author: vikas
>Date: Tue Feb  7 02:24:10 2006
>New Revision: 375561
>
>URL: http://svn.apache.org/viewcvs?rev=375561&view=rev
>Log:
>The prototype of synapse object for property and parameter handling!
>
>Added:
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/xercesImpl.jar   (with props)
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java
>    incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt?rev=375561&view=auto
>==============================================================================
>--- incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt (added)
>+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/README.txt Tue Feb  7 02:24:10 2006
>@@ -0,0 +1,12 @@
>+Features:
>+1) Create SynapseObject from SynapseObject-XML
>+2) Create SynapseObject from any xml using BO xslt
>+3) SynapseObject can have a SynapseObject (self aggregation)
>+4) SynapseObject can have 0 or more attributes
>+5) To set attribute for a SynapseMediatorObject there are setters/getters
>+   methods such as setString(String name,String value), setLong(String name,String value),etc.
>+   eg. SetString(foo,value)
>+6) SynapseObject has a getXMLFragment method which spits out an xml
>+   representing the BO itself
>+7) SynapseObject have finder methods based on attribute names, values as
>+   well as businessObjects.
>\ No newline at end of file
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml?rev=375561&view=auto
>==============================================================================
>--- incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml (added)
>+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/build.xml Tue Feb  7 02:24:10 2006
>@@ -0,0 +1,85 @@
>+<?xml version = '1.0' encoding = 'windows-1252'?>
>+
>+<project name="Test" default="usage" basedir=".">
>+
>+
>+   <!--Set the output directories-->
>+   <property name="compile.outdir" value="classes"/>
>+   <property name="javadoc.outdir" value="javadoc"/>
>+
>+   <!--Set the classpath-->
>+   <path id="classpath">
>+      <pathelement location="lib/xercesImpl.jar"/>
>+      <pathelement location="${compile.outdir}"/>
>+   </path>
>+
>+   <!--Set the source path-->
>+   <property name="src.dir" value="src"/>
>+   <path id="srcpath">
>+      <pathelement location="${src.dir}"/>
>+   </path>
>+
>+   <target name="usage">
>+    <echo>
>+        ant compile
>+            Compiles the source code and creates a classes directory at the same level as src
>+        ant Sample
>+            Runs the com.infravio.core.Sample which demonstrates building a SynapseObject through 
>+            API and displays the its xml fragment.
>+        ant TestSample
>+            Runs the com.infravio.utils.TestSample which creates a SynapseObject from an xml fragment. Displays the xml fragment for that synapse object.
>+    </echo>
>+   </target>
>+
>+   <target name="Sample">
>+       <java classname="com.infravio.core.Sample">
>+               <classpath refid="classpath"/>
>+       </java>
>+   </target>
>+
>+   <target name="TestSample">
>+       <java classname="com.infravio.utils.TestSample">
>+           <classpath refid="classpath"/>
>+        </java>
>+   </target>
>+
>+   <target name="init">
>+      <tstamp/>
>+   </target>
>+
>+   <target name="compile" depends="init">
>+      <mkdir dir="${compile.outdir}"/>
>+      <!--Compile Java source files-->
>+      <javac destdir="${compile.outdir}" debug="on" encoding="Cp1252">
>+         <classpath refid="classpath"/>
>+         <src refid="srcpath"/>
>+         <include name="com/infravio/utils/TestSample.java"/>
>+         <include name="com/infravio/utils/UtilConstants.java"/>
>+         <include name="com/infravio/core/SynapseObjectArray.java"/>
>+         <include name="com/infravio/utils/Utils.java"/>
>+         <include name="com/infravio/core/Sample.java"/>
>+         <include name="com/infravio/core/GenericObject.java"/>
>+         <include name="com/infravio/core/SynapseObject.java"/>
>+      </javac>
>+   </target>
>+
>+   <target name="doc" depends="init">
>+      <mkdir dir="${javadoc.outdir}"/>
>+      <!--Create Javadoc-->
>+      <javadoc sourcepathref="srcpath" classpathref="classpath" destdir="${javadoc.outdir}" version="false" author="false" encoding="Cp1252" additionalparam="-J-Xmx32m">
>+         <package name="com.infravio.utils"/>
>+         <package name="com.infravio.core"/>
>+      </javadoc>
>+   </target>
>+
>+   <target name="clean">
>+      <!--Delete output directories-->
>+      <delete dir="${compile.outdir}"/>
>+      <delete dir="${javadoc.outdir}"/>
>+   </target>
>+
>+   <target name="rebuild" depends="clean,compile"/>
>+
>+   <target name="all" depends="compile,doc"/>
>+
>+</project>
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/xercesImpl.jar
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/xercesImpl.jar?rev=375561&view=auto
>==============================================================================
>Binary file - no diff available.
>
>Propchange: incubator/synapse/trunk/scratch/infravio/synapse-SO/lib/xercesImpl.jar
>------------------------------------------------------------------------------
>    svn:mime-type = application/octet-stream
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java?rev=375561&view=auto
>==============================================================================
>--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java (added)
>+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/GenericObject.java Tue Feb  7 02:24:10 2006
>@@ -0,0 +1,30 @@
>+package com.infravio.core;
>+
>+import java.io.Serializable;
>+
>+/**
>+ * @author
>+ */
>+public class GenericObject implements Serializable {
>+    String name;
>+    String type;
>+    String value;
>+
>+    public GenericObject(String name, String type, String value) {
>+        this.name = name;
>+        this.type = type;
>+        this.value = value;
>+    }
>+
>+    public String getName() {
>+        return name;
>+    }
>+
>+    public String getType() {
>+        return type;
>+    }
>+
>+     public String getValue() {
>+        return value;
>+    }
>+}
>\ No newline at end of file
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java?rev=375561&view=auto
>==============================================================================
>--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java (added)
>+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/Sample.java Tue Feb  7 02:24:10 2006
>@@ -0,0 +1,27 @@
>+package com.infravio.core;
>+
>+/**
>+ * @author
>+ */
>+public class Sample {
>+    public Sample() {
>+    }
>+
>+    public static void main(String[] args) {
>+        SynapseObject slaConfig = new SynapseObject("slaConfig");
>+        SynapseObject slaRequest = new SynapseObject("slaRequest");
>+        SynapseObject serviceURL = new SynapseObject("serviceURL");
>+        slaRequest.setString("ip", "192.168.1.127");
>+        slaRequest.setBoolean("enabled", "true");
>+        serviceURL.setString("url", "http://www.webservicex.net/stockquote.asmx");
>+        serviceURL.setBoolean("enabled", "true");
>+        serviceURL.setInteger("priority", "0");
>+        slaConfig.addChild(slaRequest);
>+        slaRequest.addChild(serviceURL);
>+        SynapseObject serviceURL1 = new SynapseObject("serviceURL1");
>+        serviceURL1.setString("url", "http://www.webservicex.net/stockquote.asmx");
>+        slaRequest.addChild(serviceURL1);
>+        System.out.println(slaConfig.getXMLFragment());
>+
>+    }
>+}
>\ No newline at end of file
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java?rev=375561&view=auto
>==============================================================================
>--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java (added)
>+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObject.java Tue Feb  7 02:24:10 2006
>@@ -0,0 +1,264 @@
>+package com.infravio.core;
>+
>+import org.w3c.dom.Document;
>+
>+import javax.xml.transform.Transformer;
>+import javax.xml.transform.TransformerConfigurationException;
>+import javax.xml.transform.TransformerException;
>+import javax.xml.transform.TransformerFactory;
>+import javax.xml.transform.stream.StreamResult;
>+import javax.xml.transform.stream.StreamSource;
>+import java.io.*;
>+import java.util.Enumeration;
>+import java.util.Hashtable;
>+
>+/**
>+ * @author
>+ */
>+public class SynapseObject extends Hashtable implements Serializable {
>+    SynapseObjectArray object = new SynapseObjectArray();
>+    String objectName;
>+    String createdBy;
>+    String creationDate;
>+
>+    public SynapseObject(String objectName) {
>+        this.objectName = objectName;
>+    }
>+
>+    public String translate(String xsl) {
>+        String out_xml = "";
>+        String xml = this.getXMLFragment();
>+        TransformerFactory tFactory = TransformerFactory.newInstance();
>+        try {
>+            Transformer transformer = tFactory.newTransformer(new StreamSource(new StringReader(xsl)));
>+            try {
>+                ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
>+                transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(byteArrayOutput));
>+                out_xml = byteArrayOutput.toString();
>+            } catch (TransformerException e) {
>+                e.printStackTrace();
>+            }
>+        } catch (TransformerConfigurationException e) {
>+            e.printStackTrace();
>+        }
>+        return out_xml;
>+    }
>+
>+    public String getBOName() {
>+        return this.objectName;
>+    }
>+
>+    /**
>+     * Get contained object
>+     *
>+     * @return SynapseObject
>+     */
>+    public SynapseObject[] getChildren() {
>+        return this.object.getSynapseObjects();
>+    }
>+
>+    /**
>+     * Set object
>+     *
>+     * @param SynapseObject
>+     */
>+    public void addChild(SynapseObject SynapseObject) {
>+
>+        this.object.add(SynapseObject);
>+    }
>+
>+    public void setLong(String attributeName, String attributeValue) {
>+        GenericObject go = new GenericObject(attributeName, (Long.TYPE).getName(), attributeValue);
>+        this.put(attributeName, go);
>+    }
>+
>+    public void setInteger(String attributeName, String attributeValue) {
>+        GenericObject go = new GenericObject(attributeName, (Integer.TYPE).getName(), attributeValue);
>+        this.put(attributeName, go);
>+    }
>+
>+    public void setFloat(String attributeName, String attributeValue) {
>+        GenericObject go = new GenericObject(attributeName, (Float.TYPE).getName(), attributeValue);
>+        this.put(attributeName, go);
>+    }
>+
>+    public void setString(String attributeName, String attributeValue) {
>+        GenericObject go = new GenericObject(attributeName, "STRING", attributeValue);
>+        this.put(attributeName, go);
>+    }
>+
>+    public void setBoolean(String attributeName, String attributeValue) {
>+        GenericObject go = new GenericObject(attributeName, (Boolean.TYPE).getName(), attributeValue);
>+        this.put(attributeName, go);
>+    }
>+
>+    public Long getLong(String attributeName) {
>+        GenericObject go = (GenericObject) this.get(attributeName);
>+        return new Long(go.getValue());
>+    }
>+
>+    public String getXMLFragment() {
>+        String xmlFragStart = "";
>+        String xmlFragEnd = "</SynapseObject>";
>+        String x3 = recurse(this, xmlFragStart);
>+        xmlFragStart += xmlFragEnd;
>+        return x3;
>+    }
>+    private String recurse(SynapseObject bo, String xmlFrag) {
>+
>+        xmlFrag = xmlFrag + "<SynapseObject name=\"" + bo.getBOName() + "\">\n";
>+        xmlFrag = bo.getAttributes(bo, xmlFrag);
>+        Enumeration enumeration = bo.object.elements();
>+        while (enumeration.hasMoreElements()) {
>+            SynapseObject boj = (SynapseObject)enumeration.nextElement();
>+            xmlFrag = boj.recurse(boj, xmlFrag);
>+        }
>+        xmlFrag += "</SynapseObject>\n";
>+        return xmlFrag;
>+    }
>+
>+    private String getAttributes(SynapseObject bo, String xmlReturn) {
>+
>+        Enumeration enumeration = bo.elements();
>+        while (enumeration.hasMoreElements()) {
>+            GenericObject go = (GenericObject) enumeration.nextElement();
>+            String name = go.getName();
>+            String type = go.getType();
>+            String value = go.getValue();
>+            xmlReturn += "<attribute name=\"" + name + "\" " + "type=\"" + type + "\">" + value + "</attribute>\n";
>+        }
>+        return xmlReturn;
>+    }
>+
>+    public SynapseObject findSynapseObjectByAttributeValue(String attributeValue) {
>+        SynapseObject bo = new SynapseObject("Not Found");
>+        if (this.hasAttributeValue(attributeValue)) {
>+            return this;
>+        } else {
>+            Enumeration enumeration = this.object.elements();
>+            while (enumeration.hasMoreElements()) {
>+                SynapseObject boj = (SynapseObject)enumeration.nextElement();
>+                bo = boj.findSynapseObjectByAttributeValue(attributeValue);
>+            }
>+        }
>+        return bo;
>+    }
>+
>+    public boolean hasAttributeValue(String attr) {
>+        SynapseObject bo = this;
>+        Enumeration enumeration = bo.elements();
>+        while (enumeration.hasMoreElements()) {
>+            GenericObject go = (GenericObject) enumeration.nextElement();
>+            String value = go.getValue();
>+            if (attr.equals(value)) {
>+                return true;
>+            }
>+        }
>+        return false;
>+    }
>+
>+    public SynapseObject findSynapseObjectByName(String name) {
>+        SynapseObject bo = new SynapseObject("Not Found");
>+        if (this.getBOName().equalsIgnoreCase(name)) {
>+            return this;
>+        } else {
>+            Enumeration enumeration = this.object.elements();
>+            while (enumeration.hasMoreElements()) {
>+                SynapseObject boj = (SynapseObject)enumeration.nextElement();
>+                bo = boj.findSynapseObjectByName(name);
>+            }
>+        }
>+        return bo;
>+    }
>+
>+    public SynapseObject[] findSynapseObjectsByAttributeName(String attributeName) {
>+
>+        SynapseObjectArray boArray = new SynapseObjectArray();
>+
>+        if (this.findChildrenWithAttributeName(attributeName) != null)
>+            boArray.addSynapseObjects(this.findChildrenWithAttributeName(attributeName));
>+
>+        Enumeration enumeration = this.object.elements();
>+        while (enumeration.hasMoreElements()) {
>+            SynapseObject bo = (SynapseObject)enumeration.nextElement();
>+            if (bo.findSynapseObjectsByAttributeName(attributeName) != null) {
>+                boArray.addSynapseObjects(bo.findSynapseObjectsByAttributeName(attributeName));
>+            }
>+        }
>+
>+        if (boArray.size() > 0) {
>+            return boArray.getSynapseObjects();
>+        } else {
>+            return null;
>+        }
>+    }
>+
>+    public SynapseObject[] findChildrenWithAttributeName(String attributeName) {
>+        SynapseObjectArray boa = new SynapseObjectArray();
>+        Enumeration enumeration = this.object.elements();
>+        while (enumeration.hasMoreElements()) {
>+            SynapseObject bo = (SynapseObject)enumeration.nextElement();
>+            if (bo.hasAttribute(attributeName)) {
>+                boa.addSynapseObject(bo);
>+            }
>+        }
>+        if (boa.size() > 0) {
>+            return boa.getSynapseObjects();
>+        } else {
>+            return null;
>+        }
>+    }
>+
>+
>+    public SynapseObject[] findSynapseObjectsByAttributeValue(String attributeValue) {
>+
>+        SynapseObjectArray boArray = new SynapseObjectArray();
>+
>+        if (this.findChildrenWithAttributeName(attributeValue) != null)
>+            boArray.addSynapseObjects(this.findChildrenWithAttributeName(attributeValue));
>+
>+        Enumeration enumeration = this.object.elements();
>+        while (enumeration.hasMoreElements()) {
>+            SynapseObject bo = (SynapseObject)enumeration.nextElement();
>+            if (bo.findSynapseObjectsByAttributeName(attributeValue) != null) {
>+                boArray.addSynapseObjects(bo.findSynapseObjectsByAttributeName(attributeValue));
>+            }
>+        }
>+
>+        if (boArray.size() > 0) {
>+            return boArray.getSynapseObjects();
>+        } else {
>+            return null;
>+        }
>+    }
>+
>+    public SynapseObject[] findChildrenWithAttributeValue(String attributeValue) {
>+        SynapseObjectArray boa = new SynapseObjectArray();
>+        Enumeration enumeration = this.object.elements();
>+        while (enumeration.hasMoreElements()) {
>+            SynapseObject bo = (SynapseObject)enumeration.nextElement();
>+            if (bo.hasAttributeValue(attributeValue)) {
>+                boa.addSynapseObject(bo);
>+            }
>+        }
>+        if (boa.size() > 0) {
>+            return boa.getSynapseObjects();
>+        } else {
>+            return null;
>+        }
>+    }
>+
>+
>+    public boolean hasAttribute(String attr) {
>+        SynapseObject bo = this;
>+        Enumeration enumeration = bo.elements();
>+        while (enumeration.hasMoreElements()) {
>+            GenericObject go = (GenericObject) enumeration.nextElement();
>+            String name = go.getName();
>+            if (attr.equals(name)) {
>+                return true;
>+            }
>+        }
>+        return false;
>+  }
>+}
>\ No newline at end of file
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java?rev=375561&view=auto
>==============================================================================
>--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java (added)
>+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/core/SynapseObjectArray.java Tue Feb  7 02:24:10 2006
>@@ -0,0 +1,32 @@
>+package com.infravio.core;
>+
>+import java.util.Enumeration;
>+import java.util.Vector;
>+
>+public class SynapseObjectArray extends Vector {
>+    public SynapseObjectArray() {
>+    }
>+
>+    public void addSynapseObject(SynapseObject bo) {
>+        this.add(bo);
>+    }
>+
>+    public void addSynapseObjects(SynapseObject[] bos) {
>+        int length = bos.length;
>+        int i;
>+        for (i = 0; i < length; i++) {
>+            this.add(bos[i]);
>+        }
>+    }
>+
>+    public SynapseObject[] getSynapseObjects() {
>+        int count = this.size();
>+        int index = 0;
>+        SynapseObject[] children = new SynapseObject[count];
>+        Enumeration enumeration = this.elements();
>+        while (enumeration.hasMoreElements()) {
>+            children[index++] = (SynapseObject)enumeration.nextElement();
>+        }
>+        return children;
>+    }
>+}
>\ No newline at end of file
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java?rev=375561&view=auto
>==============================================================================
>--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java (added)
>+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/TestSample.java Tue Feb  7 02:24:10 2006
>@@ -0,0 +1,21 @@
>+package com.infravio.utils;
>+
>+import com.infravio.core.SynapseObject;
>+
>+public class TestSample {
>+    public static void main(String[] args) {
>+        String xml = "<SynapseObject name=\"SLA\">\n" +
>+                "    <attribute name=\"service\" type=\"String\">http://myhost:myport/Service</attribute>\n" +
>+                "    <SynapseObject name=\"consumer\">\n" +
>+                "        <attribute name=\"ip\" type=\"string\">192.9.2.11</attribute>\n" +
>+                "    </SynapseObject>\n" +
>+                "</SynapseObject>";
>+        SynapseObject so = Utils.xmlToSynapseObject(xml);
>+        System.out.println("The XML Frag : \n" + so.getXMLFragment());
>+        SynapseObject result[] = so.findSynapseObjectsByAttributeName("ip");
>+        System.out.println("The XML for SynapseObject with 'ip' : \n" + result[0].getXMLFragment());
>+        boolean hasAttrib = so.hasAttribute("service");
>+        System.out.println("Has Attrib service : \n" + hasAttrib);
>+
>+    }
>+}
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java?rev=375561&view=auto
>==============================================================================
>--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java (added)
>+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/UtilConstants.java Tue Feb  7 02:24:10 2006
>@@ -0,0 +1,9 @@
>+package com.infravio.utils;
>+
>+public class UtilConstants {
>+
>+    public static String NODE = "SynapseObject";
>+    public static String LEAF = "attribute";
>+    public static String NAME_ATTRIB = "name";
>+    public static String TYPE_ATTRIB = "type";
>+}
>
>Added: incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java
>URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java?rev=375561&view=auto
>==============================================================================
>--- incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java (added)
>+++ incubator/synapse/trunk/scratch/infravio/synapse-SO/src/com/infravio/utils/Utils.java Tue Feb  7 02:24:10 2006
>@@ -0,0 +1,198 @@
>+package com.infravio.utils;
>+
>+import com.infravio.core.SynapseObject;
>+import org.w3c.dom.Document;
>+import org.w3c.dom.NamedNodeMap;
>+import org.w3c.dom.Node;
>+import org.w3c.dom.NodeList;
>+import org.xml.sax.InputSource;
>+
>+import javax.xml.parsers.DocumentBuilder;
>+import javax.xml.parsers.DocumentBuilderFactory;
>+import javax.xml.transform.Transformer;
>+import javax.xml.transform.TransformerConfigurationException;
>+import javax.xml.transform.TransformerException;
>+import javax.xml.transform.TransformerFactory;
>+import javax.xml.transform.stream.StreamResult;
>+import javax.xml.transform.stream.StreamSource;
>+import java.io.ByteArrayOutputStream;
>+import java.io.StringReader;
>+
>+public class Utils {
>+
>+    private static Document xmlDocument;
>+
>+    public static SynapseObject xmlToSynapseObject(String xml) {
>+        SynapseObject businessObj;
>+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>+
>+        try {
>+            InputSource inputSource = new InputSource(new StringReader(xml));
>+            DocumentBuilder parser = factory.newDocumentBuilder();
>+            xmlDocument = parser.parse(inputSource);
>+
>+        } catch (Exception e) {
>+            e.printStackTrace();
>+        }
>+        businessObj = createSynapseObject(xmlDocument);
>+        return businessObj;
>+    }
>+
>+    public static SynapseObject createSynapseObject(Document xmlDocument) {
>+
>+        SynapseObject businessObj = null;
>+        NodeList node = xmlDocument.getChildNodes();
>+        int len = node.getLength();
>+        int i;
>+
>+        for (i = 0; i < len; i++) {
>+
>+            String nodeName = node.item(i).getNodeName();
>+            if (nodeName.equalsIgnoreCase(UtilConstants.NODE)) {
>+                businessObj = processBONode(node.item(i));
>+            }
>+        }
>+        return businessObj;
>+    }
>+
>+    private static SynapseObject processBONode(Node boNode) {
>+
>+        String name = "";
>+        SynapseObject tempObj;
>+        NamedNodeMap namedNodeMap = boNode.getAttributes();
>+        int attributeCount = namedNodeMap.getLength();
>+        for (int counter = 0; counter < attributeCount; counter++) {
>+            Node attribName = namedNodeMap.item(counter);
>+            if (attribName.getNodeName().equals(UtilConstants.NAME_ATTRIB)) {
>+                name = namedNodeMap.getNamedItem(UtilConstants.NAME_ATTRIB).getNodeValue();
>+            }
>+
>+        }
>+        tempObj = new SynapseObject(name);
>+        NodeList nodeList = boNode.getChildNodes();
>+        int len = nodeList.getLength();
>+        int i;
>+
>+        for (i = 0; i < len; i++) {
>+            String nodeName = nodeList.item(i).getNodeName();
>+            if (nodeName.equalsIgnoreCase(UtilConstants.LEAF)) {
>+                try {
>+                    tempObj = processGONode(nodeList.item(i), tempObj);
>+                } catch (Exception e) {
>+                    e.printStackTrace();
>+                }
>+            }
>+            if (nodeName.equalsIgnoreCase(UtilConstants.NODE)) {
>+                SynapseObject bObj = processBONode(nodeList.item(i));
>+                tempObj.addChild(bObj);
>+            }
>+        }
>+        return tempObj;
>+    }
>+
>+    private static SynapseObject processGONode(Node goNode, SynapseObject parent) throws Exception {
>+
>+        String goName = "", goType = "", goValue = "";
>+        NamedNodeMap namedNodeMap = goNode.getAttributes();
>+        int attributeCount = namedNodeMap.getLength();
>+        for (int counter = 0; counter < attributeCount; counter++) {
>+            Node attribName = namedNodeMap.item(counter);
>+            if (attribName.getNodeName().equals(UtilConstants.NAME_ATTRIB)) {
>+                goName = namedNodeMap.getNamedItem(UtilConstants.NAME_ATTRIB).getNodeValue();
>+            } else if (attribName.getNodeName().equals(UtilConstants.TYPE_ATTRIB)) {
>+                goType = namedNodeMap.getNamedItem(UtilConstants.TYPE_ATTRIB).getNodeValue();
>+            }
>+        }
>+        if (goNode.hasChildNodes()) {
>+            if (goNode.getFirstChild().getNodeType() == Node.TEXT_NODE) {
>+                goValue = goNode.getFirstChild().getNodeValue();
>+            }
>+        }
>+        if (goType.equalsIgnoreCase("Boolean")) {
>+            parent.setBoolean(goName, goValue);
>+        } else if (goType.equalsIgnoreCase("Float")) {
>+            parent.setFloat(goName, goValue);
>+        } else if (goType.equalsIgnoreCase("Integer")) {
>+            parent.setInteger(goName, goValue);
>+        } else if (goType.equalsIgnoreCase("Long")) {
>+            parent.setLong(goName, goValue);
>+        } else if (goType.equalsIgnoreCase("String")) {
>+            parent.setString(goName, goValue);
>+        } else {
>+            throw new Exception("TYPE NOT SUPPORTED!");
>+        }
>+        return parent;
>+    }
>+
>+    public static String transform(String xml, String xsl) {
>+        /*String xsl = "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n" +
>+         "<xsl:output method=\"text\" /> \n" +
>+         "<xsl:template match=\"/\">\n" +
>+         "<xsl:apply-templates /> \n" +
>+         "</xsl:template>\n" +
>+         "<xsl:template match=\"student_list\">\n" +
>+         "Student Directory for example.edu \n" +
>+         "<xsl:apply-templates /> \n" +
>+         "</xsl:template>\n" +
>+         "<xsl:template match=\"name\">\n" +
>+         "Name: \n" +
>+         "<xsl:apply-templates /> \n" +
>+         "</xsl:template>\n" +
>+         "<xsl:template match=\"major\">\n" +
>+         "Major: \n" +
>+         "<xsl:apply-templates /> \n" +
>+         "</xsl:template>\n" +
>+         "<xsl:template match=\"phone\">\n" +
>+         "Phone: \n" +
>+         "<xsl:apply-templates /> \n" +
>+         "</xsl:template>\n" +
>+         "<xsl:template match=\"email\">\n" +
>+         "Email: \n" +
>+         "<xsl:apply-templates /> \n" +
>+         "</xsl:template>\n" +
>+         "</xsl:stylesheet>";
>+
>+  String xml = "<student_list>\n" +
>+          "<student>\n" +
>+          "<name>George Washington</name> \n" +
>+          "<major>Politics</major> \n" +
>+          "<phone>312-123-4567</phone> \n" +
>+          "<email>gw@example.edu</email> \n" +
>+          "</student>\n" +
>+          "<student>\n" +
>+          "<name>Janet Jones</name> \n" +
>+          "<major>Undeclared</major> \n" +
>+          "<phone>311-122-2233</phone> \n" +
>+          "<email>janetj@example.edu</email> \n" +
>+          "</student>\n" +
>+          "<student>\n" +
>+          "<name>Joe Taylor</name> \n" +
>+          "<major>Engineering</major> \n" +
>+          "<phone>211-111-2333</phone> \n" +
>+          "<email>joe@example.edu</email> \n" +
>+          "</student>\n" +
>+          "</student_list>";
>+        */
>+        String out_xml = "";
>+        TransformerFactory tFactory = TransformerFactory.newInstance();
>+        try {
>+            Transformer transformer = tFactory.newTransformer(new StreamSource(new StringReader(xsl)));
>+            try {
>+                ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
>+                transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(byteArrayOutput));
>+                out_xml = byteArrayOutput.toString();
>+            } catch (TransformerException e) {
>+                e.printStackTrace();
>+            }
>+        } catch (TransformerConfigurationException e) {
>+            e.printStackTrace();
>+        }
>+        return out_xml;
>+    }
>+
>+    public static SynapseObject transformToSynapseObject(String xml, String xsl){
>+        String BOXml = Utils.transform(xml,xsl);
>+        SynapseObject bObject = Utils.xmlToSynapseObject(BOXml);
>+        return bObject;
>+    }
>+}
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
>For additional commands, e-mail: synapse-dev-help@ws.apache.org
>
>
>  
>
hmmm , I think its better you can rename packege neme to
org.apache.synapse.....  (currntly it is com.infravio.core), since the
project is under apache and having some other packege name will have
problem in the future !!
This is just a sggection , dont take it so serious. :)




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