User: hiram   
  Date: 00/12/27 09:02:24

  Modified:    src/java/org/spydermq/xml XElement.java
  Log:
  Feature Add: Durable Topic Subscriptions now work!
  More work still has to be done with user managment (who
  is allowed to create durable subscriptions).  The DurableSubscriptionExample
  class now works.
  
  Revision  Changes    Path
  1.3       +89 -61    spyderMQ/src/java/org/spydermq/xml/XElement.java
  
  Index: XElement.java
  ===================================================================
  RCS file: /products/cvs/ejboss/spyderMQ/src/java/org/spydermq/xml/XElement.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XElement.java     2000/12/23 15:48:27     1.2
  +++ XElement.java     2000/12/27 17:02:24     1.3
  @@ -59,7 +59,7 @@
    *
    *   @author Hiram Chirino ([EMAIL PROTECTED])
    *
  - *   @version $Revision: 1.2 $
  + *   @version $Revision: 1.3 $
    */
   public class XElement {
        
  @@ -342,7 +342,7 @@
                if( names[0] == null ) {
                        for (int i = 1; i < contents.size(); i++) {
                                XElement o = (XElement) contents.elementAt(i);
  -                             if (relativeName.equals(o.getName())) {
  +                             if (names[1].equals(o.getName())) {
                                        return o;
                                }
                        }
  @@ -357,7 +357,7 @@
                        } else {                        
                                for (int i = 1; i < contents.size(); i++) {
                                        XElement o = (XElement) contents.elementAt(i);
  -                                     if (relativeName.equals(o.getName())) {
  +                                     if (names[0].equals(o.getName())) {
                                                return o.getElement(names[1]);
                                        }
                                }
  @@ -368,36 +368,7 @@
                throw new XElementException("Invalid name ("+getName()+ " does not 
contain the name) : " + relativeName);
        }
   
  -     /**
  -      * Returns all the contained objects with the specified name.
  -      *
  -      * @param relativeName The name of the objects
  -      * @returns whose name is relativeName;
  -      */
  -     public Iterator getElementsNamed(String relativeName) {
  -
  -             Vector t = new Vector();
  -             
  -             if (relativeName != null) {
  -                     String split[] = splitBack(relativeName, "/");
  -                     if( split != null ) {
  -                             try {
  -                                     return 
getElement(split[0]).getElementsNamed(split[1]);
  -                             } catch (XElementException e) {
  -                                     return t.iterator(); // return an empty 
enumeration
  -                             }
  -                     }               
  -             }
  -
  -             for (int i = 1; i < contents.size(); i++) {
  -                     XElement o = (XElement) contents.elementAt(i);
  -                     if (relativeName == null || relativeName.equals(o.getName())) {
  -                             t.addElement(o);
  -                     }
  -             }
   
  -             return t.iterator();
  -     }
   
        /**
         * Gets the value of a contained attribute object.
  @@ -420,12 +391,7 @@
                return contents.size() == 1;
        }
   
  -     /**
  -      * @returns an Enumeration of all the XElement conatained within this object.
  -      */
  -     public Iterator iterator() {
  -             return getElementsNamed(null);
  -     }
  +
   
        /**
         * Sets/Adds a attribute
  @@ -437,31 +403,8 @@
        }
        
        
  -     static private String[] splitBack(String string, String splitMarker) {
  -             
  -             if (string == null || splitMarker==null )
  -                     throw new NullPointerException();
  -                     
  -             String front;
  -             String back;
  -             
  -             int pos = string.lastIndexOf(splitMarker);
  -             if (pos == -1) 
  -                     return null;
  -
  -             int l = splitMarker.length();
  -             front = string.substring(0, pos);
  -             if ( pos+l >= string.length() ) {
  -                     back = "";
  -             } else {
  -                     back = string.substring(pos+l);
  -             }
  -
  -             String rc[] = { front, back };
  -             return rc;
  -             
  -     }       
        
  +     
        static private String[] splitFront(String string, String splitMarker) {
                
                if (string == null || splitMarker==null )
  @@ -635,5 +578,90 @@
                        
                parent.contents.remove(this);
                parent = null;
  +     }
  +
  +     /**
  +      * adds all the contains elements to the vector that match the relative name.
  +      */
  +     private void addElementsToVector(Vector t, String relativeName) {
  +             
  +             String names[] = {null, relativeName};
  +
  +             // Does the name have a "/" in it?
  +             String split[] = splitFront(relativeName, "/");
  +             if( split != null ) {
  +
  +                     // was it an absolute name? (started with a '/')
  +                     if( split[0].length() == 0 ) {
  +                             // we are the parent
  +                             if( parent == null ) {
  +                                     split[0] = null;
  +                             } else { // Let my parent handle the request.
  +                                     parent.addElementsToVector(t, relativeName);
  +                                     return;
  +                             }
  +                     }
  +
  +                     // did we have a trailing / in the name?
  +                     if( split[1].length() == 0 ) {
  +                             return;
  +                     }                       
  +                     names = split;                  
  +             }
  +
  +
  +             if( names[0] == null ) {
  +                     if( names[1].equals("*") ) {
  +                             for (int i = 1; i < contents.size(); i++) {
  +                                     t.addElement(contents.elementAt(i));
  +                             }
  +                     } else {
  +                             for (int i = 1; i < contents.size(); i++) {
  +                                     XElement o = (XElement) contents.elementAt(i); 
  +                                     if (names[1].equals(o.getName())) {
  +                                             t.addElement(o);
  +                                     }
  +                             }
  +                     }
  +             } else {
  +                     if( names[0].equals(".") ) {
  +                             addElementsToVector(t, names[1]);
  +                             return;
  +                     } else if( names[0].equals("..") ) {
  +                             if( parent != null ) {
  +                                     parent.addElementsToVector(t, names[1]);
  +                             }
  +                             return;
  +                     } else {                        
  +                             for (int i = 1; i < contents.size(); i++) {
  +                                     XElement o = (XElement) contents.elementAt(i);
  +                                     if (names[0].equals(o.getName())) {
  +                                             o.addElementsToVector(t, names[1]);
  +                                     }
  +                                     return;
  +                             }
  +                     }
  +             }
  +     }
  +
  +     /**
  +      * @returns an Enumeration of all the XElement conatained within this object.
  +      */
  +     public Enumeration elements() {
  +             return getElementsNamed("*");
  +     }
  +
  +     /**
  +      * Returns all the contained objects with the specified name.
  +      *
  +      * @param relativeName The name of the objects
  +      * @returns whose name is relativeName;
  +      */
  +     public java.util.Enumeration getElementsNamed(String relativeName) {
  +
  +             Vector t = new Vector();
  +             addElementsToVector(t, relativeName);
  +             return t.elements();
  +             
        }
   }
  
  
  

Reply via email to