synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject svn commit: r388076 - in /incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject: Sample.java SynapseObject.java Utils.java
Date Thu, 23 Mar 2006 07:19:55 GMT
Author: vikas
Date: Wed Mar 22 23:19:53 2006
New Revision: 388076

URL: http://svn.apache.org/viewcvs?rev=388076&view=rev
Log:
Updated to handle the xml format suggested on the mailing list...

Modified:
    incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Sample.java
    incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/SynapseObject.java
    incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Utils.java

Modified: incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Sample.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Sample.java?rev=388076&r1=388075&r2=388076&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Sample.java
(original)
+++ incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Sample.java
Wed Mar 22 23:19:53 2006
@@ -8,19 +8,30 @@
     }
 
     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);
+
+        String sla = "<Consumer_Identification>\n" +
+                " <Consumer>\n" +
+                "   <CONSUMER_TYPE type=\"xsd:String\">GOLD</CONSUMER_TYPE>\n"
+
+                "   <IP_ADDRESS_FROM type=\"xsd:String\">192.167.6.0</IP_ADDRESS_FROM>\n"
+
+                "   <IP_ADDRESS_TO type=\"xsd:String\">192.168.6.255</IP_ADDRESS_TO>\n"
+
+                "   <HTTP_AUTH_USERNAME type=\"xsd:String\">john</HTTP_AUTH_USERNAME>\n"
+
+                "   <WS_SEC_USERNAME type=\"xsd:String\">john</WS_SEC_USERNAME>\n"
+
+                "   <Assigned_Service>\n" +
+                "    <Service_ID type=\"xsd:String\">stockQuote1</Service_ID>\n"
+
+                "   </Assigned_Service>\n" +
+                " </Consumer>\n" +
+                " <Consumer>\n" +
+                "   <CONSUMER_TYPE type=\"xsd:String\">SILVER</CONSUMER_TYPE>\n"
+
+                "   <IP_ADDRESS_FROM type=\"xsd:String\">192.168.6.255</IP_ADDRESS_FROM>\n"
+
+                "   <IP_ADDRESS_TO type=\"xsd:String\">192.168.6.255</IP_ADDRESS_TO>\n"
+
+                "   <HTTP_AUTH_USERNAME type=\"xsd:String\">mary</HTTP_AUTH_USERNAME>\n"
+
+                "   <WS_SEC_USERNAME type=\"xsd:String\">mary</WS_SEC_USERNAME>\n"
+
+                "   <Assigned_Service>\n" +
+                "    <Service_ID type=\"xsd:String\">stockQuote1</Service_ID>\n"
+
+                "   </Assigned_Service>\n" +
+                " </Consumer>\n" +
+                "</Consumer_Identification>";
+        SynapseObject slaConfig = Utils.xmlToSynapseObject(sla);
         //String xsl = "XSL";
         //String xml = slaConfig.translate(xsl);
         //System.out.println("XML****\n" + xml);

Modified: incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/SynapseObject.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/SynapseObject.java?rev=388076&r1=388075&r2=388076&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/SynapseObject.java
(original)
+++ incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/SynapseObject.java
Wed Mar 22 23:19:53 2006
@@ -165,21 +165,19 @@
    */
     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.getSynapseObjectName() + "\">\n";
+        xmlFrag = xmlFrag + "<" + bo.getSynapseObjectName() + ">\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";
+        xmlFrag += "</" + bo.getSynapseObjectName()+">\n";
         return xmlFrag;
     }
     private String getAttributes(SynapseObject bo, String xmlReturn) {
@@ -190,7 +188,7 @@
             String name = go.getName();
             String type = go.getType();
             String value = go.getValue();
-            xmlReturn += "<attribute name=\"" + name + "\" " + "type=\"" + type + "\">"
+ value + "</attribute>\n";
+            xmlReturn += "<" + name + " type=\"" + type + "\">" + value + "</" +
name + ">\n";
         }
         return xmlReturn;
     }

Modified: incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Utils.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Utils.java?rev=388076&r1=388075&r2=388076&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Utils.java
(original)
+++ incubator/synapse/trunk/scratch/infravio/Mediators-SynapseObject/org/apache/synapse/synapseobject/Utils.java
Wed Mar 22 23:19:53 2006
@@ -65,46 +65,67 @@
 
         for (i = 0; i < len; i++) {
 
-            String nodeName = node.item(i).getNodeName();
-            if (nodeName.equalsIgnoreCase(UtilConstants.NODE)) {
+            if (isObjectNode(node.item(i))) {
                 businessObj = processBONode(node.item(i));
             }
         }
         return businessObj;
     }
 
+    private static boolean isObjectNode(Node node) {
+
+        if(node.hasAttributes()){
+            NamedNodeMap attributes = node.getAttributes();
+            int attribCount = attributes.getLength();
+            int index;
+            for(index=0; index<attribCount;index++){
+                if(attributes.item(index).getNodeName().equals("type")){
+                    return false;
+                }
+            }
+
+        }
+        if(!(node.getNodeType()==Node.ELEMENT_NODE))
+            return false;
+
+        return true;
+    }
+
     private static SynapseObject processBONode(Node boNode) {
 
         String name = "";
         SynapseObject tempObj;
-        NamedNodeMap namedNodeMap = boNode.getAttributes();
+        name = boNode.getNodeName();
+    /*    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();
+            if (!isObjectNode(attribName)) {
+                name = attribName.getNodeName();
             }
 
         }
+    */
         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)) {
+            if(nodeList.item(i).getNodeType() == Node.ELEMENT_NODE){
+            if(isObjectNode(nodeList.item(i))) {
+                SynapseObject bObj = processBONode(nodeList.item(i));
+                tempObj.addChild(bObj);
+            }
+            else if (!isObjectNode(nodeList.item(i))) {
                 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;
     }
 
@@ -113,11 +134,10 @@
         String goName = "", goType = "", goValue = "";
         NamedNodeMap namedNodeMap = goNode.getAttributes();
         int attributeCount = namedNodeMap.getLength();
+        goName = goNode.getNodeName();
         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)) {
+            if (attribName.getNodeName().equals(UtilConstants.TYPE_ATTRIB)) {
                 goType = namedNodeMap.getNamedItem(UtilConstants.TYPE_ATTRIB).getNodeValue();
             }
         }
@@ -126,6 +146,7 @@
                 goValue = goNode.getFirstChild().getNodeValue();
             }
         }
+        goType = "String";
         if (goType.equalsIgnoreCase("Boolean")) {
             parent.setBoolean(goName, goValue.toLowerCase());
         } else if (goType.equalsIgnoreCase("Float")) {



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


Mime
View raw message