Java 类javax.xml.bind.SchemaOutputResolver 实例源码

项目:jmx-prometheus-exporter    文件:SchemaGenerator.java   
public static @NotNull Optional<Schema> load(@NotNull JAXBContext context) {
  try {
    final List<ByteArrayOutputStream> outputs = new ArrayList<>();
    context.generateSchema(new SchemaOutputResolver() {
      @Override
      public @NotNull Result createOutput(@NotNull String namespace, @NotNull String suggestedFileName) {
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        outputs.add(output);
        final StreamResult result = new StreamResult(output);
        result.setSystemId("");
        return result;
      }
    });
    return Optional.ofNullable(
        SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
            .newSchema(outputs.stream()
                .map(ByteArrayOutputStream::toByteArray)
                .map(ByteArrayInputStream::new)
                .map(input -> new StreamSource(input, ""))
                .toArray(StreamSource[]::new))
    );
  } catch (IOException | SAXException e) {
    logger.error("Failed to load schema", e);
    return Optional.empty();
  }
}
项目:jmx-prometheus-exporter    文件:SchemaGenerator.java   
private void generate() {
  try {
    JAXBContext.newInstance(Configuration.class).generateSchema(new SchemaOutputResolver() {
      @Override
      public @NotNull Result createOutput(@NotNull String namespace, @NotNull String suggestedFileName) throws MalformedURLException {
        final File file = new File(filename);
        final StreamResult result = new StreamResult(file);
        result.setSystemId(file.toURI().toURL().toString());
        return result;
      }
    });
    logger.info("Schema successfully generated to " + filename);
  } catch (JAXBException | IOException e) {
    logger.error("Failed to generate schema", e);
  }
}
项目:FinanceAnalytics    文件:SchemaGenerator.java   
private static DOMResult extractSchemaResult(JAXBContext ctx) throws IOException {

    final Set<DOMResult> resultWrapper = new HashSet<>();

    ctx.generateSchema(new SchemaOutputResolver() {
      @Override
      public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
        DOMResult result = new DOMResult();
        result.setSystemId(suggestedFileName);
        resultWrapper.add(result);
        return result;
      }
    });

    return resultWrapper.iterator().next();
  }
