Package org.jdom

Examples of org.jdom.Element


            return results;
        }
        // -------------------------------
        // Read the SELECT elements
        // -------------------------------
        Element selectElement = resultsElement.getChild(TagNames.Elements.SELECT);
        Select select = new Select();
        select = consumeMsg(select, selectElement);

        List listOfElementSymbols = select.getSymbols();
        Iterator elementSymbolItr = listOfElementSymbols.iterator();
        Collection collectionOfColumnInfos = new ArrayList();
        while ( elementSymbolItr.hasNext() ) {
            ElementSymbol elementSymbol = (ElementSymbol) elementSymbolItr.next();
            Class elementType = elementSymbol.getType();
            String dataType = DataTypeManager.getDataTypeName(elementType);
            ColumnInfo columnInfo = new ColumnInfo(elementSymbol.getName(), dataType, elementType);
            collectionOfColumnInfos.add(columnInfo);
        }
        // Save column info
        results.addFields(collectionOfColumnInfos);
        // -------------------------------
        // Read the TABLE of data
        // -------------------------------

        Element tableElement = resultsElement.getChild(TagNames.Elements.TABLE);
        List tableRows = tableElement.getChildren(TagNames.Elements.TABLE_ROW);
        if ( tableRows.size() > 0 ) {
            Iterator rowIter = tableRows.iterator();

            while ( rowIter.hasNext() ) {
                Element rowElement = (Element) rowIter.next();
                List cellElements = rowElement.getChildren(TagNames.Elements.TABLE_CELL);
                Iterator cellIter = cellElements.iterator();
                // Read cells of the table
                ArrayList row = new ArrayList();
                Object evalue = null;
                while ( cellIter.hasNext() ) {
                    Element cellElement = (Element) cellIter.next();
                    if ( cellElement.getTextTrim().equalsIgnoreCase(TagNames.Elements.NULL) ) {
                        row.add(null);
                    } else {
                        Element cellChildElement = (Element) cellElement.getChildren().get(0);
                        evalue = consumeMsg(cellChildElement);
                        row.add(evalue);
                    }
                }
                // Save row
View Full Code Here


        // Read the IDENTIFIER elements ...
        // --------------------------------
        List idents = selectElement.getChildren();
        Iterator identIter = idents.iterator();
        while ( identIter.hasNext() ) {
            Element dataElement = (Element) identIter.next();
            Attribute dataType = dataElement.getAttribute(TagNames.Attributes.TYPE);
            // add the dataType of the element to the list containing dataTypes
            ElementSymbol nodeID = new ElementSymbol(dataElement.getText());
            Class nodeType = (Class) TagNames.TYPE_MAP.get(dataType.getValue());
            if (nodeType == null)  {
                throw new JDOMException("Unknown class for type \"" + dataType.getValue() + "\"."); //$NON-NLS-1$ //$NON-NLS-2$
            }
            nodeID.setType(nodeType);
View Full Code Here

    private Element produceMsg(ResultSet object, int endRow) throws JDOMException, SQLException {

        // -----------------------------------
        // Create the QueryResults element ...
        // -----------------------------------
        Element resultsElement = new Element(TagNames.Elements.QUERY_RESULTS);

        // -----------------------------------
        // Add the Select (header) element ...
        // -----------------------------------
        try {
            ResultSetMetaData rmdata = object.getMetaData();
            List identList = new ArrayList(rmdata.getColumnCount());
            for ( int i = 1; i <= rmdata.getColumnCount(); i++ ) {
                identList.add(new ElementSymbol(rmdata.getColumnName(i)));
            }
            Select select = new Select(identList);
            resultsElement = produceMsg(select, rmdata, resultsElement);

            // -------------------------
            // Add the Table element ...
            // -------------------------
            resultsElement.addContent(new Element(TagNames.Elements.TABLE));
            Element tableElement = resultsElement.getChild(TagNames.Elements.TABLE);
            int rowCount = 0;
            int colCount = rmdata.getColumnCount();

            while ( object.next() && (object.getRow() <= endRow) ) {

                // -------------------------
                // Add the ROW element ...
                // -------------------------
                Element rowElement = new Element(TagNames.Elements.TABLE_ROW);

                for ( int i = 1; i <= colCount; i++ ) {
                    // -------------------------
                    // Add the Cell element ...
                    // -------------------------
                    Element cellElement = new Element(TagNames.Elements.TABLE_CELL);
                    Object cellValue = object.getObject(i);
                    if ( cellValue != null ) {
                        cellElement = produceMsg(cellValue, cellElement);
                    } else {
                        cellElement = cellElement.addContent(TagNames.Elements.NULL);
                    }
                    rowElement.addContent(cellElement);
                }
                tableElement.addContent(rowElement);
                rowCount++;
View Full Code Here

            resultsElement = produceMsg(select, rmdata, resultsElement);

            // -------------------------
            // Add the Table element ...
            // -------------------------
            resultsElement.addContent(new Element(TagNames.Elements.TABLE));
            Element tableElement = resultsElement.getChild(TagNames.Elements.TABLE);
            int rowCount = 0;
            int colCount = rmdata.getColumnCount();

            while ( object.next() ) {

                // -------------------------
                // Add the ROW element ...
                // -------------------------
                Element rowElement = new Element(TagNames.Elements.TABLE_ROW);

                for ( int i = 1; i <= colCount; i++ ) {
                    // -------------------------
                    // Add the Cell element ...
                    // -------------------------
                    Element cellElement = new Element(TagNames.Elements.TABLE_CELL);
                    Object cellValue = object.getObject(i);
                    if ( cellValue != null ) {
                        cellElement = produceMsg(cellValue, cellElement);
                    } else {
                        cellElement = cellElement.addContent(TagNames.Elements.NULL);
                    }
                    rowElement.addContent(cellElement);
                }
                tableElement.addContent(rowElement);
                rowCount++;
View Full Code Here

     */
    public Element produceMsg(Object object, Element parent) throws JDOMException, SQLException {
        if ( object == null ) {
            throw new IllegalArgumentException("Null object reference."); //$NON-NLS-1$
        }
        Element element = null;

        if ( object instanceof Boolean ) {
            element = produceMsg((Boolean) object, parent);
        } else if ( object instanceof String ) {
            element = produceMsg((String) object, parent);
View Full Code Here

        // -----------------------------------
        // Create the Select element ...
        // -----------------------------------

        Element selectElement = new Element(TagNames.Elements.SELECT);

        // ---------------------------------
        // Create the DISTINCT attribute ...
        // ---------------------------------
        boolean distinct = select.isDistinct();
        if ( distinct ) {
            Attribute distinctAttribute = new Attribute(TagNames.Attributes.DISTINCT, "true"); //$NON-NLS-1$
            selectElement.setAttribute(distinctAttribute);
        } // else default is false so no need

        // ----------------------------------
        // Create the STAR attribute ...
        // ----------------------------------
        if ( select.isStar() ) {
            Attribute starAttribute = new Attribute(TagNames.Attributes.STAR, "true"); //$NON-NLS-1$
            selectElement.setAttribute(starAttribute);
        }

        // --------------------------------
        // Create the DATANODE elements ...
        // --------------------------------
        int col = 0;
        Iterator iter = select.getSymbols().iterator();
        while ( iter.hasNext() ) {
            Element dataElement = new Element(TagNames.Elements.DATA_ELEMENT);
            ElementSymbol symbol = (ElementSymbol) iter.next();
            String elementName = symbol.getName();
            Attribute dataType = null;
            try {
                dataType = new Attribute(TagNames.Attributes.TYPE, rmdata.getColumnTypeName(++col));
            } catch ( SQLException e ) {
                //
            }
            dataElement.setAttribute(dataType);
            dataElement.setText(elementName);
            selectElement.addContent(dataElement);
        }
        if ( parent != null ) {
            selectElement = parent.addContent(selectElement);
        }
View Full Code Here

    private Element produceObject(Object object, Element parent) throws JDOMException, SQLException {

         // ----------------------
        // Create the Object element ...
        // ----------------------
        Element objectElement = new Element(TagNames.Elements.OBJECT);
       
        String result = null;
        if (object instanceof Blob || object instanceof Clob || object instanceof SQLXML) {
         
          if (object instanceof Clob){
            Clob c = (Clob)object;
            try {
              result = ObjectConverterUtil.convertToString(c.getAsciiStream());
         
        } catch (Throwable e) {
          // TODO Auto-generated catch block
          throw new SQLException(e);
        }
          } else if (object instanceof Blob){
                Blob b = (Blob)object;
                try {
                  result = ObjectConverterUtil.convertToString(b.getBinaryStream());
           
          } catch (Throwable e) {
            // TODO Auto-generated catch block
            throw new SQLException(e);
          }
            } else if (object instanceof SQLXML){
              SQLXML s = (SQLXML)object;
            try {
              result = ObjectConverterUtil.convertToString(s.getBinaryStream());
         
        } catch (Throwable e) {
          // TODO Auto-generated catch block
          throw new SQLException(e);
        }
            }
        } else {
          result = object.toString();
        }
       
         objectElement.setText(result);

       
        if ( parent != null ) {
            objectElement = parent.addContent(objectElement);
        }
View Full Code Here

    private Element produceMsg(String object, Element parent) throws JDOMException {

        // ----------------------
        // Create the String element ...
        // ----------------------
        Element stringElement = new Element(TagNames.Elements.STRING);
        stringElement.setText(object);
        if ( parent != null ) {
            stringElement = parent.addContent(stringElement);
        }

        return stringElement;
View Full Code Here

    private Element produceMsg(Character object, Element parent) throws JDOMException {

        // ----------------------
        // Create the Character element ...
        // ----------------------
        Element charElement = new Element(TagNames.Elements.CHAR);
              
        String v = object.toString();
        if (v != null && v.length() != 0) {
           
      String toReplace = new String( new Character( (char)0x0).toString() );
      v.replaceAll(toReplace," ");
      charElement.setText(v.trim());

        }
        if ( parent != null ) {
            charElement = parent.addContent(charElement);
        }
View Full Code Here

    private Element produceMsg(Byte object, Element parent) throws JDOMException {

        // ----------------------
        // Create the Byte element ...
        // ----------------------
        Element byteElement = new Element(TagNames.Elements.BYTE);
        byteElement.setText(object.toString());
        if ( parent != null ) {
            byteElement = parent.addContent(byteElement);
        }

        return byteElement;
View Full Code Here

TOP

Related Classes of org.jdom.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.