synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r451999 - in /incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml: EndpointSerializer.java PropertyFactory.java PropertySerializer.java XMLConfigurationSerializer.java
Date Mon, 02 Oct 2006 12:32:00 GMT
Author: asankha
Date: Mon Oct  2 05:31:59 2006
New Revision: 451999

URL: http://svn.apache.org/viewvc?view=rev&rev=451999
Log:
Commiting for Ruwan


Added:
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertyFactory.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertySerializer.java
Modified:
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointSerializer.java
    incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationSerializer.java

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointSerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointSerializer.java?view=diff&rev=451999&r1=451998&r2=451999
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointSerializer.java
(original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/EndpointSerializer.java
Mon Oct  2 05:31:59 2006
@@ -54,10 +54,6 @@
     protected static final OMNamespace synNS = fac.createOMNamespace(Constants.SYNAPSE_NAMESPACE,
"syn");
     protected static final OMNamespace nullNS = fac.createOMNamespace(Constants.NULL_NAMESPACE,
"");
 
-    private static final EndpointSerializer instance = new EndpointSerializer();
-
-    private EndpointSerializer() {}
-
     public static OMElement serializeEndpoint(Endpoint endpt, OMElement parent) {
 
         OMElement endpoint = fac.createOMElement("endpoint", synNS);

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertyFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertyFactory.java?view=auto&rev=451999
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertyFactory.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertyFactory.java
Mon Oct  2 05:31:59 2006
@@ -0,0 +1,102 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.synapse.config.xml;
+
+import org.apache.synapse.config.XMLToObjectMapper;
+import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.config.Property;
+import org.apache.synapse.SynapseException;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMText;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+
+public class PropertyFactory implements XMLToObjectMapper {
+    private static Log log = LogFactory.getLog(PropertyFactory.class);
+
+    private static final PropertyFactory instance = new PropertyFactory();
+
+    private PropertyFactory() {}
+
+    public static Property createProperty(OMElement elem) {
+
+        OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+        if (name == null) {
+            handleException("The 'name' attribute is required for a property definition");
+            return null;
+        } else {
+            Property property = new Property();
+            property.setName(name.getAttributeValue());
+            String value = elem.getAttributeValue(new QName(Constants.NULL_NAMESPACE, "value"));
+            String src = elem.getAttributeValue(new QName(Constants.NULL_NAMESPACE, "src"));
+            String key = elem.getAttributeValue(new QName(Constants.NULL_NAMESPACE, "key"));
+            OMElement content = elem.getFirstElement();
+            if(value != null) {
+                property.setType(Property.VALUE_TYPE);
+                property.setValue(value);
+            } else if(src != null) {
+                property.setType(Property.SRC_TYPE);
+                try {
+                    property.setSrc(new URL(src));
+                } catch (MalformedURLException e) {
+                    handleException("Given src attribute " + src + "is not a propper URL.");
+                }
+            } else if(key != null) {
+                property.setType(Property.DYNAMIC_TYPE);
+                property.setKey(key);
+            } else if(content != null) {
+                if (content instanceof OMText) {
+                    property.setType(Property.INLINE_STRING_TYPE);
+                    property.setValue(content.getText());
+                } else {
+                    property.setType(Property.INLINE_XML_TYPE);
+                    property.setValue(content);
+                }
+            }
+            return property;
+        }
+    }
+
+    private static void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseException(msg);
+    }
+
+    private static void handleException(String msg, Exception e) {
+        log.error(msg, e);
+        throw new SynapseException(msg, e);
+    }
+
+    public Object getObjectFromOMNode(OMNode om) {
+        if (om instanceof OMElement) {
+            return createProperty((OMElement) om);
+        } else {
+            handleException("Invalid XML configuration for an Endpoint. OMElement expected");
+        }
+        return null;
+    }
+
+    public static PropertyFactory getInstance() {
+        return instance;
+    }
+}

Added: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertySerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertySerializer.java?view=auto&rev=451999
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertySerializer.java
(added)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/PropertySerializer.java
Mon Oct  2 05:31:59 2006
@@ -0,0 +1,72 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.synapse.config.xml;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.config.Property;
+import org.apache.synapse.SynapseException;
+
+public class PropertySerializer {
+
+    private static Log log = LogFactory.getLog(PropertySerializer.class);
+
+    protected static final OMFactory fac = OMAbstractFactory.getOMFactory();
+    protected static final OMNamespace synNS = fac.createOMNamespace(
+            Constants.SYNAPSE_NAMESPACE, "syn");
+    protected static final OMNamespace nullNS = fac.createOMNamespace(Constants.NULL_NAMESPACE,
"");
+
+    /**
+     * Serialize the Property object to an OMElement representing the property
+     * @param property
+     * @param parent
+     * @return OMElement representing the property
+     */
+    public static OMElement serializeProperty(Property property, OMElement parent) {
+
+        OMElement propertyElement = fac.createOMElement("set-property", synNS);
+        propertyElement.addAttribute(fac.createOMAttribute(
+                "name", nullNS, property.getName()));
+
+        if (property.getType() == Property.DYNAMIC_TYPE) {
+            propertyElement.addAttribute(fac.createOMAttribute(
+                    "key", nullNS, property.getKey()));
+        } else if (property.getType() == Property.SRC_TYPE) {
+            propertyElement.addAttribute(fac.createOMAttribute(
+                    "src", nullNS, property.getSrc().toString()));
+        } else if (property.getType() == Property.VALUE_TYPE) {
+            propertyElement.addAttribute(fac.createOMAttribute(
+                    "value", nullNS, (String) property.getValue()));
+        } else if (property.getType() == Property.INLINE_XML_TYPE) {
+            propertyElement.addChild((OMElement) property.getValue());
+        } else if (property.getType() == Property.INLINE_STRING_TYPE) {
+            propertyElement.addChild(fac.createOMText((String) property.getValue()));
+        } else {
+            handleException("Property type undefined");
+        }
+        parent.addChild(propertyElement);
+        return propertyElement;
+    }
+
+    private static void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseException(msg);
+    }
+}

Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationSerializer.java?view=diff&rev=451999&r1=451998&r2=451999
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationSerializer.java
(original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/XMLConfigurationSerializer.java
Mon Oct  2 05:31:59 2006
@@ -92,29 +92,8 @@
         Iterator iter = synCfg.getGlobalProps().keySet().iterator();
         while (iter.hasNext()) {
             String propertyName = (String) iter.next();
-            OMElement property = fac.createOMElement("set-property", synNS);
-            property.addAttribute(fac.createOMAttribute(
-                "name", nullNS, propertyName));
-
-            Property prop = synCfg.getPropertyObject(propertyName);
-            if (prop.getType() == Property.DYNAMIC_TYPE) {
-                property.addAttribute(fac.createOMAttribute(
-                        "key", nullNS, prop.getKey()));
-            } else if (prop.getType() == Property.SRC_TYPE) {
-                property.addAttribute(fac.createOMAttribute(
-                        "src", nullNS, prop.getSrc().toString()));
-            } else if (prop.getType() == Property.VALUE_TYPE) {
-                property.addAttribute(fac.createOMAttribute(
-                        "value", nullNS, (String) prop.getValue()));
-            } else if (prop.getType() == Property.INLINE_XML_TYPE) {
-                property.addChild((OMElement) prop.getValue());
-            } else if (prop.getType() == Property.INLINE_STRING_TYPE) {
-                property.addChild(fac.createOMText((String) prop.getValue()));
-            } else {
-                handleException("Property type undefined");
-            }
-
-            definitions.addChild(property);
+            PropertySerializer.serializeProperty(
+                    synCfg.getPropertyObject(propertyName), definitions);
         }
     }
 



---------------------------------------------------------------------
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