项目:msdapl    文件:SchemaGenerator.java   
public static void main(String[] args) throws IOException, JAXBException {

    // specify where the generated XML schema will be created
    String schemaDir = "/Users/silmaril/WORK/UW/Workspaces/MyEclipse8.5/MSDaPlUploadQueue/";
    final File dir = new File(schemaDir);

    // create a JAXBContext for the MsJob class
    JAXBContext ctx = JAXBContext.newInstance(MsJob.class);
    // generate an XML schema from the annotated object model; create it
    // in the dir specified earlier under the default name, schema1.xsd
    ctx.generateSchema(new SchemaOutputResolver() {
           @Override
           public Result createOutput(String namespaceUri, String schemaName) throws IOException {
                return new StreamResult(new File(dir, "msjob_schema.xsd"));
           }
       });
}
项目:Telepathology    文件:SchemaGenerator.java   
public static void main(String [] args)
{
    try
    {
        Class<?>[] classes = new Class[3]; 
        classes[0] = PathologyCaseUpdateAttributeResultType.class;
        classes[1] = PathologyAcquisitionSiteType.class;
        classes[2] = PathologyReadingSiteType.class;
        JAXBContext jaxbContext = JAXBContext.newInstance(classes);

        SchemaOutputResolver sor = new MySchemaOutputResolver();
        jaxbContext.generateSchema(sor);


    }
    catch(Exception ex)
    {
        ex.printStackTrace();
    }
}
项目:artifactory    文件:JaxbHelper.java   
public void generateSchema(final OutputStream stream, final Class<T> clazz, final String namespace) {
    try {
        JAXBContext context = JAXBContext.newInstance(clazz);
        context.generateSchema(new SchemaOutputResolver() {
            @Override
            public Result createOutput(String namespaceUri, String suggestedFileName)
                    throws IOException {
                StreamResult result = new StreamResult(stream);
                result.setSystemId(namespace);
                return result;
            }
        });
    } catch (Exception e) {
        throw new RuntimeException("Failed to write object to stream.", e);
    }
}
项目:cukes    文件:WebServiceConfiguration.java   
@Bean
public XsdSchemaCollection schemaCollection() throws JAXBException, IOException {
    JAXBContext context = JAXBContext.newInstance(CalculatorRequest.class, CalculatorResponse.class);
    List<ByteArrayOutputStream> outs = new ArrayList<>();
    context.generateSchema(new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            outs.add(out);
            StreamResult result = new StreamResult(out);
            result.setSystemId(suggestedFileName);
            return result;
        }
    });
    Resource[] resources = outs.stream().
        map(ByteArrayOutputStream::toByteArray).
        map(InMemoryResource::new).
        collect(Collectors.toList()).
        toArray(new Resource[]{});
    return new CommonsXsdSchemaCollection(resources);
}
项目:cxf-plus    文件:JAXBUtils.java   
public static List<DOMResult> generateJaxbSchemas(
    JAXBContext context, final Map<String, DOMResult> builtIns) throws IOException {
    final List<DOMResult> results = new ArrayList<DOMResult>();

    context.generateSchema(new SchemaOutputResolver() {
        @Override
        public Result createOutput(String ns, String file) throws IOException {
            DOMResult result = new DOMResult();

            if (builtIns.containsKey(ns)) {
                DOMResult dr = builtIns.get(ns);
                result.setSystemId(dr.getSystemId());
                results.add(dr);
                return result;
            }
            result.setSystemId(file);
            results.add(result);
            return result;
        }
    });

    return results;
}
项目:web-feature-service    文件:WFSConfigSchemaWriter.java   
public static void main(String[] args) throws Exception {
    System.out.print("Generting XML schema in " + Constants.CONFIG_SCHEMA_FILE + "... ");

    JAXBContext ctx = JAXBContext.newInstance(WFSConfig.class);
    ctx.generateSchema(new SchemaOutputResolver() {

        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            File file;

            if (namespaceUri.equals("http://www.3dcitydb.org/importer-exporter/config"))
                file = new File(Constants.CONFIG_SCHEMA_FILE);
            else
                file = new File(Constants.CONFIG_SCHEMA_PATH + "/ows/" + suggestedFileName);

            file.getAbsoluteFile().getParentFile().mkdirs();

            StreamResult res = new StreamResult();
            res.setSystemId(file.toURI().toString());
            return res;
        }

    });

    System.out.println("finished.");
}
项目:importer-exporter    文件:SchemaMappingWriter.java   
public static void main(String[] args) throws Exception {
    final File file = new File("src/main/resources/org/citydb/database/schema/3dcitydb-schema.xsd");
    System.out.print("Generting XML schema in " + file.getAbsolutePath() + "...");

    JAXBContext ctx = JAXBContext.newInstance(SchemaMapping.class);
    ctx.generateSchema(new SchemaOutputResolver() {

        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {              
            StreamResult res = new StreamResult(file);
            res.setSystemId(file.toURI().toString());
            return res;
        }

    });

    System.out.println("finished.");
}
项目:database-metadata-bind    文件:JaxbTest.java   
private static void storeSchema(
        final JAXBContext context,
        final BiFunction<String, String, File> locator)
        throws IOException {
    context.generateSchema(new SchemaOutputResolver() {
        @Override
        public Result createOutput(final String namespaceUri,
                                   final String suggestedFileName)
                throws IOException {
            final File file
                    = locator.apply(namespaceUri, suggestedFileName);
            final Result output = new StreamResult(file);
            //output.setSystemId(suggestedFileName);
            return output;
        }
    });
}
项目:common-biorepository-model    文件:SchemaGenerator.java   
public void generateSchema() {
Class[] classes = new Class[1];
classes[0] = CbmNode.class;

JAXBContext jaxbContext;
try {
    jaxbContext = JAXBContext.newInstance(classes);
    SchemaOutputResolver sor = new MySchemaOutputResolver();
    jaxbContext.generateSchema(sor);
} catch (Throwable e) {
    System.err
        .println("An error has occurred while generating the schema: "
            + e.getMessage());
    e.printStackTrace();
}
System.out
    .println("Schema generation complete.  \nThe schema has been written to "
        + XML_SCHEMA);
   }
项目:common-biorepository-model    文件:SchemaGenerator.java   
public void generateSchema() {
Class[] classes = new Class[1];
classes[0] = CbmNode.class;

JAXBContext jaxbContext;
try {
    jaxbContext = JAXBContext.newInstance(classes);
    SchemaOutputResolver sor = new MySchemaOutputResolver();
    jaxbContext.generateSchema(sor);
} catch (Throwable e) {
    System.err
        .println("An error has occurred while generating the schema: "
            + e.getMessage());
    e.printStackTrace();
}
System.out
    .println("Schema generation complete.  \nThe schema has been written to "
        + XML_SCHEMA);
   }
