Exemplo n.º 1
0
  /**
   * Sets a property, metadata, or data value with the characters in the given array of characters,
   * starting with the array element indicated by <code>start</code> and continuing for <code>length
   * </code> number of characters.
   *
   * <p>The SAX parser invokes this method and supplies the character array, start position, and
   * length parameter values it got from parsing the XML document. An application programmer never
   * invokes this method directly.
   *
   * @param ch an array of characters supplied by the SAX parser, all or part of which will be used
   *     to set a value
   * @param start the position in the given array at which to start
   * @param length the number of consecutive characters to use
   */
  public void characters(char[] ch, int start, int length) throws SAXException {
    try {
      switch (getState()) {
        case PROPERTIES:
          propertyValue = new String(ch, start, length);

          /**
           * This has been added for handling of special characters. When special characters are
           * encountered the characters function gets called for each of the characters so we need
           * to append the value got in the previous call as it is the same data present between the
           * start and the end tag.
           */
          tempCommand = tempCommand.concat(propertyValue);
          propertyValue = tempCommand;

          // Added the following check for handling of type tags in maps
          if (tag == PropTypeTag) {
            Key_map = propertyValue;
          }

          // Added the following check for handling of class tags in maps
          else if (tag == PropClassTag) {
            Value_map = propertyValue;
          }
          break;

        case METADATA:

          // The parser will come here after the endElement as there is
          // "\n" in the after endTag is printed. This will cause a problem
          // when the data between the tags is an empty string so adding
          // below condition to take care of that situation.

          if (tag == -1) {
            break;
          }

          metaDataValue = new String(ch, start, length);
          break;
        case DATA:
          setDataValue(ch, start, length);
          break;
        default:;
      }
    } catch (SQLException ex) {
      throw new SAXException(
          resBundle.handleGetObject("xmlrch.chars").toString() + ex.getMessage());
    }
  }
Exemplo n.º 2
0
  private void applyUpdates() throws SAXException {
    // now handle any updates
    if (updates.size() > 0) {
      try {
        Object upd[];
        Iterator<?> i = updates.iterator();
        while (i.hasNext()) {
          upd = (Object[]) i.next();
          idx = ((Integer) upd[0]).intValue();

          if (!(lastval.equals(upd[1]))) {
            insertValue((String) (upd[1]));
          }
        }

        rs.updateRow();
      } catch (SQLException ex) {
        throw new SAXException(
            MessageFormat.format(
                resBundle.handleGetObject("xmlrch.errupdrow").toString(), ex.getMessage()));
      }
      updates.removeAllElements();
    }
  }
Exemplo n.º 3
0
  private void setPropertyValue(String s) throws SQLException {
    // find out if we are going to be dealing with a null
    boolean nullValue = getNullValue();

    switch (getTag()) {
      case CommandTag:
        if (nullValue) ; // rs.setCommand(null);
        else rs.setCommand(s);
        break;
      case ConcurrencyTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setConcurrency(getIntegerValue(s));
        break;
      case DatasourceTag:
        if (nullValue) rs.setDataSourceName(null);
        else rs.setDataSourceName(s);
        break;
      case EscapeProcessingTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setEscapeProcessing(getBooleanValue(s));
        break;
      case FetchDirectionTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setFetchDirection(getIntegerValue(s));
        break;
      case FetchSizeTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setFetchSize(getIntegerValue(s));
        break;
      case IsolationLevelTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setTransactionIsolation(getIntegerValue(s));
        break;
      case KeycolsTag:
        break;
      case PropColumnTag:
        if (keyCols == null) keyCols = new Vector<>();
        keyCols.add(s);
        break;
      case MapTag:
        break;
      case MaxFieldSizeTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setMaxFieldSize(getIntegerValue(s));
        break;
      case MaxRowsTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setMaxRows(getIntegerValue(s));
        break;
      case QueryTimeoutTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setQueryTimeout(getIntegerValue(s));
        break;
      case ReadOnlyTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setReadOnly(getBooleanValue(s));
        break;
      case RowsetTypeTag:
        if (nullValue) {
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        } else {
          // rs.setType(getIntegerValue(s));
          String strType = getStringValue(s);
          int iType = 0;

          if (strType.trim().equals("ResultSet.TYPE_SCROLL_INSENSITIVE")) {
            iType = 1004;
          } else if (strType.trim().equals("ResultSet.TYPE_SCROLL_SENSITIVE")) {
            iType = 1005;
          } else if (strType.trim().equals("ResultSet.TYPE_FORWARD_ONLY")) {
            iType = 1003;
          }
          rs.setType(iType);
        }
        break;
      case ShowDeletedTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString());
        else rs.setShowDeleted(getBooleanValue(s));
        break;
      case TableNameTag:
        if (nullValue)
          // rs.setTableName(null);
          ;
        else rs.setTableName(s);
        break;
      case UrlTag:
        if (nullValue) rs.setUrl(null);
        else rs.setUrl(s);
        break;
      case SyncProviderNameTag:
        if (nullValue) {
          rs.setSyncProvider(null);
        } else {
          String str = s.substring(0, s.indexOf("@") + 1);
          rs.setSyncProvider(str);
        }
        break;
      case SyncProviderVendorTag:
        // to be implemented
        break;
      case SyncProviderVersionTag:
        // to be implemented
        break;
      case SyncProviderGradeTag:
        // to be implemented
        break;
      case DataSourceLock:
        // to be implemented
        break;
      default:
        break;
    }
  }
