You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2010/08/23 19:14:58 UTC

svn commit: r988212 - in /synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config: Entry.java xml/EntryFactory.java xml/EntrySerializer.java

Author: ruwan
Date: Mon Aug 23 17:14:57 2010
New Revision: 988212

URL: http://svn.apache.org/viewvc?rev=988212&view=rev
Log:
Adding the description to the local entries

Modified:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntryFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntrySerializer.java

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java?rev=988212&r1=988211&r2=988212&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java Mon Aug 23 17:14:57 2010
@@ -21,6 +21,7 @@ package org.apache.synapse.config;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseArtifact;
 import org.apache.synapse.SynapseException;
 
 import java.net.URL;
@@ -30,7 +31,7 @@ import java.net.URL;
  *
  * @see org.apache.synapse.config.SynapseConfiguration#localRegistry
  */
-public class Entry {
+public class Entry implements SynapseArtifact {
 
     private static final Log log = LogFactory.getLog(Entry.class);
 
@@ -50,6 +51,8 @@ public class Entry {
     private long expiryTime;
     /** The name of the file where this entry is defined */
     private String fileName;
+    /** The description of the local entry */
+    private String description;
 
     public Entry() {}
     
@@ -155,6 +158,14 @@ public class Entry {
         this.fileName = fileName;
     }
 
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
     public boolean isExpired() {
         return getType() == REMOTE_ENTRY && getExpiryTime() > 0
                 && System.currentTimeMillis() > expiryTime;

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntryFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntryFactory.java?rev=988212&r1=988211&r2=988212&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntryFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntryFactory.java Mon Aug 23 17:14:57 2010
@@ -19,6 +19,7 @@
 
 package org.apache.synapse.config.xml;
 
+import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.config.XMLToObjectMapper;
 import org.apache.synapse.config.Entry;
 import org.apache.synapse.SynapseException;
@@ -40,6 +41,9 @@ public class EntryFactory implements XML
 
     private static Log log = LogFactory.getLog(EntryFactory.class);
 
+    private static final QName DESCRIPTION_Q
+            = new QName(SynapseConstants.SYNAPSE_NAMESPACE, "description");
+
     public static Entry createEntry(OMElement elem) {
 
         OMAttribute key = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
@@ -78,6 +82,12 @@ public class EntryFactory implements XML
                 	entry.setValue(elem.getText());
 				}
             }
+
+            OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
+            if (descriptionElem != null) {
+                entry.setDescription(descriptionElem.getText());
+            }
+
             return entry;
         }
     }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntrySerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntrySerializer.java?rev=988212&r1=988211&r2=988212&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntrySerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/EntrySerializer.java Mon Aug 23 17:14:57 2010
@@ -29,6 +29,8 @@ import org.apache.synapse.config.Entry;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.SynapseConstants;
 import org.apache.axiom.om.impl.llom.OMTextImpl;
+
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamConstants;
 import java.net.URL;
 
@@ -41,7 +43,8 @@ public class EntrySerializer {
 
     protected static final OMFactory fac = OMAbstractFactory.getOMFactory();
     protected static final OMNamespace synNS = SynapseConstants.SYNAPSE_OMNAMESPACE;
-    protected static final OMNamespace nullNS = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
+    protected static final OMNamespace nullNS
+            = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
 
     /**
      * Serialize the Entry object to an OMElement representing the entry
@@ -50,27 +53,27 @@ public class EntrySerializer {
      * @return OMElement representing the entry
      */
     public static OMElement serializeEntry(Entry entry, OMElement parent) {
-        OMElement propertyElement = fac.createOMElement("localEntry", synNS);
-        propertyElement.addAttribute(fac.createOMAttribute(
+        OMElement entryElement = fac.createOMElement("localEntry", synNS);
+        entryElement.addAttribute(fac.createOMAttribute(
                 "key", nullNS, entry.getKey().trim()));
         int type = entry.getType();
         if (type == Entry.URL_SRC) {
             URL srcUrl = entry.getSrc();
             if (srcUrl != null) {
-                propertyElement.addAttribute(fac.createOMAttribute(
+                entryElement.addAttribute(fac.createOMAttribute(
                         "src", nullNS, srcUrl.toString().trim()));
             }
         } else if (type == Entry.INLINE_XML) {
             Object value = entry.getValue();
             if (value != null && value instanceof OMElement) {
-                propertyElement.addChild((OMElement) value);
+                entryElement.addChild((OMElement) value);
             }
         } else if (type == Entry.INLINE_TEXT) {
             Object value = entry.getValue();
             if (value != null && value instanceof String) {
                 OMTextImpl textData = (OMTextImpl) fac.createOMText(((String) value).trim());
                 textData.setType(XMLStreamConstants.CDATA);
-                propertyElement.addChild(textData);
+                entryElement.addChild(textData);
             }
         } else if (type == Entry.REMOTE_ENTRY) {
             // nothing to serialize
@@ -78,10 +81,19 @@ public class EntrySerializer {
         } else {
             handleException("Entry type undefined");
         }
+
+        if (entry.getDescription() != null) {
+
+            OMElement descriptionElem = fac.createOMElement(
+                    new QName(SynapseConstants.SYNAPSE_NAMESPACE, "description"));
+            descriptionElem.setText(entry.getDescription());
+            entryElement.addChild(descriptionElem);
+        }
+
         if (parent != null) {
-            parent.addChild(propertyElement);
+            parent.addChild(entryElement);
         }
-        return propertyElement;
+        return entryElement;
     }
 
     private static void handleException(String msg) {