项目:nadia-model    文件:DialogModel.java   
public void generateSchema(){
    JAXBContext jc;
    try {
        jc = JAXBContext.newInstance(Dialog.class, DialogModel.class);

        jc.generateSchema(new SchemaOutputResolver() {
                @Override
                public Result createOutput(String namespaceUri, String suggestedFileName)
                        throws IOException {
                    StreamResult result = new StreamResult(new FileWriter(suggestedFileName));
                    result.setSystemId(suggestedFileName);
                    return result;
                }
            });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:maps4cim    文件:Serializer.java   
/**
    * Generates a schema object for the specified class
    * @param clazz the class to generate the schema for
    * @return the generated schema object
    * @throws JAXBException
    * @throws IOException
    * @throws SAXException
    */
   @SuppressWarnings("rawtypes")
public static Schema generateSchema(Class clazz) throws JAXBException, IOException, SAXException {
       // get context to write schema for
       JAXBContext context = JAXBContext.newInstance(clazz);

       // write schema in DOMResult using SchemaOutputResolver
       final List<DOMResult> results = new ArrayList<DOMResult>();
       context.generateSchema(new SchemaOutputResolver() {
           @Override
           public Result createOutput(String ns, String file) throws IOException {
               DOMResult result = new DOMResult();
               result.setSystemId(file);
               results.add(result);
               return result;
           }
       });

       // transform domresult in source
       DOMResult res = results.get(0);
       DOMSource src = new DOMSource(res.getNode());

       // write schema object from source
       return sf.newSchema(src);
   }
项目:windup    文件:DefaultToolingXMLService.java   
@Override
public void generateSchema(Path outputPath)
{
    try
    {
        JAXBContext jaxbContext = getJAXBContext();
        SchemaOutputResolver sor = new SchemaOutputResolver()
        {
            @Override
            public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException
            {
                StreamResult result = new StreamResult();
                result.setSystemId(outputPath.toUri().toString());
                return result;
            }
        };
        jaxbContext.generateSchema(sor);
    }
    catch (JAXBException | IOException e)
    {
        throw new WindupException("Error generating Windup schema due to: " + e.getMessage(), e);
    }
}
项目:OpenJSharp    文件:ConfigReader.java   
private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) {
    File baseDir = new File(xmlpath, config.getBaseDir().getPath());
    SchemaOutputResolverImpl outResolver = new SchemaOutputResolverImpl (baseDir);

    for( Schema schema : (List<Schema>)config.getSchema() ) {
        String namespace = schema.getNamespace();
        File location = schema.getLocation();
        outResolver.addSchemaInfo(namespace,location);
    }
    return outResolver;
}
项目:openjdk-jdk10    文件:ConfigReader.java   
private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) {
    File baseDir = new File(xmlpath, config.getBaseDir().getPath());
    SchemaOutputResolverImpl outResolver = new SchemaOutputResolverImpl (baseDir);

    for( Schema schema : (List<Schema>)config.getSchema() ) {
        String namespace = schema.getNamespace();
        File location = schema.getLocation();
        outResolver.addSchemaInfo(namespace,location);
    }
    return outResolver;
}
项目:openjdk9    文件:ConfigReader.java   
private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) {
    File baseDir = new File(xmlpath, config.getBaseDir().getPath());
    SchemaOutputResolverImpl outResolver = new SchemaOutputResolverImpl (baseDir);

    for( Schema schema : (List<Schema>)config.getSchema() ) {
        String namespace = schema.getNamespace();
        File location = schema.getLocation();
        outResolver.addSchemaInfo(namespace,location);
    }
    return outResolver;
}
项目:v8fs    文件:JAXBSerializer.java   
protected void generateSchema(File dir, String name) throws IOException {
    jaxbContext.generateSchema(new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            File schFile = new File(dir, name + ".xsd");
            StreamResult result = new StreamResult(schFile);
            result.setSystemId(schFile.toURI().toURL().toString());
            return result;
        }
    });
}
项目:lookaside_java-1.8.0-openjdk    文件:ConfigReader.java   
private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) {
    File baseDir = new File(xmlpath, config.getBaseDir().getPath());
    SchemaOutputResolverImpl outResolver = new SchemaOutputResolverImpl (baseDir);

    for( Schema schema : (List<Schema>)config.getSchema() ) {
        String namespace = schema.getNamespace();
        File location = schema.getLocation();
        outResolver.addSchemaInfo(namespace,location);
    }
    return outResolver;
}
项目:incubator-taverna-server    文件:JaxbSanityTest.java   
@Before
public void init() {
    schema = new StringWriter();
    sink = new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri,
                String suggestedFileName) throws IOException {
            StreamResult sr = new StreamResult(schema);
            sr.setSystemId("/dev/null");
            return sr;
        }
    };
}
项目:incubator-taverna-server    文件:TestUR.java   
@Before
public void setUp() throws Exception {
    writer = new StringWriter();
    sink = new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri,
                String suggestedFileName) throws IOException {
            StreamResult sr = new StreamResult(writer);
            sr.setSystemId("/dev/null");
            return sr;
        }
    };
    Assert.assertNull(null);// Shut up, Eclipse!
    Assert.assertEquals("", result());
}
项目:incubator-taverna-server    文件:JaxbSanityTest.java   
@Before
public void init() {
    schema = new StringWriter();
    sink = new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri,
                String suggestedFileName) throws IOException {
            StreamResult sr = new StreamResult(schema);
            sr.setSystemId("/dev/null");
            return sr;
        }
    };
    assertEquals("", schema());
}
项目:proarc    文件:WorkflowProfilesTest.java   
public void testCreateSchema() throws Exception {
    JAXBContext jctx = JAXBContext.newInstance(WorkflowDefinition.class);
    final Map<String, StreamResult> schemas = new HashMap<String, StreamResult>();
    jctx.generateSchema(new SchemaOutputResolver() {

        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            StreamResult sr = new StreamResult(new StringWriter());
            sr.setSystemId(namespaceUri);
            schemas.put(namespaceUri, sr);
            return sr;
        }
    });
    System.out.println(schemas.get(WorkflowProfileConsts.NS_WORKFLOW_V1).getWriter().toString());
}
项目:infobip-open-jdk-8    文件:ConfigReader.java   
private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) {
    File baseDir = new File(xmlpath, config.getBaseDir().getPath());
    SchemaOutputResolverImpl outResolver = new SchemaOutputResolverImpl (baseDir);

    for( Schema schema : (List<Schema>)config.getSchema() ) {
        String namespace = schema.getNamespace();
        File location = schema.getLocation();
        outResolver.addSchemaInfo(namespace,location);
    }
    return outResolver;
}
项目:AutomotiveServiceBus    文件:ServiceRegistryImpl.java   
public static void main(String[] args) throws JAXBException, IOException {
    JAXBContext jaxbContext = JAXBContext.newInstance(ServiceImpl.class,
            ServiceList.class, ParameterImpl.class,
            ParameterReference.class, NumericParameterImpl.class,
            StateParameterImpl.class, SwitchParameterImpl.class,
            StringParameterImpl.class);
    SchemaOutputResolver sor = new MySchemaOutputResolver();
    jaxbContext.generateSchema(sor);
}
项目:cxf-plus    文件:JAXBContextImpl.java   
/**
 * Used for testing.
 */
