Пример #1
0
  public HashMap<String, SchemaTypeInfo> generateSchemaFiles(
      SchemaOutputResolver outputResolver, HashMap<QName, String> additonalGlobalElements) {
    schemaGenerator.generateSchema(
        annotationsProcessor.getTypeInfoClasses(),
        annotationsProcessor.getTypeInfo(),
        annotationsProcessor.getUserDefinedSchemaTypes(),
        annotationsProcessor.getPackageToNamespaceMappings(),
        additonalGlobalElements);
    Project proj = new SchemaModelTopLinkProject();
    XMLContext context = new XMLContext(proj);
    XMLMarshaller marshaller = context.createMarshaller();

    XMLDescriptor schemaDescriptor = (XMLDescriptor) proj.getDescriptor(Schema.class);

    java.util.Collection<Schema> schemas = schemaGenerator.getAllSchemas();
    int schemaCount = 0;
    for (Schema schema : schemas) {
      try {
        NamespaceResolver schemaNamespaces = schema.getNamespaceResolver();
        schemaNamespaces.put(XMLConstants.SCHEMA_PREFIX, "http://www.w3.org/2001/XMLSchema");
        schemaDescriptor.setNamespaceResolver(schemaNamespaces);
        javax.xml.transform.Result target =
            outputResolver.createOutput(schema.getTargetNamespace(), schema.getName());
        marshaller.marshal(schema, target);
        schemaCount++;
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    return schemaGenerator.getSchemaTypeInfo();
  }
Пример #2
0
  public HashMap<String, SchemaTypeInfo> generateSchemaFiles(
      String schemaPath, HashMap<QName, String> additionalElements) throws FileNotFoundException {
    schemaGenerator.generateSchema(
        annotationsProcessor.getTypeInfoClasses(),
        annotationsProcessor.getTypeInfo(),
        annotationsProcessor.getUserDefinedSchemaTypes(),
        annotationsProcessor.getPackageToNamespaceMappings(),
        additionalElements);
    Project proj = new SchemaModelTopLinkProject();
    XMLContext context = new XMLContext(proj);
    XMLMarshaller marshaller = context.createMarshaller();
    XMLDescriptor schemaDescriptor = (XMLDescriptor) proj.getDescriptor(Schema.class);

    java.util.Collection<Schema> schemas = schemaGenerator.getAllSchemas();
    int schemaCount = 0;
    for (Schema schema : schemas) {
      File file = new File(schemaPath + "/" + schema.getName());
      NamespaceResolver schemaNamespaces = schema.getNamespaceResolver();
      schemaNamespaces.put(XMLConstants.SCHEMA_PREFIX, "http://www.w3.org/2001/XMLSchema");
      schemaDescriptor.setNamespaceResolver(schemaNamespaces);
      marshaller.marshal(schema, new FileOutputStream(file));
      schemaCount++;
    }
    return schemaGenerator.getSchemaTypeInfo();
  }