Exemplo n.º 4
0
  /**
   * Sets the value for the given element if <code>name</code> is one of the array elements in the
   * fields <code>properties</code>, <code>colDef</code>, or <code>data</code> and this <code>
   * XmlReaderContentHandler</code> object's state is not <code>INITIAL</code>. If the state is
   * <code>INITIAL</code>, this method does nothing.
   *
   * <p>If the state is <code>METADATA</code> and the argument supplied is <code>"metadata"</code>,
   * the rowset's metadata is set. If the state is <code>PROPERTIES</code>, the appropriate property
   * is set using the given name to determine the appropriate value. If the state is <code>DATA
   * </code> and the argument supplied is <code>"data"</code>, this method sets the state to <code>
   * INITIAL</code> and returns. If the argument supplied is one of the elements in the field <code>
   * data</code>, this method makes the appropriate changes to the rowset's data.
   *
   * @param lName the name of the element; either (1) one of the array elements in the fields <code>
   *     properties</code>, <code>colDef</code>, or <code>data</code> or (2) one of the <code>RowSet
   *     </code> elements <code>"properties"</code>, <code>"metadata"</code>, or <code>"data"</code>
   * @exception SAXException if a general SAX error occurs
   */
  @SuppressWarnings("fallthrough")
  public void endElement(String uri, String lName, String qName) throws SAXException {
    int tag;

    String name = "";
    name = lName;

    switch (getState()) {
      case PROPERTIES:
        if (name.equals("properties")) {
          state = INITIAL;
          break;
        }

        try {
          tag = propMap.get(name);
          switch (tag) {
            case KeycolsTag:
              if (keyCols != null) {
                int i[] = new int[keyCols.size()];
                for (int j = 0; j < i.length; j++) i[j] = Integer.parseInt(keyCols.elementAt(j));
                rs.setKeyColumns(i);
              }
              break;

            case PropClassTag:
              // Added the handling for Class tags to take care of maps
              // Makes an entry into the map upon end of class tag
              try {
                typeMap.put(Key_map, j86.sun.reflect.misc.ReflectUtil.forName(Value_map));

              } catch (ClassNotFoundException ex) {
                throw new SAXException(
                    MessageFormat.format(
                        resBundle.handleGetObject("xmlrch.errmap").toString(), ex.getMessage()));
              }
              break;

            case MapTag:
              // Added the handling for Map to take set the typeMap
              rs.setTypeMap(typeMap);
              break;

            default:
              break;
          }

          if (getNullValue()) {
            setPropertyValue(null);
            setNullValue(false);
          } else {
            setPropertyValue(propertyValue);
          }
        } catch (SQLException ex) {
          throw new SAXException(ex.getMessage());
        }

        // propertyValue need to be reset to an empty string
        propertyValue = "";
        setTag(-1);
        break;
      case METADATA:
        if (name.equals("metadata")) {
          try {
            rs.setMetaData(md);
            state = INITIAL;
          } catch (SQLException ex) {
            throw new SAXException(
                MessageFormat.format(
                    resBundle.handleGetObject("xmlrch.errmetadata").toString(), ex.getMessage()));
          }
        } else {
          try {
            if (getNullValue()) {
              setMetaDataValue(null);
              setNullValue(false);
            } else {
              setMetaDataValue(metaDataValue);
            }
          } catch (SQLException ex) {
            throw new SAXException(
                MessageFormat.format(
                    resBundle.handleGetObject("xmlrch.errmetadata").toString(), ex.getMessage()));
          }
          // metaDataValue needs to be reset to an empty string
          metaDataValue = "";
        }
        setTag(-1);
        break;
      case DATA:
        if (name.equals("data")) {
          state = INITIAL;
          return;
        }

        if (dataMap.get(name) == null) {
          tag = NullTag;
        } else {
          tag = dataMap.get(name);
        }
        switch (tag) {
          case ColTag:
            try {
              idx++;
              if (getNullValue()) {
                insertValue(null);
                setNullValue(false);
              } else {
                insertValue(tempStr);
              }
              // columnValue now need to be reset to the empty string
              columnValue = "";
            } catch (SQLException ex) {
              throw new SAXException(
                  MessageFormat.format(
                      resBundle.handleGetObject("xmlrch.errinsertval").toString(),
                      ex.getMessage()));
            }
            break;
          case RowTag:
            try {
              rs.insertRow();
              rs.moveToCurrentRow();
              rs.next();

              // Making this as the original to turn off the
              // rowInserted flagging
              rs.setOriginalRow();

              applyUpdates();
            } catch (SQLException ex) {
              throw new SAXException(
                  MessageFormat.format(
                      resBundle.handleGetObject("xmlrch.errconstr").toString(), ex.getMessage()));
            }
            break;
          case DelTag:
            try {
              rs.insertRow();
              rs.moveToCurrentRow();
              rs.next();
              rs.setOriginalRow();
              applyUpdates();
              rs.deleteRow();
            } catch (SQLException ex) {
              throw new SAXException(
                  MessageFormat.format(
                      resBundle.handleGetObject("xmlrch.errdel").toString(), ex.getMessage()));
            }
            break;
          case InsTag:
            try {
              rs.insertRow();
              rs.moveToCurrentRow();
              rs.next();
              applyUpdates();
            } catch (SQLException ex) {
              throw new SAXException(
                  MessageFormat.format(
                      resBundle.handleGetObject("xmlrch.errinsert").toString(), ex.getMessage()));
            }
            break;

          case InsDelTag:
            try {
              rs.insertRow();
              rs.moveToCurrentRow();
              rs.next();
              rs.setOriginalRow();
              applyUpdates();
            } catch (SQLException ex) {
              throw new SAXException(
                  MessageFormat.format(
                      resBundle.handleGetObject("xmlrch.errinsdel").toString(), ex.getMessage()));
            }
            break;

          case UpdTag:
            try {
              if (getNullValue()) {
                insertValue(null);
                setNullValue(false);
              } else if (getEmptyStringValue()) {
                insertValue("");
                setEmptyStringValue(false);
              } else {
                updates.add(upd);
              }
            } catch (SQLException ex) {
              throw new SAXException(
                  MessageFormat.format(
                      resBundle.handleGetObject("xmlrch.errupdate").toString(), ex.getMessage()));
            }
            break;

          default:
            break;
        }
      default:
        break;
    }
  }