public SchemaOutputResolver createTestResolver() {
    return new SchemaOutputResolver() {
        public Result createOutput(String namespaceUri, String suggestedFileName) {
            SAXResult r = new SAXResult(new DefaultHandler());
            r.setSystemId(suggestedFileName);
            return r;
        }
    };
}
项目:jaxb2-basics    文件:DynamicSchemaTest.java   
@Test(expected = MarshalException.class)
public void generatesAndUsesSchema() throws JAXBException, IOException,
        SAXException {
    final JAXBContext context = JAXBContext.newInstance(A.class);
    final DOMResult result = new DOMResult();
    result.setSystemId("schema.xsd");
    context.generateSchema(new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri,
                String suggestedFileName) {
            return result;
        }
    });

    @SuppressWarnings("deprecation")
    final SchemaFactory schemaFactory = SchemaFactory
            .newInstance(WellKnownNamespace.XML_SCHEMA);
    final Schema schema = schemaFactory.newSchema(new DOMSource(result
            .getNode()));

    final Marshaller marshaller = context.createMarshaller();
    marshaller.setSchema(schema);
    // Works
    marshaller.marshal(new A("works"), System.out);
    // Fails
    marshaller.marshal(new A(null), System.out);
}
项目:dohko    文件:GenerateDeploymentSchema.java   
public static void main(String[] args) throws Exception
{
    JAXBContext jc = JAXBContext.newInstance(Deployment.class);
    jc.generateSchema(new SchemaOutputResolver()
    {
        @Override
        public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException
        {
            return new StreamResult(suggestedFileName);
        }
    });
}
项目:OLD-OpenJDK8    文件:ConfigReader.java   
private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) {
    File baseDir = new File(xmlpath, config.getBaseDir().getPath());
    SchemaOutputResolverImpl outResolver = new SchemaOutputResolverImpl (baseDir);

    for( Schema schema : (List<Schema>)config.getSchema() ) {
        String namespace = schema.getNamespace();
        File location = schema.getLocation();
        outResolver.addSchemaInfo(namespace,location);
    }
    return outResolver;
}
项目:settlers-remake    文件:DevelopmentGenerateJaxbSchema.java   
public static void main(String[] args) throws JAXBException, IOException {
    JAXBContext jaxbContext = JAXBContext.newInstance(Presets.class);
    SchemaOutputResolver sor = new SchemaOutputResolver() {

        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            File file = new File("src/jsettlers/mapcreator/presetloader/preset.xsd");
            StreamResult result = new StreamResult(file);
            result.setSystemId(file.toURI().toURL().toString());
            return result;
        }
    };
    jaxbContext.generateSchema(sor);
    System.out.println("Finished!");
}
项目:ASWProject    文件:XmlSchemaGenerator.java   
private static void writeXmlSchema(Class xmlRoot) throws JAXBException, IOException {
    JAXBContext context = JAXBContext.newInstance(xmlRoot);
    context.generateSchema(new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            return new StreamResult(new File("/Users/mattia",suggestedFileName));
        }
    });
}
项目:wso2-axis2    文件:JaxbSchemaGenerator.java   
protected List<DOMResult> generateJaxbSchemas(JAXBContext context) throws IOException {
    final List<DOMResult> results = new ArrayList<DOMResult>();

    context.generateSchema(new SchemaOutputResolver() {
        @Override
        public Result createOutput(String ns, String file) throws IOException {
            DOMResult result = new DOMResult();
            result.setSystemId(file);
            results.add(result);
            return result;
        }
    });

    return results;
}
项目:ProfiSounder    文件:XSDCreator.java   
public static void main(String[] args) {
    JAXBContext context;
    try {
        context = JAXBContext.newInstance(SounderConfig.class);

        SchemaOutputResolver sor = new PSSchemaOutputResolver("config_schema.xsd");
        context.generateSchema(sor);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:aludratest    文件:TestData.java   
private static void generateXmlSchema(JAXBContext ctx) throws IOException {
    SchemaOutputResolver resolver = new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            File file = new File(suggestedFileName); // NOSONAR
            StreamResult result = new StreamResult(file);
            result.setSystemId(file);
            return result;
        }
    };
    ctx.generateSchema(resolver);
}
项目:edal-java    文件:CatalogueConfig.java   
public void generateSchema(final String path) throws IOException, JAXBException {
    JAXBContext context = JAXBContext.newInstance(this.getClass());
    context.generateSchema(new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName)
                throws IOException {
            return new StreamResult(new File(path, suggestedFileName));
        }
    });
}
项目:openjdk-icedtea7    文件:JAXBContextImpl.java   
/**
 * Used for testing.
 */
