[jboss-cvs] JBossCache/src/org/jboss/cache/factories ...

Brian Stansberry brian.stansberry at jboss.com
Thu Nov 9 23:39:21 EST 2006


  User: bstansberry
  Date: 06/11/09 23:39:21

  Modified:    src/org/jboss/cache/factories  XmlConfigurationParser.java
  Log:
  Do the JGroups ClusterConfig parsing in XmlConfigurationParser
  
  Revision  Changes    Path
  1.6       +56 -1     JBossCache/src/org/jboss/cache/factories/XmlConfigurationParser.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: XmlConfigurationParser.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/XmlConfigurationParser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- XmlConfigurationParser.java	10 Nov 2006 02:48:46 -0000	1.5
  +++ XmlConfigurationParser.java	10 Nov 2006 04:39:21 -0000	1.6
  @@ -35,7 +35,9 @@
   import org.jboss.cache.eviction.EvictionPolicyConfig;
   import org.jboss.cache.util.Util;
   import org.jboss.cache.xml.XmlHelper;
  +import org.w3c.dom.Attr;
   import org.w3c.dom.Element;
  +import org.w3c.dom.NamedNodeMap;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
   
  @@ -208,7 +210,8 @@
             }
             else if ("ClusterConfig".equals(propname))
             {
  -             conf.setClusterConfig((Element) entry.getValue());
  +             String jgc = parseClusterConfigXml((Element) entry.getValue());
  +             conf.setClusterConfig(jgc);
             }
             else
             {
  @@ -464,6 +467,58 @@
          target.validate();
       }
       
  +    /**
  +     * Parses the cluster config which is used to start a JGroups channel
  +     *
  +     * @param config an old-style JGroups protocol config String
  +     */
  +   public static String parseClusterConfigXml(Element config)
  +   {
  +      StringBuffer buffer = new StringBuffer();
  +      NodeList stack = config.getChildNodes();
  +      int length = stack.getLength();
  +
  +      for (int s = 0; s < length; s++)
  +      {
  +         org.w3c.dom.Node node = stack.item(s);
  +         if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
  +         {
  +            continue;
  +         }
  +
  +         Element tag = (Element) node;
  +         String protocol = tag.getTagName();
  +         buffer.append(protocol);
  +         NamedNodeMap attrs = tag.getAttributes();
  +         int attrLength = attrs.getLength();
  +         if (attrLength > 0)
  +         {
  +            buffer.append('(');
  +         }
  +         for (int a = 0; a < attrLength; a++)
  +         {
  +            Attr attr = (Attr) attrs.item(a);
  +            String name = attr.getName();
  +            String value = attr.getValue();
  +            buffer.append(name);
  +            buffer.append('=');
  +            buffer.append(value);
  +            if (a < attrLength - 1)
  +            {
  +               buffer.append(';');
  +            }
  +         }
  +         if (attrLength > 0)
  +         {
  +            buffer.append(')');
  +         }
  +         buffer.append(':');
  +      }
  +      // Remove the trailing ':'
  +      buffer.setLength(buffer.length() - 1);
  +      return buffer.toString();
  +   }
  +    
       private static ParsedAttributes extractAttributes(Element source)
       {
          Map<String, String> stringAttribs = new HashMap<String, String>();
  
  
  



More information about the jboss-cvs-commits mailing list