You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by zo...@apache.org on 2002/08/24 13:33:31 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom DOMImpl.java

zongaro     2002/08/24 04:33:31

  Modified:    java/src/org/apache/xalan/xsltc/dom Tag: XSLTC_DTM
                        DOMImpl.java
  Log:
  Eliminated use of DTDMonitor in building an XSLTC DOM object.  Instead, the
  nested DOMBuilderImpl classes of DOMImpl and SAXImpl now implement the
  DTDHandler and DeclHandler SAX interfaces (and the ExtendedSAX interface now
  extends them).
  
  DTDMonitor was responsible for capturing information from SAX events relating
  to unparsed entities and ID attribute values, and gave that information to the
  translet, where it was ultimately stored.  With this change, DOMImpl and SAXImpl
  are responsible for capturing this information; in the case of ID attribute
  values, the information is again given back to the translet, which treats them
  in the same manner as xsl:key elements.  So the XSLTC DOM interface (and the
  classes that implement it) now add a getUnparsedEntityURI method and a
  getElementsWithID method.
  
  With these changes, we now use DOMImpl to build an XSLTC DOM from a DOMSource
  object, rather than using DOM2SAX to build the XSLTC DOM from SAX events.
  Currently, this requires an extra call to the post-processing method
  createMappings to traverse the DOM, gathering information in the form required
  by the XSLTC DOM interface, which SAXImpl gathers as SAX events are fired.
  
  One additional note - the getElementsWithID method in DOMImpl does not work at
  all, and probably cannot be made to work.  It allows XSLTC to continue using the
  same mechanism for handling the id() function as it did previously, but that
  mechanism never worked in the case of DOMSource input.
  
  Finally, one bug fix:  the NamespaceIterator created in lookupNamespace wasn't
  getting its setStartNode method called to specify the starting point from which
  to look up namespace nodes.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.68.2.4  +196 -48   xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java
  
  Index: DOMImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java,v
  retrieving revision 1.68.2.3
  retrieving revision 1.68.2.4
  diff -u -r1.68.2.3 -r1.68.2.4
  --- DOMImpl.java	29 Jul 2002 00:01:27 -0000	1.68.2.3
  +++ DOMImpl.java	24 Aug 2002 11:33:31 -0000	1.68.2.4
  @@ -123,6 +123,8 @@
       // Node-to-type, type-to-name, and name-to-type mappings
       private int[] _types;
       private String[]  _namesArray;
  +    private Hashtable _names;
  +    private int       _namesCount = 0;
   
       // Tree navigation arrays
       private int[]     _offsetOrChild; // Serves two purposes !!!
  @@ -135,7 +137,9 @@
       private String[]  _uriArray;
       private Hashtable _prefixArray;
       private short[]   _namespace;
  +    private Hashtable _namespaceHash;
       private Hashtable _nsIndex = new Hashtable();
  +    private int       _URICount = 0;
   
       // Tracks which textnodes are whitespaces and which are not
       private BitArray  _whitespace; // takes xml:space into acc.
  @@ -156,13 +160,110 @@
       private final static String XML_LANG_ATTRIBUTE =
   	"http://www.w3.org/XML/1998/namespace:@lang";
   
  +    private static final String XML_PREFIX   = "xml";
  +
  +    /**
  +     * %HZ% %REVISIT% Need javadoc
  +     */
  +    public void createMappings() {
  +        DTMAxisIterator rootIterator = getIterator();
  +        DTMAxisIterator docIter =
  +                 new org.apache.xml.dtm.ref.DTMDefaultBaseIterators
  +                                            .DescendantIterator();
  +        docIter.setStartNode(rootIterator.next());
  +
  +        _names = new Hashtable();
  +        _namespaceHash = new Hashtable();
  +        _prefixArray = new Hashtable();
  +
  +
  +        for (int node = docIter.next();
  +             node != DTM.NULL;
  +             node = docIter.next()) {
  +            if (getNodeType(node) == DTM.ELEMENT_NODE) {
  +                addNodeToMappings(node, false);
  +
  +                for (int anode = getFirstAttribute(node);
  +                     anode != DTM.NULL;
  +                     anode = getNextAttribute(anode)) {
  +                    addNodeToMappings(anode, true);
  +                }
  +            }
  +        }
  +
  +        String [] URIArray = new String[_URICount];
  +        String [] namesArray = new String[_namesCount];
  +        short [] namespace = new short[_namesCount];
  +
  +        Enumeration names = _names.keys();
  +        while (names.hasMoreElements()) {
  +            final String name = (String)names.nextElement();
  +            final Integer Idx = (Integer)_names.get(name);
  +            final String uri = (String)_namespaceHash.get(Idx);
  +            final int idx = Idx.intValue();
  +
  +            namesArray[idx] = name;
  +            if (uri != null) {
  +                final String prefix = (String)_prefixArray.get(uri);
  +                final Integer eType =
  +                             new Integer(getExpandedTypeID(uri, prefix,
  +                                                           DTM.NAMESPACE_NODE));
  +                final short URIIdx = ((Integer)_nsIndex.get(eType))
  +                                                       .shortValue();
  +                namespace[idx] = URIIdx;
  +                URIArray[URIIdx] = uri;
  +            }
  +        }
  +        _namespace = namespace;
  +        _namesArray = namesArray;
  +        _uriArray = URIArray;
  +
  +        _names = null;
  +        _namespaceHash = null;
  +
  +        _types = setupMapping(namesArray);
  +    }
  +
  +
  +    /**
  +     * %HZ% %REVISIT% Need javadoc
  +     */
  +    private void addNodeToMappings(int node, boolean isAttrNode) {
  +        String name = getLocalName(node);
  +        final String prefix = getPrefix(node);
  +        final String uri = getNamespaceName(node);
  +        name = (uri.length() == 0) ? (isAttrNode ? ('@' + name) : name)
  +                                   : (isAttrNode ? (uri + ":@" + name)
  +                                                 : (uri + ':' + name));
  +
  +        final boolean hasNamespace = (uri.length() != 0 &&
  +                                      !prefix.equals(XML_PREFIX));
  +        if (hasNamespace) {
  +            Integer eType = new Integer (getExpandedTypeID(uri, prefix,
  +                                                           DTM.NAMESPACE_NODE));
  +            if ((Integer)_nsIndex.get(eType) == null) {
  +                _prefixArray.put(uri, prefix);
  +                _nsIndex.put(eType, new Integer(_URICount++));
  +            }
  +        }
  +
  +        if (_names.get(name) == null) {
  +            final Integer nameIdx = new Integer(_namesCount++);
  +            _names.put(name, nameIdx);
  +
  +            if (hasNamespace) {
  +                _namespaceHash.put(nameIdx, uri);
  +            }
  +        }
  +    }
  +
       /**
        * Define the origin of the document from which the tree was built
        */
       public void setDocumentURI(String uri) 
       {
  -      setDocumentBaseURI(uri);
  -	    _documentURI = uri;
  +        setDocumentBaseURI(uri);
  +        _documentURI = uri;
       }
   
       /**
  @@ -202,9 +303,12 @@
   
   	ancestors.setStartNode(node);
   	while ((anode = ancestors.next()) != DTM.NULL) {
  -	    final org.apache.xml.dtm.ref.DTMDefaultBaseIterators.NamespaceIterator namespaces = 
  -                new org.apache.xml.dtm.ref.DTMDefaultBaseIterators.NamespaceIterator();
  +            final org.apache.xml.dtm.ref.DTMDefaultBaseIterators
  +                     .NamespaceIterator namespaces =
  +                             new org.apache.xml.dtm.ref.DTMDefaultBaseIterators
  +                                                       .NamespaceIterator();
   
  +            namespaces.setStartNode(anode);
   	    while ((nsnode = namespaces.next()) != DTM.NULL) {
   		if (getPrefix(nsnode).equals(prefix)) {
   		    return getNodeValue(nsnode);
  @@ -924,29 +1028,27 @@
        * Get mapping from DOM element/attribute types to external types
        */
       public short[] getMapping(String[] names) {
  -      int i;
  -      final int namesLength = names.length;
  -      final int mappingLength = _namesArray.length + NTYPES;
  -      final int exLength = m_expandedNameTable.getSize();
  -      final short[] result = new short[exLength];
  -
  -      // primitive types map to themselves
  -      for (i = 0; i < DTM.NTYPES; i++)
  -        result[i] = (short)i;
  +        int i;
  +        final int namesLength = names.length;
  +        final int exLength = m_expandedNameTable.getSize();
  +        final short[] result = new short[exLength];
  +
  +        // primitive types map to themselves
  +        for (i = 0; i < DTM.NTYPES; i++)
  +            result[i] = (short)i;
           
  -      for (i = NTYPES; i < exLength; i++) 
  -      	result[i] = m_expandedNameTable.getType(i); 
  +        for (i = NTYPES; i < exLength; i++) 
  +            result[i] = m_expandedNameTable.getType(i); 
         	
  -      // actual mapping of caller requested names
  -      for (i = 0; i < namesLength; i++) {
  -          int genType = getGeneralizedType(names[i]);
  -          if (genType < _types.length && genType == _types[genType])
  -          {
  -          result[genType] = (short)(i + DTM.NTYPES);
  -          }
  -      }
  +        // actual mapping of caller requested names
  +        for (i = 0; i < namesLength; i++) {
  +            int genType = getGeneralizedType(names[i]);
  +            if (genType < _types.length && genType == _types[genType]) {
  +                result[genType] = (short)(i + DTM.NTYPES);
  +            }
  +        }
   
  -      return result;
  +        return result;
       }
   
       /**
  @@ -1091,33 +1193,53 @@
       }
   
       /**
  -     * Constructor - defaults to 32K nodes
  +     * Construct a DOMImpl object from a DOM node.
  +     *
  +     * @param mgr The DTMManager who owns this DTM.
  +     * @param domSource the DOM source that this DTM will wrap.
  +     * @param dtmIdentity The DTM identity ID for this DTM.
  +     * @param whiteSpaceFilter The white space filter for this DTM, which may
  +     *                         be null.
  +     * @param xstringFactory XMLString factory for creating character content.
  +     * @param doIndexing true if the caller considers it worth it to use
  +     *                   indexing schemes.
        */
  -    
       public DOMImpl(DTMManager mgr, DOMSource domSource, 
  -                 int dtmIdentity, DTMWSFilter whiteSpaceFilter,
  -                 XMLStringFactory xstringfactory,
  -                 boolean doIndexing)
  -    {
  -      super(mgr, domSource, 
  -                 dtmIdentity, whiteSpaceFilter,
  -                 xstringfactory,
  -                 doIndexing);
  -      initSize(8*1024);
  +                   int dtmIdentity, DTMWSFilter whiteSpaceFilter,
  +                   XMLStringFactory xstringfactory,
  +                   boolean doIndexing)
  +    {
  +        super(mgr, domSource, dtmIdentity, whiteSpaceFilter, xstringfactory,
  +              doIndexing);
  +        initSize(8*1024);
       }
       
  +    /**
  +     * Construct a DOMImpl object from a DOM node.
  +     *
  +     * @param mgr The DTMManager who owns this DTM.
  +     * @param domSource the DOM source that this DTM will wrap.
  +     * @param dtmIdentity The DTM identity ID for this DTM.
  +     * @param whiteSpaceFilter The white space filter for this DTM, which may
  +     *                         be null.
  +     * @param xstringFactory XMLString factory for creating character content.
  +     * @param doIndexing true if the caller considers it worth it to use
  +     *                   indexing schemes.
  +     * @param size The number of nodes required for the tree.
  +     */
       public DOMImpl(DTMManager mgr, DOMSource domSource, 
                    int dtmIdentity, DTMWSFilter whiteSpaceFilter,
                    XMLStringFactory xstringfactory,
                    boolean doIndexing, int size)
       {
  -      super(mgr, domSource, 
  -                 dtmIdentity, whiteSpaceFilter,
  -                 xstringfactory,
  -                 doIndexing);
  -      initSize(size);
  +        super(mgr, domSource, dtmIdentity, whiteSpaceFilter, xstringfactory,
  +              doIndexing);
  +        initSize(size);
       }
       
  +    /**
  +     * Constructor - defaults to 32K nodes
  +     */
     /*  public DOMImpl() 
       {
         //this(32*1024);
  @@ -1129,15 +1251,10 @@
        */
       public void initSize(int size) 
       {
  -      //_type          = new short[size];
  -      //_parent        = new int[size];
  -      //_nextSibling   = new int[size];
         _offsetOrChild = new int[size];
         _lengthOrAttr  = new int[size];
         _text          = new char[size * 10];
         _whitespace    = new BitArray(size);
  -    //  _prefix        = new short[size];
  -      // _namesArray[] and _uriArray[] are allocated in endDocument
       }
   
       /**
  @@ -1836,7 +1953,8 @@
        */
       public DOMBuilder getBuilder() 
       {
  -	return new DOMBuilderImpl();
  +       //return new DOMBuilderImpl();
  +       return null;
       }
   
       /**
  @@ -1848,7 +1966,8 @@
       {
         //DOMBuilder builder = getBuilder();
        // return new SAXAdapter(builder, builder);
  -      return new SAXAdapter(new DOMBuilderImpl());
  +     // %HZ% %REVISIT%:  return new SAXAdapter(new DOMBuilderImpl());
  +      return null;
       }
       
       /**
  @@ -1861,6 +1980,13 @@
       }
   
       /**
  +     * %HZ% Need Javadoc
  +     */
  +    public Hashtable getElementsWithIDs() {
  +        return null;
  +    }
  +
  +    /**
        * Returns true if a character is an XML whitespace character.
        * Order of tests is important for performance ([space] first).
        */
  @@ -2493,6 +2619,28 @@
   	public void endDTD() {}
   	public void startEntity(String name) {}
   	public void endEntity(String name) {}
  +        public void notationDecl(String name, String publicId,
  +                                 String systemId) {}
  +
  +
  +        // %HZ%:  Need Javadoc
  +        public void unparsedEntityDecl(String name, String publicId,
  +                                       String systemId, String notationName) {}
  +
  +        // %HZ%:  Need Javadoc
  +        public void elementDecl(String name, String model) {}
  +
  +        // %HZ%:  Need Javadoc
  +        public void attributeDecl(String eName, String aName, String type,
  +                                  String valueDefault, String value) {}
  +
  +        // %HZ%:  Need Javadoc
  +        public void externalEntityDecl(String name, String publicId,
  +                                       String systemId) {}
  +
  +        // %HZ%:  Need Javadoc
  +        public void internalEntityDecl(String name, String value) {}
  +
   
   	/**
   	 * Similar to the SAX2 method character(char[], int, int), but this
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org