Ejemplo n.º 1
0
  public void setOption(Attributes attributes) {
    // Look thru supported model elements in reverse order to
    // find one that this option statement applies to.

    String key = attributes.getValue("key");
    String value = attributes.getValue("value");
    if (currUnique != null) {
      currUnique.addOption(key, value);
    } else if (currIndex != null) {
      currIndex.addOption(key, value);
    } else if (currFK != null) {
      currFK.addOption(key, value);
    } else if (currColumn != null) {
      currColumn.addOption(key, value);
    } else if (currTable != null) {
      currTable.addOption(key, value);
    } else { // Must be a db level option.
      database.addOption(key, value);
    }
  }
Ejemplo n.º 2
0
  /**
   * Handles opening elements of the xml file.
   *
   * @param uri
   * @param localName The local name (without prefix), or the empty string if Namespace processing
   *     is not being performed.
   * @param rawName The qualified name (with prefix), or the empty string if qualified names are not
   *     available.
   * @param attributes The specified or defaulted attributes
   */
  public void startElement(String uri, String localName, String rawName, Attributes attributes)
      throws SAXException {
    try {
      if (rawName.equals("database")) {
        if (isExternalSchema) {
          currentPackage = attributes.getValue("package");
          if (currentPackage == null) {
            currentPackage = defaultPackage;
          }
        } else {
          database.loadFromXML(attributes);
          if (database.getPackage() == null) {
            database.setPackage(defaultPackage);
          }
        }
      } else if (rawName.equals("external-schema")) {
        String xmlFile = attributes.getValue("filename");
        if (xmlFile.charAt(0) != '/') {
          File f = new File(currentXmlFile);
          xmlFile = new File(f.getParent(), xmlFile).getPath();
        }

        // put current state onto the stack
        ParseStackElement.pushState(this);

        isExternalSchema = true;

        parseFile(xmlFile);
        // get the last state from the stack
        ParseStackElement.popState(this);
      } else if (rawName.equals("domain")) {
        Domain domain = new Domain();
        domain.loadFromXML(attributes, database.getPlatform());
        database.addDomain(domain);
      } else if (rawName.equals("table")) {
        currTable = database.addTable(attributes);
        if (isExternalSchema) {
          currTable.setForReferenceOnly(true);
          currTable.setPackage(currentPackage);
        }
      } else if (rawName.equals("view")) {
        currView = database.addView(attributes);
      } else if (rawName.equals("sequence")) {
        currSequence = database.addSequence(attributes);
      } else if (rawName.equals("column")) {
        currColumn = currTable.addColumn(attributes);
      } else if (rawName.equals("inheritance")) {
        currColumn.addInheritance(attributes);
      } else if (rawName.equals("foreign-key")) {
        currFK = currTable.addForeignKey(attributes);
      } else if (rawName.equals("reference")) {
        currFK.addReference(attributes);
      } else if (rawName.equals("index")) {
        currIndex = currTable.addIndex(attributes);
      } else if (rawName.equals("index-column")) {
        currIndex.addColumn(attributes);
      } else if (rawName.equals("unique")) {
        currUnique = currTable.addUnique(attributes);
      } else if (rawName.equals("unique-column")) {
        currUnique.addColumn(attributes);
      } else if (rawName.equals("id-method-parameter")) {
        currTable.addIdMethodParameter(attributes);
      } else if (rawName.equals("option")) {
        setOption(attributes);
      }
    } catch (Exception e) {
      throw new SAXException(e);
    }
  }