Exemplo n.º 1
0
  private static void parseModel(XMLStreamReader reader, ModelMetaData model)
      throws XMLStreamException {
    Properties props = getAttributes(reader);
    model.setName(props.getProperty(Element.NAME.getLocalName()));
    model.setModelType(props.getProperty(Element.TYPE.getLocalName(), "PHYSICAL"));
    model.setVisible(
        Boolean.parseBoolean(props.getProperty(Element.VISIBLE.getLocalName(), "true")));
    model.setPath(props.getProperty(Element.PATH.getLocalName()));

    while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
      Element element = Element.forName(reader.getLocalName());
      switch (element) {
        case DESCRIPTION:
          model.setDescription(reader.getElementText());
          break;
        case PROPERTY:
          parseProperty(reader, model);
          break;
        case SOURCE:
          Properties sourceProps = getAttributes(reader);
          String name = sourceProps.getProperty(Element.NAME.getLocalName());
          String translatorName =
              sourceProps.getProperty(Element.SOURCE_TRANSLATOR_NAME_ATTR.getLocalName());
          String connectionName =
              sourceProps.getProperty(Element.SOURCE_CONNECTION_JNDI_NAME_ATTR.getLocalName());
          model.addSourceMapping(name, translatorName, connectionName);
          ignoreTillEnd(reader);
          break;
        case VALIDATION_ERROR:
          Properties validationProps = getAttributes(reader);
          String msg = reader.getElementText();
          String severity =
              validationProps.getProperty(Element.VALIDATION_SEVERITY_ATTR.getLocalName());
          String path = validationProps.getProperty(Element.PATH.getLocalName());
          Message ve = new Message(Severity.valueOf(severity), msg);
          ve.setPath(path);
          model.addMessage(ve);
          break;
        case METADATA:
          Properties metdataProps = getAttributes(reader);
          String type = metdataProps.getProperty(Element.TYPE.getLocalName(), "DDL");
          String schema = reader.getElementText();
          model.setSchemaSourceType(type);
          model.setSchemaText(schema);
          break;
        default:
          throw new XMLStreamException(
              AdminPlugin.Util.gs(
                  "unexpected_element5",
                  reader.getName(),
                  Element.DESCRIPTION.getLocalName(),
                  Element.PROPERTY.getLocalName(),
                  Element.SOURCE.getLocalName(),
                  Element.METADATA.getLocalName(),
                  Element.VALIDATION_ERROR.getLocalName()),
              reader.getLocation());
      }
    }
  }
Exemplo n.º 2
0
  private static void writeModel(final XMLStreamWriter writer, ModelMetaData model)
      throws XMLStreamException {
    writer.writeStartElement(Element.MODEL.getLocalName());
    writeAttribute(writer, Element.NAME.getLocalName(), model.getName());
    writeAttribute(writer, Element.TYPE.getLocalName(), model.getModelType().name());

    writeAttribute(writer, Element.VISIBLE.getLocalName(), String.valueOf(model.isVisible()));
    writeAttribute(writer, Element.PATH.getLocalName(), model.getPath());

    if (model.getDescription() != null) {
      writeElement(writer, Element.DESCRIPTION, model.getDescription());
    }
    writeProperties(writer, model.getProperties());

    // source mappings
    for (SourceMappingMetadata source : model.getSourceMappings()) {
      writer.writeStartElement(Element.SOURCE.getLocalName());
      writeAttribute(writer, Element.NAME.getLocalName(), source.getName());
      writeAttribute(
          writer, Element.SOURCE_TRANSLATOR_NAME_ATTR.getLocalName(), source.getTranslatorName());
      writeAttribute(
          writer,
          Element.SOURCE_CONNECTION_JNDI_NAME_ATTR.getLocalName(),
          source.getConnectionJndiName());
      writer.writeEndElement();
    }

    if (model.getSchemaSourceType() != null) {
      writer.writeStartElement(Element.METADATA.getLocalName());
      writeAttribute(writer, Element.TYPE.getLocalName(), model.getSchemaSourceType());
      writer.writeCData(model.getSchemaText());
      writer.writeEndElement();
    }

    // model validation errors
    for (Message ve : model.getMessages(false)) {
      writer.writeStartElement(Element.VALIDATION_ERROR.getLocalName());
      writeAttribute(
          writer, Element.VALIDATION_SEVERITY_ATTR.getLocalName(), ve.getSeverity().name());
      writeAttribute(writer, Element.PATH.getLocalName(), ve.getPath());
      writer.writeCharacters(ve.getValue());
      writer.writeEndElement();
    }
    writer.writeEndElement();
  }