Diff for /java/classes/org/w3c/rdf/Element.java between versions 1.6 and 1.7

version 1.6, 1998/08/28 10:03:15 version 1.7, 1998/09/08 15:54:01
Line 3 Line 3
  * and children.   * and children.
  *   *
  * $Log$   * $Log$
    * Revision 1.7  1998/09/08 15:54:01  jsaarela
    * Distribution release V1.4 - aboutEachPrefix added, namespace management
    * improved.
    *
  * Revision 1.6  1998/08/28 10:03:15  jsaarela   * Revision 1.6  1998/08/28 10:03:15  jsaarela
  * Distribution release 1.3 on 28-Aug-98.   * Distribution release 1.3 on 28-Aug-98.
  *   *
Line 29  import org.xml.sax.SAXException; Line 33  import org.xml.sax.SAXException;
   
 public class Element  public class Element
 {  {
   private String        m_sNamespace = null;      private String      m_sName = null;
   private String        m_sName = null;      private Hashtable   m_attributes = new Hashtable();
   private Hashtable     m_attributes = new Hashtable();      private Vector      m_children = new Vector();
   private Hashtable     m_attributeNamespaces = new Hashtable();      private String      m_sID = null;
   private Vector        m_children = new Vector();      private String      m_sBagID = null;
   private String        m_sID = null;      private Hashtable   m_nodes = new Hashtable ();
   private String        m_sBagID = null;      private Vector      m_vTargets = new Vector ();
   private Hashtable     m_nodes = new Hashtable ();      private boolean     m_bDone = false;
   private Element       m_target = null;  
   private boolean       m_bDone = false;      public Element (String sName, AttributeList al) throws SAXException {
           m_sName = sName;
   private static Vector s_resolveQueue = new Vector ();  
   private static Hashtable s_hIDtable = new Hashtable ();          if (al != null) {
               int iLength = al.getLength ();
   private static int    s_iReificationCounter = 0;              if (al == null) {
                   // System.out.println("[Attributes not available]");
   public static void init () {              } else {
         s_iReificationCounter = 0;                  for (int x = 0; x < iLength; x++) {
         s_resolveQueue.removeAllElements ();                      String aName = al.getName (x);
         s_hIDtable.clear ();                      String aValue = al.getValue (x);
   }  
                       m_attributes.put (aName, aValue);
   public Element (String sNamespace,                  }
                   String sName,              }
                   AttributeList al) throws SAXException {  
     m_sNamespace = sNamespace;  
     m_sName = sName;  
   
     if (al != null) {  
         int iLength = al.getLength ();  
       if (al == null) {  
           // System.out.println("[Attributes not available]");  
       } else {  
         for (int x = 0; x < iLength; x++) {  
           String aName = al.getName (x);  
           String aValue = al.getValue (x);  
           String aNamespace = al.getType (x);  
   
           m_attributes.put (aName, aValue);  
           m_attributeNamespaces.put (aName, aNamespace);  
         }          }
       }  
     }      }
   
     if (m_attributes != null) {      public String name() {
       String sResource = (String)m_attributes.get ("resource");  
       if (sResource != null && sResource.startsWith("#")) {  
           Element.resolveLater (this);  
       }  
       String sAboutEach = (String)m_attributes.get ("aboutEach");  
       if (sAboutEach != null && sAboutEach.startsWith("#")) {  
           Element.resolveLater (this);  
       }  
       String sAbout = (String)m_attributes.get ("about");  
       if (sAbout != null) {  
           if (sAbout.startsWith("#")) {  
               Element.resolveLater (this);  
           } else {  
               Element.registerResource (this);  
           }  
       }  
       String sBagID = (String)m_attributes.get ("bagID");  
       if (sBagID != null) {  
         Element.registerBag (this);  
         bagID (sBagID);  
       }  
       String sId = (String)m_attributes.get ("ID");  
       if (sId != null) {  
         Element.registerID (this);  
         ID (sId); // default value  
       }  
   
       if (sId != null && sAbout != null) {  
           throw new SAXException ("'ID' and 'about' attribute may not appear within the same Description block");  
       }  
     }  
   }  
   
   public String name() {  
     return m_sName;  
   }  
   
   public String namespace () {  
     return m_sNamespace;  
   }  
   
   public void addChild (Element e) {  
     m_children.addElement (e);  
   }  
   
   public Enumeration children () {  
     return m_children.elements();  
   }  
   
   public Enumeration attributes () {  
       return m_attributes.keys();  
   }  
   
   public void addAttribute (String sName, String sValue) {  
       if (sName == null ||  
           sValue == null)  
           return;  
       if (m_attributes == null) {  
           m_attributes = new Hashtable ();  
       }  
       m_attributes.put (sName, sValue);  
   }  
   
   public void removeAttribute (String sName) {  
       m_attributes.remove (sName);  
   }  
   
   public String getAttribute (String sName) {  
     return (String)m_attributes.get (sName);  
   }  
   
   public String getAttributeNamespace (String sName) {  
     return (String)m_attributeNamespaces.get (sName);  
   }  
   
   public String expandName () {  
     if (m_sNamespace == null ||  
         m_sNamespace.trim().length() == 0) {  
         return m_sName;          return m_sName;
     } else {  
         return m_sNamespace + m_sName;  
     }      }
   }  
   
   public static void resolveLater (Element e) {      public void addChild (Element e) {
     s_resolveQueue.addElement (e);          m_children.addElement (e);
   }  
   
   public static void resolve () {  
     for (int x = 0; x < s_resolveQueue.size(); x++) {  
       Element e = (Element)s_resolveQueue.elementAt(x);  
   
       String sAbout = e.getAttribute ("about");  
       if (sAbout != null) {  
           if (sAbout.startsWith ("#"))  
               sAbout = sAbout.substring (1);  
           Element e2 = (Element)lookforNode(sAbout);  
           if (e2 != null) {  
               e.setTarget (e2);  
           }       
       }  
   
       String sResource = e.getAttribute ("resource");  
       if (sResource != null) {  
           if (sResource.startsWith ("#"))  
               sResource = sResource.substring (1);  
           Element e2 = (Element)lookforNode(sResource);  
           if (e2 != null) {  
               e.setTarget (e2);  
           }       
       }  
   
       String sAboutEach = e.getAttribute ("aboutEach");  
       if (sAboutEach != null) {  
           sAboutEach = sAboutEach.substring (1);  
           Element e2 = (Element)lookforNode(sAboutEach);  
           if (e2 != null) {  
               e.setTarget (e2);  
           }       
       }  
     }  
     s_resolveQueue.removeAllElements();  
   }  
   
   public static Element lookforNode (String sID) {  
       if (sID == null)  
           return null;  
       else  
           return (Element)s_hIDtable.get (sID);  
   }  
   
   public static void registerID (Element e) throws SAXException {  
     if (e.getAttribute ("ID") != null) {  
         if (s_hIDtable.get (e.getAttribute ("ID")) != null)  
             throw new SAXException ("ID attribute value '"+e.getAttribute("ID")+"' not unique");  
         else  
             s_hIDtable.put (e.getAttribute("ID"), e);  
     }      }
   }  
   
   public static void registerBag (Element e) {      public Enumeration children () {
     if (e.getAttribute ("bagID") != null) {          return m_children.elements();
       s_hIDtable.put (e.getAttribute ("bagID"), e);  
     }      }
   }  
   
   public static void registerResource (Element e) {      public Enumeration attributes () {
     if (e.getAttribute ("about") != null) {          return m_attributes.keys();
       s_hIDtable.put (e.getAttribute ("about"), e);  
     }      }
   }  
   
       public void addAttribute (String sName, String sValue) {
           if (sName == null ||
               sValue == null)
               return;
           m_attributes.put (sName, sValue);
       }
   
   public void setTarget (Element e) {      public void removeAttribute (String sName) {
     m_target = e;          m_attributes.remove (sName);
   }      }
   
   public Element target () {      public String getAttribute (String sName) {
     return m_target;          return (String)m_attributes.get (sName);
   }      }
   
   static public String newReificationID () {      public String getAttribute (String sNamespace, String sName) {
     s_iReificationCounter++;          return (String)m_attributes.get (sNamespace+sName);
     return  new String ("genid" + s_iReificationCounter);      }
   }  
   
   public void ID (String sID) {      public void addTarget (Element e) {
     m_sID = sID;          m_vTargets.addElement (e);
   }      }
   
   public String ID () {      public Enumeration targets () {
     return m_sID;          return m_vTargets.elements();
   }      }
   
   public void bagID (String sBagID) {      public Element target () {
     m_sBagID = sBagID;          if (m_vTargets.size() == 0)
   }              return null;
           else
               return (Element)m_vTargets.elementAt(0);
       }
   
   public String bagID () {      public void ID (String sID) {
     return m_sBagID;          m_sID = sID;
   }      }
   
       public String ID () {
           return m_sID;
       }
   
       public void bagID (String sBagID) {
           m_sBagID = sBagID;
       }
   
   public void linearize (int indent, PrintStream ps) {      public String bagID () {
     for (int x = 0; x < indent; x++) {          return m_sBagID;
       ps.print (" ");  
     }      }
     System.out.println ("Element "+name());  
     Enumeration e = children();      public void linearize (int indent, PrintStream ps) {
     while (e.hasMoreElements()) {          for (int x = 0; x < indent; x++) {
       Element ele = (Element)e.nextElement();              ps.print (" ");
       ele.linearize (indent + 2, ps);          }
           System.out.println ("Element "+name());
           Enumeration e = children();
           while (e.hasMoreElements()) {
               Element ele = (Element)e.nextElement();
               ele.linearize (indent + 2, ps);
           }
     }      }
   }  
   
   public boolean done () {      public boolean done () {
       return m_bDone;          return m_bDone;
   }      }
   
   public void done (boolean b) {      public void done (boolean b) {
       m_bDone = b;          m_bDone = b;
   }      }
 }  }

Removed from v.1.6  
changed lines
  Added in v.1.7


Webmaster