johng       01/07/15 12:30:58

  Modified:    java/src/org/apache/xalan/lib/sql SQLDocument.java
  Log:
  Project Update
  Submitted by: John gentilin mailto://[EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.3       +575 -244  
xml-xalan/java/src/org/apache/xalan/lib/sql/SQLDocument.java
  
  Index: SQLDocument.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/SQLDocument.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SQLDocument.java  2001/07/12 20:02:44     1.2
  +++ SQLDocument.java  2001/07/15 19:30:57     1.3
  @@ -89,18 +89,17 @@
   import java.sql.SQLException;
   import org.w3c.dom.Node;
   
  +import java.io.IOException;
  +import java.io.File;
  +import java.io.PrintStream;
  +import java.io.FileOutputStream;
  +
   /**
    * The SQL Document is the main controlling class the executesa SQL Query
    */
   public class SQLDocument extends DTMDefaultBaseIterators
   {
  -  private boolean DEBUG = true;
  -  /**
  -   *
  -   */
  -  private Connection  m_Connection = null;
  -  private Statement   m_Statement = null;
  -  private ResultSet   m_ResultSet = null;
  +  private boolean DEBUG = false;
   
     private static final String S_NAMESPACE = null;
   
  @@ -108,6 +107,10 @@
     private static final String S_ISTRUE="true";
     private static final String S_ISFALSE="false";
   
  +  private static final String S_DOCUMENT = "#root";
  +  private static final String S_TEXT_NODE = "#text";
  +  private static final String S_ELEMENT_NODE   = "#element";
  +
     private static final String S_COLUMN_HEADER = "column-header";
     private static final String S_ROW_SET = "row-set";
     private static final String S_ROW = "row";
  @@ -130,6 +133,9 @@
     private static final String S_ISWRITEABLE = "writable";
     private static final String S_ISSEARCHABLE = "searchable";
   
  +  private int         m_Document_TypeID = 0;
  +  private int         m_TextNode_TypeID = 0;
  +
     private int         m_ColumnHeader_TypeID = 0;
     private int         m_RowSet_TypeID = 0;
     private int         m_Row_TypeID = 0;
  @@ -153,11 +159,48 @@
     private int         m_ColAttrib_ISSEARCHABLE_TypeID = 0;
   
     /**
  +   * The DBMS Connection used to produce this SQL Document.
  +   * Will be used to clear free up the database resources on
  +   * close.
  +   */
  +  private Connection  m_Connection = null;
  +
  +  /**
  +   * The Statement used to extract the data from the Database connection.
  +   * We really don't need the connection, but it is NOT defined from
  +   * JDBC Driver to driver what happens to the ResultSet if the statment
  +   * is closed prior to reading all the data needed. So as long as we are
  +   * using the ResultSet, we will track the Statement used to produce it.
  +   */
  +  private Statement   m_Statement = null;
  +
  +  /**
  +   * The conduit to our data that will be used to fill the document.
  +   */
  +  private ResultSet   m_ResultSet = null;
  +
  +  /**
      * Store the SQL Data in this growable array
      */
     private ObjectArray m_ObjectArray = new ObjectArray();
   
     /**
  +   * For each element node, there can be zero or more attributes. If 
Attributes
  +   * are assigned, the first attribute for that element will be use here.
  +   * Subsequent elements will use the m_nextsib, m_prevsib array. The sibling
  +   * arrays are not meeant to hold indexes to attribute information but as
  +   * long as there is not direct connection back into the main DTM tree
  +   * we should be OK.
  +   */
  +  protected SuballocatedIntVector m_attribute;
  +
  +  /**
  +   * The Document Index will most likely be 0, but we will reference it
  +   * by variable in case that paradigm falls through.
  +   */
  +  private int       m_DocumentIdx;
  +
  +  /**
      * As the column header array is built, keep the node index
      * for each Column.
      *
  @@ -167,6 +210,10 @@
     private int[]     m_ColHeadersIdx;
   
     /**
  +   * An indicator on how many columns are in this query
  +   */
  +  private int       m_ColCount;
  +  /**
      * The index of the Row Set node. This is the sibling directly after
      * the last Column Header.
      */
  @@ -185,21 +232,25 @@
      */
     private int     m_LastRowIdx = DTM.NULL;
   
  -  public SQLDocument(DTMManager mgr, int ident, Connection con, Statement 
stmt, ResultSet data)
  +  public SQLDocument(
  +    DTMManager mgr, int ident,
  +    Connection con, Statement stmt, ResultSet data)
       throws SQLException
     {
       super(mgr, null, ident,
         null, mgr.getXMLStringFactory(), true);
   
  -    // DTMManager mgr, Source source, int dtmIdentity,
  -    // DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory,
  -    // boolean doIndexing
       m_Connection = con;
       m_Statement  = stmt;
       m_ResultSet  = data;
   
  +    m_attribute = new SuballocatedIntVector(m_initialblocksize);
  +
       createExpandedNameTable();
       extractSQLMetaData(m_ResultSet.getMetaData());
  +
  +    // Let's see what we have
  +    dumpDTM();
     }
   
   
  @@ -209,17 +260,18 @@
      */
     private void extractSQLMetaData(ResultSetMetaData meta)
     {
  -    int colCount = 0;
       // Build the Node Tree, just add the Column Header
       // branch now, the Row & col elements will be added
       // on request.
   
  +    // Start the document here
  +    m_DocumentIdx = addElement(0, m_Document_TypeID, DTM.NULL, DTM.NULL);
       // Add in the row-set Element
  -    m_RowSetIdx = addNode(null, 0, m_RowSet_TypeID, DTM.NULL, DTM.NULL);
  +    m_RowSetIdx = addElement(1, m_RowSet_TypeID,  m_DocumentIdx, DTM.NULL);
       try
       {
  -      colCount = meta.getColumnCount();
  -      m_ColHeadersIdx = new int[colCount];
  +      m_ColCount = meta.getColumnCount();
  +      m_ColHeadersIdx = new int[m_ColCount];
       }
       catch(Exception e)
       {
  @@ -235,222 +287,223 @@
       int lastColHeaderIdx = DTM.NULL;
   
       // JDBC Columms Start at 1
  -    for (int i=1; i<= colCount; i++)
  +    int i = 1;
  +    for (i=1; i<= m_ColCount; i++)
       {
  -      idx = DTM.NULL;
  -
         m_ColHeadersIdx[i-1] =
  -        addNode(
  -          null, 1,
  -          m_ColumnHeader_TypeID, m_RowSetIdx, lastColHeaderIdx);
  +        addElement(2,m_ColumnHeader_TypeID, m_RowSetIdx, lastColHeaderIdx);
   
         lastColHeaderIdx = m_ColHeadersIdx[i-1];
         // A bit brute force, but not sure how to clean it up
  -
  +/*
         try
         {
  -        idx = addNode(
  -          new Integer(meta.getColumnDisplaySize(i)), 1,
  -          m_ColAttrib_CATALOGUE_NAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.getCatalogName(i),
  +          m_ColAttrib_CATALOGUE_NAME_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_CATALOGUE_NAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_CATALOGUE_NAME_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          new Integer(meta.getColumnDisplaySize(i)), 1,
  -          m_ColAttrib_DISPLAY_SIZE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          new Integer(meta.getColumnDisplaySize(i)),
  +          m_ColAttrib_DISPLAY_SIZE_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_DISPLAY_SIZE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_DISPLAY_SIZE_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          meta.getColumnLabel(i), 1,
  -          m_ColAttrib_COLUMN_LABEL_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.getColumnLabel(i),
  +          m_ColAttrib_COLUMN_LABEL_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_COLUMN_LABEL_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_COLUMN_LABEL_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          meta.getColumnName(i), 1,
  -          m_ColAttrib_COLUMN_NAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.getColumnName(i),
  +          m_ColAttrib_COLUMN_NAME_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_COLUMN_NAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_COLUMN_NAME_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          new Integer(meta.getColumnType(i)), 1,
  -          m_ColAttrib_COLUMN_TYPE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          new Integer(meta.getColumnType(i)),
  +          m_ColAttrib_COLUMN_TYPE_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_COLUMN_TYPE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_COLUMN_TYPE_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          meta.getColumnTypeName(i), 1,
  -          m_ColAttrib_COLUMN_TYPENAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.getColumnTypeName(i),
  +          m_ColAttrib_COLUMN_TYPENAME_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_COLUMN_TYPENAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_COLUMN_TYPENAME_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          new Integer(meta.getPrecision(i)), 1,
  -          m_ColAttrib_PRECISION_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          new Integer(meta.getPrecision(i)),
  +          m_ColAttrib_PRECISION_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_PRECISION_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_PRECISION_TypeID, lastColHeaderIdx);
         }
         try
         {
  -        idx = addNode(
  -          new Integer(meta.getScale(i)), 1,
  -          m_ColAttrib_SCALE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          new Integer(meta.getScale(i)),
  +          m_ColAttrib_SCALE_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_SCALE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_SCALE_TypeID, lastColHeaderIdx);
         }
  +
         try
         {
  -        idx = addNode(
  -          meta.getSchemaName(i), 1,
  -          m_ColAttrib_SCHEMA_NAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.getSchemaName(i),
  +          m_ColAttrib_SCHEMA_NAME_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_SCHEMA_NAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_SCHEMA_NAME_TypeID, lastColHeaderIdx);
         }
         try
         {
  -        idx = addNode(
  -          meta.getTableName(i), 1,
  -          m_ColAttrib_TABLE_NAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.getTableName(i),
  +          m_ColAttrib_TABLE_NAME_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_TABLE_NAME_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_TABLE_NAME_TypeID, lastColHeaderIdx);
         }
  +
         try
         {
  -        idx = addNode(
  -          meta.isCaseSensitive(i) ? S_ISTRUE : S_ISFALSE, 1,
  -          m_ColAttrib_CASESENSITIVE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.isCaseSensitive(i) ? S_ISTRUE : S_ISFALSE,
  +          m_ColAttrib_CASESENSITIVE_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_CASESENSITIVE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_CASESENSITIVE_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          meta.isDefinitelyWritable(i) ? S_ISTRUE : S_ISFALSE, 1,
  -          m_ColAttrib_DEFINITLEYWRITEABLE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.isDefinitelyWritable(i) ? S_ISTRUE : S_ISFALSE,
  +          m_ColAttrib_DEFINITLEYWRITEABLE_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_DEFINITLEYWRITEABLE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_DEFINITLEYWRITEABLE_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          meta.isNullable(i) != 0 ? S_ISTRUE : S_ISFALSE, 1,
  -          m_ColAttrib_ISNULLABLE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.isNullable(i) != 0 ? S_ISTRUE : S_ISFALSE,
  +          m_ColAttrib_ISNULLABLE_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_ISNULLABLE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_ISNULLABLE_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          meta.isSigned(i) ? S_ISTRUE : S_ISFALSE, 1,
  -          m_ColAttrib_ISSIGNED_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.isSigned(i) ? S_ISTRUE : S_ISFALSE,
  +          m_ColAttrib_ISSIGNED_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_ISSIGNED_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_ISSIGNED_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          meta.isWritable(i) == true ? S_ISTRUE : S_ISFALSE, 1,
  -          m_ColAttrib_ISWRITEABLE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.isWritable(i) == true ? S_ISTRUE : S_ISFALSE,
  +          m_ColAttrib_ISWRITEABLE_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_ISWRITEABLE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_ISWRITEABLE_TypeID, lastColHeaderIdx);
         }
   
         try
         {
  -        idx = addNode(
  -          meta.isSearchable(i) == true ? S_ISTRUE : S_ISFALSE, 1,
  -          m_ColAttrib_ISSEARCHABLE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          meta.isSearchable(i) == true ? S_ISTRUE : S_ISFALSE,
  +          m_ColAttrib_ISSEARCHABLE_TypeID, lastColHeaderIdx);
         }
         catch(Exception e)
         {
  -        idx = addNode(
  -          S_ATTRIB_NOT_SUPPORTED, 1,
  -          m_ColAttrib_ISSEARCHABLE_TypeID, lastColHeaderIdx, idx);
  +        addAttributeToNode(
  +          S_ATTRIB_NOT_SUPPORTED,
  +          m_ColAttrib_ISSEARCHABLE_TypeID, lastColHeaderIdx);
         }
  +*/
       }
  +
     }
   
     /**
  @@ -461,6 +514,12 @@
     private void createExpandedNameTable()
     {
   
  +    m_Document_TypeID =
  +      m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_DOCUMENT, 
DTM.DOCUMENT_NODE);
  +
  +    m_TextNode_TypeID =
  +      m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_TEXT_NODE, 
DTM.TEXT_NODE);
  +
       m_ColumnHeader_TypeID =
         m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_COLUMN_HEADER, 
DTM.ELEMENT_NODE);
       m_RowSet_TypeID =
  @@ -505,26 +564,54 @@
         m_expandedNameTable.getExpandedTypeID(S_NAMESPACE, S_ISSEARCHABLE, 
DTM.ATTRIBUTE_NODE);
     }
   
  -  private int addNode(Object o, int level, int extendedType, int parent, int 
prevsib)
  +  /**
  +   * A common routine that allocates an Object from the Object Array.
  +   * One of the common bugs in this code was to allocate an Object and
  +   * not incerment m_size, using this method will assure that function.
  +   */
  +  private int allocateNodeObject(Object o)
     {
  -    int node = DTM.NULL;
  -
       // Need to keep this counter going even if we don't use it.
       m_size++;
  +    return m_ObjectArray.append(o);
  +  }
  +
  +  private int addElementWithData(Object o, int level, int extendedType, int 
parent, int prevsib)
  +  {
  +    int elementIdx = addElement(level,extendedType,parent,prevsib);
  +/*
  +    int data = allocateNodeObject(o);
  +    m_firstch.setElementAt(data,elementIdx);
   
  +    m_exptype.setElementAt(m_TextNode_TypeID, data);
  +    m_level.setElementAt((byte)(level), data);
  +    m_parent.setElementAt(elementIdx, data);
  +
  +    m_prevsib.setElementAt(DTM.NULL, data);
  +    m_nextsib.setElementAt(DTM.NULL, data);
  +    m_attribute.setElementAt(DTM.NULL, data);
  +    m_firstch.setElementAt(DTM.NULL, data);
  +*/
  +    return elementIdx;
  +  }
  +
  +  private int addElement(int level, int extendedType, int parent, int 
prevsib)
  +  {
  +    int node = DTM.NULL;
  +
       try
       {
         // Add the Node and adjust its Extended Type
  -      node = m_ObjectArray.append(o);
  +      node = allocateNodeObject(S_ELEMENT_NODE);
  +
         m_exptype.setElementAt(extendedType, node);
  +      m_nextsib.setElementAt(DTM.NULL, node);
         m_prevsib.setElementAt(prevsib, node);
  -      m_parent.setElementAt(parent, node);
   
  -      // Fixup the previous sibling
  -      // So if there was a previous sibling, chain into them.
  -
  -      // As a precaution, always set the next sibling
  -      m_nextsib.setElementAt(DTM.NULL, node);
  +      m_parent.setElementAt(parent, node);
  +      m_firstch.setElementAt(DTM.NULL, node);
  +      m_level.setElementAt((byte)level, node);
  +      m_attribute.setElementAt(DTM.NULL, node);
   
         if (prevsib != DTM.NULL)
         {
  @@ -536,12 +623,8 @@
           // Tell the proevious sibling that they have a new bother/sister.
           m_nextsib.setElementAt(node, prevsib);
         }
  -
  -      // Set this value even if we change it later
  -      m_parent.setElementAt(parent, node);
   
  -      // Fix up the Parent, Since we don't track f ththe last child, then
  -      // So if we have a valid parent and the new node ended up being first
  +       // So if we have a valid parent and the new node ended up being first
         // in the list, i.e. no prevsib, then set the new node up as the
         // first child of the parent. Since we chained the node in the list,
         // there should be no reason to worry about the current first child
  @@ -560,6 +643,87 @@
       return node;
     }
   
  +  /**
  +   * Link an attribute to a node, if the node already has one or more
  +   * attributes assigned, then just link this one to the attribute list.
  +   * The first attribute is attached to the Parent Node (pnode) through the
  +   * m_attribute array, subsequent attributes are linked through the
  +   * m_prevsib, m_nextsib arrays.
  +   *
  +   */
  +  private int addAttributeToNode(
  +    Object o, int extendedType, int pnode)
  +  {
  +
  +    int attrib = DTM.NULL;
  +    int prevsib = DTM.NULL;
  +    int lastattrib = DTM.NULL;
  +    int value = DTM.NULL;
  +
  +    try
  +    {
  +      // Add the Node and adjust its Extended Type
  +      attrib = allocateNodeObject(o);
  +
  +      m_attribute.setElementAt(DTM.NULL, attrib);
  +      m_exptype.setElementAt(extendedType, attrib);
  +      m_level.setElementAt((byte)0, attrib);
  +
  +
  +      // Clear the sibling references
  +      m_nextsib.setElementAt(DTM.NULL, attrib);
  +      m_prevsib.setElementAt(DTM.NULL,attrib);
  +      // Set the parent, although the was we are using attributes
  +      // in the SQL extension this reference will more than likly
  +      // be wrong
  +      m_parent.setElementAt(pnode, attrib);
  +      m_firstch.setElementAt(DTM.NULL, attrib);
  +
  +      if (m_attribute.elementAt(pnode) != DTM.NULL)
  +      {
  +        // OK, we already have an attribute assigned to this
  +        // Node, Insert us into the head of the list.
  +        lastattrib = m_attribute.elementAt(pnode);
  +        m_nextsib.setElementAt(lastattrib, attrib);
  +        m_prevsib.setElementAt(attrib, lastattrib);
  +      }
  +      // Okay set the new attribute up as the first attribute
  +      // for the node.
  +      m_attribute.setElementAt(attrib, pnode);
  +    }
  +    catch(Exception e)
  +    {
  +      // Let's just return DTM.NULL now
  +      error("");
  +    }
  +
  +    return attrib;
  +  }
  +
  +  /**
  +   * Allow two nodes to share the same set of attributes. There may be some
  +   * problems because the parent of any attribute will be the original node
  +   * they were assigned to. Need to see how the attribute walker works, then
  +   * we should be able to fake it out.
  +   */
  +  private void cloneAttributeFromNode(int toNode, int fromNode)
  +  {
  +   try
  +    {
  +      if (m_attribute.elementAt(toNode) != DTM.NULL)
  +      {
  +        error("Cloneing Attributes, where from Node already had addtibures 
assigned");
  +      }
  +
  +      m_attribute.setElementAt(m_attribute.elementAt(fromNode), toNode);
  +    }
  +    catch(Exception e)
  +    {
  +      // Let's just return DTM.NULL now
  +      error("Cloning attributes");
  +    }
  +  }
  +
     private boolean addRowToDTMFromResultSet()
     {
       try
  @@ -569,19 +733,33 @@
         // If this is the first time here, start the new level
         if (m_FirstRowIdx == DTM.NULL)
         {
  -        m_FirstRowIdx = addNode(null,2, m_Row_TypeID, m_RowSetIdx, DTM.NULL);
  +        m_FirstRowIdx =
  +          addElement(2, m_Row_TypeID, m_RowSetIdx, 
m_ColHeadersIdx[m_ColCount-1]);
           m_LastRowIdx = m_FirstRowIdx;
         }
         else
         {
  -        m_LastRowIdx = addNode(null,2, m_Row_TypeID, m_RowSetIdx, 
m_LastRowIdx);
  +        m_LastRowIdx = addElement(2, m_Row_TypeID, m_RowSetIdx, 
m_LastRowIdx);
         }
  +
  +      int colID = DTM.NULL;
  +
  +      // Columns in JDBC Start at 1 and go to the Extent
  +      for (int i=1; i<= m_ColCount; i++)
  +      {
  +        // Just grab the Column Object Type, we will convert it to a string
  +        // later.
  +        Object o = m_ResultSet.getObject(i);
  +        colID = addElementWithData(o,3,m_Col_TypeID, m_LastRowIdx, colID);
  +//        cloneAttributeFromNode(colID, m_ColHeadersIdx[i-1]);
  +      }
       }
       catch(Exception e)
       {
         error("SQL Error Fetching next row [" + e.getLocalizedMessage() + "]");
       }
   
  +    // Only do a single row...
       return false;
     }
   
  @@ -618,11 +796,242 @@
       }
     }
   
  +  public int getFirstAttribute(int parm1)
  +  {
  +    if (DEBUG) System.out.println("getFirstAttribute("+ 
(parm1&NODEIDENTITYBITS)+")");
  +    int nodeIdx = parm1 & NODEIDENTITYBITS;
  +    if (nodeIdx != DTM.NULL) return m_attribute.elementAt(nodeIdx);
  +    else return DTM.NULL;
  +  }
  +
  + /**
  +   * @param parm1
  +   * @return
  +   */
  +  public String getNodeValue( int parm1 )
  +  {
  +    if (DEBUG) System.out.println("getNodeValue(" + parm1 + ")");
  +    try
  +    {
  +      Object o = m_ObjectArray.getAt(parm1 & NODEIDENTITYBITS);
  +      if (o != null)
  +      {
  +        return o.toString();
  +      }
  +      else
  +      {
  +        return "";
  +      }
  +    }
  +    catch(Exception e)
  +    {
  +      error("Getting String Value");
  +      return null;
  +    }
  +  }
  +
   
     /**
      * @param parm1
      * @return
      */
  +  public XMLString getStringValue( int parm1 )
  +  {
  +    if (DEBUG) System.out.println("getStringValue(" + parm1 + ")");
  +    try
  +    {
  +      Object o = m_ObjectArray.getAt(parm1 & NODEIDENTITYBITS);
  +      if (o != null)
  +      {
  +        return m_xstrf.newstr(o.toString());
  +      }
  +      else
  +      {
  +        return m_xstrf.emptystr();
  +      }
  +    }
  +    catch(Exception e)
  +    {
  +      error("Getting String Value");
  +      return null;
  +    }
  +  }
  +
  +
  +  public int getNextAttribute(int parm1)
  +  {
  +    if (DEBUG) System.out.println("getNextAttribute(" + parm1 + ")");
  +    int nodeIdx = parm1 & NODEIDENTITYBITS;
  +    if (nodeIdx != DTM.NULL) return m_nextsib.elementAt(nodeIdx);
  +    else return DTM.NULL;
  +  }
  +
  +
  +  /**
  +   * @return
  +   */
  +  protected int getNumberOfNodes( )
  +  {
  +    if (DEBUG) System.out.println("getNumberOfNodes()");
  +    return m_size;
  +  }
  +
  +  /**
  +   * @return
  +   */
  +  protected boolean nextNode( )
  +  {
  +    if (DEBUG) System.out.println("nextNode()");
  +    return addRowToDTMFromResultSet();
  +  }
  +
  +
  +  public void dumpDTM()
  +  {
  +    try
  +    {
  +//      File f = new File("DTMDump"+((Object)this).hashCode()+".txt");
  +      File f = new File("DTMDump.txt");
  +      System.err.println("Dumping... "+f.getAbsolutePath());
  +      PrintStream ps = new PrintStream(new FileOutputStream(f));
  +
  +      while (nextNode()){}
  +
  +      int nRecords = m_size;
  +
  +      ps.println("Total nodes: " + nRecords);
  +
  +      for (int i = 0; i < nRecords; i++)
  +      {
  +        ps.println("=========== " + i + " ===========");
  +        ps.println("NodeName: " + getNodeName(i));
  +        ps.println("NodeNameX: " + getNodeNameX(i));
  +        ps.println("LocalName: " + getLocalName(i));
  +        ps.println("NamespaceURI: " + getNamespaceURI(i));
  +        ps.println("Prefix: " + getPrefix(i));
  +
  +        int exTypeID = getExpandedTypeID(i);
  +
  +        ps.println("Expanded Type ID: "
  +                           + Integer.toHexString(exTypeID));
  +
  +        int type = getNodeType(i);
  +        String typestring;
  +
  +        switch (type)
  +        {
  +        case DTM.ATTRIBUTE_NODE :
  +          typestring = "ATTRIBUTE_NODE";
  +          break;
  +        case DTM.CDATA_SECTION_NODE :
  +          typestring = "CDATA_SECTION_NODE";
  +          break;
  +        case DTM.COMMENT_NODE :
  +          typestring = "COMMENT_NODE";
  +          break;
  +        case DTM.DOCUMENT_FRAGMENT_NODE :
  +          typestring = "DOCUMENT_FRAGMENT_NODE";
  +          break;
  +        case DTM.DOCUMENT_NODE :
  +          typestring = "DOCUMENT_NODE";
  +          break;
  +        case DTM.DOCUMENT_TYPE_NODE :
  +          typestring = "DOCUMENT_NODE";
  +          break;
  +        case DTM.ELEMENT_NODE :
  +          typestring = "ELEMENT_NODE";
  +          break;
  +        case DTM.ENTITY_NODE :
  +          typestring = "ENTITY_NODE";
  +          break;
  +        case DTM.ENTITY_REFERENCE_NODE :
  +          typestring = "ENTITY_REFERENCE_NODE";
  +          break;
  +        case DTM.NAMESPACE_NODE :
  +          typestring = "NAMESPACE_NODE";
  +          break;
  +        case DTM.NOTATION_NODE :
  +          typestring = "NOTATION_NODE";
  +          break;
  +        case DTM.NULL :
  +          typestring = "NULL";
  +          break;
  +        case DTM.PROCESSING_INSTRUCTION_NODE :
  +          typestring = "PROCESSING_INSTRUCTION_NODE";
  +          break;
  +        case DTM.TEXT_NODE :
  +          typestring = "TEXT_NODE";
  +          break;
  +        default :
  +          typestring = "Unknown!";
  +          break;
  +        }
  +
  +        ps.println("Type: " + typestring);
  +
  +        int firstChild = _firstch(i);
  +
  +        if (DTM.NULL == firstChild)
  +          ps.println("First child: DTM.NULL");
  +        else if (NOTPROCESSED == firstChild)
  +          ps.println("First child: NOTPROCESSED");
  +        else
  +          ps.println("First child: " + firstChild);
  +
  +        int prevSibling = _prevsib(i);
  +
  +        if (DTM.NULL == prevSibling)
  +          ps.println("Prev sibling: DTM.NULL");
  +        else if (NOTPROCESSED == prevSibling)
  +          ps.println("Prev sibling: NOTPROCESSED");
  +        else
  +          ps.println("Prev sibling: " + prevSibling);
  +
  +        int nextSibling = _nextsib(i);
  +
  +        if (DTM.NULL == nextSibling)
  +          ps.println("Next sibling: DTM.NULL");
  +        else if (NOTPROCESSED == nextSibling)
  +          ps.println("Next sibling: NOTPROCESSED");
  +        else
  +          ps.println("Next sibling: " + nextSibling);
  +
  +        int parent = _parent(i);
  +
  +        if (DTM.NULL == parent)
  +          ps.println("Parent: DTM.NULL");
  +        else if (NOTPROCESSED == parent)
  +          ps.println("Parent: NOTPROCESSED");
  +        else
  +          ps.println("Parent: " + parent);
  +
  +        int level = _level(i);
  +
  +        ps.println("Level: " + level);
  +        ps.println("Node Value: " + getNodeValue(i));
  +        ps.println("String Value: " + getStringValue(i));
  +
  +        ps.println("First Attribute Node: " + m_attribute.elementAt(i));
  +      }
  +
  +    }
  +    catch(IOException ioe)
  +    {
  +      ioe.printStackTrace(System.err);
  +      System.exit(-1);
  +    }
  +  }
  +
  +  /*********************************************************************/
  +  /*********************************************************************/
  +  /******************* End of Functions we Wrote ***********************/
  +  /*********************************************************************/
  +  /*********************************************************************/
  +
  +  /**
  +   * @param parm1
  +   * @return
  +   */
     protected int getNextNodeIdentity( int parm1 )
     {
       if (DEBUG) System.out.println("getNextNodeIdenty(" + parm1 + ")");
  @@ -683,68 +1092,11 @@
       }
       return getLocalNameFromExpandedNameID(exID);
     }
  -
  -  /**
  -   * @param parm1
  -   * @return
  -   */
  -  public int getElementById( String parm1 )
  -  {
  -    if (DEBUG) System.out.println("getElementByID("+parm1+")");
  -    return DTM.NULL;
  -  }
  -
  -  /**
  -   * @return
  -   */
  -  public DeclHandler getDeclHandler( )
  -  {
  -    if (DEBUG) System.out.println("getDeclHandler()");
  -    return null;
  -  }
  -
  -  /**
  -   * @return
  -   */
  -  public ErrorHandler getErrorHandler( )
  -  {
  -    if (DEBUG) System.out.println("getErrorHandler()");
  -    return null;
  -  }
  -
  -  /**
  -   * @return
  -   */
  -  public String getDocumentTypeDeclarationSystemIdentifier( )
  -  {
  -    if (DEBUG) System.out.println("get_DTD-SID()");
  -    return null;
  -  }
  -
  -  /**
  -   * @return
  -   */
  -  protected int getNumberOfNodes( )
  -  {
  -    if (DEBUG) System.out.println("getNumberOfNodes()");
  -    return 0;
  -  }
   
  -
  -  /**
  +   /**
      * @param parm1
      * @return
      */
  -  public String getNodeValue( int parm1 )
  -  {
  -    if (DEBUG) System.out.println("getNodeValue(" + parm1 + ")");
  -    return "";
  -  }
  -
  -  /**
  -   * @param parm1
  -   * @return
  -   */
     public boolean isAttributeSpecified( int parm1 )
     {
       if (DEBUG) System.out.println("isAttributeSpecified(" + parm1 + ")");
  @@ -801,31 +1153,11 @@
     /**
      * @return
      */
  -  protected boolean nextNode( )
  -  {
  -    if (DEBUG) System.out.println("nextNode()");
  -    return addRowToDTMFromResultSet();
  -  }
  -
  -  /**
  -   * @return
  -   */
     public LexicalHandler getLexicalHandler( )
     {
       if (DEBUG) System.out.println("getLexicalHandler()");
       return null;
     }
  -
  -  /**
  -   * @param parm1
  -   * @return
  -   */
  -  public XMLString getStringValue( int parm1 )
  -  {
  -    if (DEBUG) System.out.println("getStringValue(" + parm1 + ")");
  -    return null;
  -  }
  -
     /**
      * @return
      */
  @@ -950,7 +1282,9 @@
     public String getNodeNameX(int parm1)
     {
       if (DEBUG) System.out.println("getNodeNameX(" + parm1 + ")");
  -    return super.getNodeNameX( parm1);
  +    //return super.getNodeNameX( parm1);
  +    return getNodeName(parm1);
  +
     }
   
     public void setFeature(String parm1, boolean parm2)
  @@ -1026,11 +1360,6 @@
       return super.isSupported( parm1,  parm2);
     }
   
  -  public void dumpDTM()
  -  {
  -    if (DEBUG) System.out.println("dumpDTM()");
  -    super.dumpDTM();
  -  }
   
     protected void setShouldStripWhitespace(boolean parm1)
     {
  @@ -1155,12 +1484,6 @@
       return super.getNodeType( parm1);
     }
   
  -  public int getNextAttribute(int parm1)
  -  {
  -    if (DEBUG) System.out.println("getNextAttribute(" + parm1 + ")");
  -    return super.getNextAttribute( parm1);
  -  }
  -
     public boolean isCharacterElementContentWhitespace(int parm1)
     {
       if (DEBUG) System.out.println("isCharacterElementContentWhitespace(" + 
parm1 +")");
  @@ -1246,11 +1569,6 @@
       super.error( parm1);
     }
   
  -  public int getFirstAttribute(int parm1)
  -  {
  -    if (DEBUG) System.out.println("getFirstAttribute("+parm1+")");
  -    return super.getFirstAttribute( parm1);
  -  }
   
     protected int _firstch(int parm1)
     {
  @@ -1329,27 +1647,40 @@
       if (DEBUG) System.out.println("getAxisIterator("+parm1+")");
       return super.getAxisIterator( parm1);
     }
  -  
     /**
  -   * For the moment all the run time properties are ignored by this
  -   * class.
  -   *
  -   * @param property a <code>String</code> value
  -   * @param value an <code>Object</code> value
  +   * @param parm1
  +   * @return
      */
  -  public void setProperty(String property, Object value)
  +  public int getElementById( String parm1 )
     {
  +    if (DEBUG) System.out.println("getElementByID("+parm1+")");
  +    return DTM.NULL;
     }
  -  
  +
     /**
  -   * No source information is available for DOM2DTM, so return
  -   * <code>null</code> here.
  -   *
  -   * @param node an <code>int</code> value
  -   * @return null
  +   * @return
      */
  -  public javax.xml.transform.SourceLocator getSourceLocatorFor(int node)
  +  public DeclHandler getDeclHandler( )
     {
  +    if (DEBUG) System.out.println("getDeclHandler()");
  +    return null;
  +  }
  +
  +  /**
  +   * @return
  +   */
  +  public ErrorHandler getErrorHandler( )
  +  {
  +    if (DEBUG) System.out.println("getErrorHandler()");
  +    return null;
  +  }
  +
  +  /**
  +   * @return
  +   */
  +  public String getDocumentTypeDeclarationSystemIdentifier( )
  +  {
  +    if (DEBUG) System.out.println("get_DTD-SID()");
       return null;
     }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to