Example #1
0
  public static void marshell(VDBMetaData vdb, OutputStream out)
      throws XMLStreamException, IOException {
    XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(out);

    writer.writeStartDocument();
    writer.writeStartElement(Element.VDB.getLocalName());
    writeAttribute(writer, Element.NAME.getLocalName(), vdb.getName());
    writeAttribute(writer, Element.VERSION.getLocalName(), String.valueOf(vdb.getVersion()));

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

    for (VDBImport vdbImport : vdb.getVDBImports()) {
      writer.writeStartElement(Element.IMPORT_VDB.getLocalName());
      writeAttribute(writer, Element.NAME.getLocalName(), vdbImport.getName());
      writeAttribute(
          writer, Element.VERSION.getLocalName(), String.valueOf(vdbImport.getVersion()));
      writeAttribute(
          writer,
          Element.IMPORT_POLICIES.getLocalName(),
          String.valueOf(vdbImport.isImportDataPolicies()));
      writer.writeEndElement();
    }

    // models
    Collection<ModelMetaData> models = vdb.getModelMetaDatas().values();
    for (ModelMetaData model : models) {
      writeModel(writer, model);
    }

    // override translators
    for (Translator translator : vdb.getOverrideTranslators()) {
      writeTranslator(writer, translator);
    }

    // data-roles
    for (DataPolicy dp : vdb.getDataPolicies()) {
      writeDataPolicy(writer, dp);
    }

    // entry
    // designer only
    for (EntryMetaData em : vdb.getEntries()) {
      writer.writeStartElement(Element.ENTRY.getLocalName());
      writeAttribute(writer, Element.PATH.getLocalName(), em.getPath());
      if (em.getDescription() != null) {
        writeElement(writer, Element.DESCRIPTION, em.getDescription());
      }
      writeProperties(writer, em.getProperties());
      writer.writeEndElement();
    }

    writer.writeEndElement();
    writer.writeEndDocument();
    writer.close();
    out.close();
  }
Example #2
0
 private static void parseVDB(XMLStreamReader reader, VDBMetaData vdb) throws XMLStreamException {
   while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
     Element element = Element.forName(reader.getLocalName());
     switch (element) {
       case DESCRIPTION:
         vdb.setDescription(reader.getElementText());
         break;
       case PROPERTY:
         parseProperty(reader, vdb);
         break;
       case MODEL:
         ModelMetaData model = new ModelMetaData();
         parseModel(reader, model);
         vdb.addModel(model);
         break;
       case TRANSLATOR:
         VDBTranslatorMetaData translator = new VDBTranslatorMetaData();
         parseTranslator(reader, translator);
         vdb.addOverideTranslator(translator);
         break;
       case DATA_ROLE:
         DataPolicyMetadata policy = new DataPolicyMetadata();
         parseDataRole(reader, policy);
         vdb.addDataPolicy(policy);
         break;
       case IMPORT_VDB:
         VDBImportMetadata vdbImport = new VDBImportMetadata();
         Properties props = getAttributes(reader);
         vdbImport.setName(props.getProperty(Element.NAME.getLocalName()));
         vdbImport.setVersion(Integer.parseInt(props.getProperty(Element.VERSION.getLocalName())));
         vdbImport.setImportDataPolicies(
             Boolean.parseBoolean(
                 props.getProperty(Element.IMPORT_POLICIES.getLocalName(), "true")));
         vdb.getVDBImports().add(vdbImport);
         ignoreTillEnd(reader);
         break;
       case ENTRY:
         EntryMetaData entry = new EntryMetaData();
         parseEntry(reader, entry);
         vdb.getEntries().add(entry);
         break;
       default:
         throw new XMLStreamException(
             AdminPlugin.Util.gs(
                 "unexpected_element5",
                 reader.getName(),
                 Element.DESCRIPTION.getLocalName(),
                 Element.PROPERTY.getLocalName(),
                 Element.MODEL.getLocalName(),
                 Element.TRANSLATOR.getLocalName(),
                 Element.DATA_ROLE.getLocalName()),
             reader.getLocation());
     }
   }
 }