Exemplo n.º 5
0
 /**
  * Prints a warning message to <code>System.out</code> giving the line number and uri for what
  * caused the warning plus a message explaining the reason for the warning. This method is invoked
  * by the SAX parser.
  *
  * @param err a warning generated by the SAX parser
  */
 public void warning(SAXParseException err) throws SAXParseException {
   System.out.println(
       MessageFormat.format(
           resBundle.handleGetObject("xmlrch.warning").toString(),
           new Object[] {err.getMessage(), err.getLineNumber(), err.getSystemId()}));
 }
Exemplo n.º 6
0
  private void setMetaDataValue(String s) throws SQLException {
    // find out if we are going to be dealing with a null
    boolean nullValue = getNullValue();

    switch (getTag()) {
      case ColumnCountTag:
        md = new RowSetMetaDataImpl();
        idx = 0;

        if (nullValue) {
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        } else {
          md.setColumnCount(getIntegerValue(s));
        }
        break;
      case ColumnDefinitionTag:
        break;
      case ColumnIndexTag:
        idx++;
        break;
      case AutoIncrementTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setAutoIncrement(idx, getBooleanValue(s));
        break;
      case CaseSensitiveTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setCaseSensitive(idx, getBooleanValue(s));
        break;
      case CurrencyTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setCurrency(idx, getBooleanValue(s));
        break;
      case NullableTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setNullable(idx, getIntegerValue(s));
        break;
      case SignedTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setSigned(idx, getBooleanValue(s));
        break;
      case SearchableTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setSearchable(idx, getBooleanValue(s));
        break;
      case ColumnDisplaySizeTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setColumnDisplaySize(idx, getIntegerValue(s));
        break;
      case ColumnLabelTag:
        if (nullValue) md.setColumnLabel(idx, null);
        else md.setColumnLabel(idx, s);
        break;
      case ColumnNameTag:
        if (nullValue) md.setColumnName(idx, null);
        else md.setColumnName(idx, s);

        break;
      case SchemaNameTag:
        if (nullValue) {
          md.setSchemaName(idx, null);
        } else md.setSchemaName(idx, s);
        break;
      case ColumnPrecisionTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setPrecision(idx, getIntegerValue(s));
        break;
      case ColumnScaleTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setScale(idx, getIntegerValue(s));
        break;
      case MetaTableNameTag:
        if (nullValue) md.setTableName(idx, null);
        else md.setTableName(idx, s);
        break;
      case CatalogNameTag:
        if (nullValue) md.setCatalogName(idx, null);
        else md.setCatalogName(idx, s);
        break;
      case ColumnTypeTag:
        if (nullValue)
          throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue1").toString());
        else md.setColumnType(idx, getIntegerValue(s));
        break;
      case ColumnTypeNameTag:
        if (nullValue) md.setColumnTypeName(idx, null);
        else md.setColumnTypeName(idx, s);
        break;
      default:
        // System.out.println("MetaData: Unknown Tag: (" + getTag() + ")");
        break;
    }
  }