public SchemaOutputResolver createTestResolver() {
    return new SchemaOutputResolver() {
        public Result createOutput(String namespaceUri, String suggestedFileName) {
            SAXResult r = new SAXResult(new DefaultHandler());
            r.setSystemId(suggestedFileName);
            return r;
        }
    };
}
项目:openjdk-icedtea7    文件:ConfigReader.java   
private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) {
    File baseDir = new File(xmlpath, config.getBaseDir().getPath());
    SchemaOutputResolverImpl schemaOutputResolver = new SchemaOutputResolverImpl (baseDir);

    for( Schema schema : (List<Schema>)config.getSchema() ) {
        String namespace = schema.getNamespace();
        File location = schema.getLocation();
        schemaOutputResolver.addSchemaInfo(namespace,location);
    }
    return schemaOutputResolver;
}
项目:wadl-tools    文件:SingleType.java   
private String tryBuildSchemaFromJaxbAnnotatedClass() throws JAXBException, IOException {
    final StringWriter stringWriter = new StringWriter();
    JAXBContext.newInstance(clazz).generateSchema(new SchemaOutputResolver() {
        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            final StreamResult result = new StreamResult(stringWriter);
            result.setSystemId("schema" + clazz.getSimpleName());
            return result;
        }
    });

    return stringWriter.toString();
}