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

下面列出了怎么用javax.xml.bind.SchemaOutputResolver的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: importer-exporter   文件: QuerySchemaWriter.java
public static void main(String[] args) throws Exception {
	Path configFile = Paths.get("src/main/resources/org/citydb/config/schema/query.xsd");
	System.out.print("Generting XML schema in " + configFile.toAbsolutePath() + "... ");
	
	JAXBContext context = JAXBContext.newInstance(QueryWrapper.class);
	context.generateSchema(new SchemaOutputResolver() {
		@Override
		public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
			if (ConfigUtil.CITYDB_CONFIG_NAMESPACE_URI.equals(namespaceUri)) {
				Files.createDirectories(configFile.getParent());
				StreamResult res = new StreamResult();
				res.setSystemId(configFile.toUri().toString());

				return res;
			} else
				return null;
		}
		
	});
	
	System.out.println("finished.");
}
 
源代码2 项目: 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);
    }
}
 
源代码3 项目: cxf   文件: JAXBUtils.java
public static List<DOMResult> generateJaxbSchemas(
    JAXBContext context, final Map<String, DOMResult> builtIns) throws IOException {
    final List<DOMResult> results = new ArrayList<>();

    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;
}
 
源代码4 项目: 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);
}
 
源代码5 项目: 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();
}
 
源代码6 项目: TencentKona-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;
}
 
源代码7 项目: recheck   文件: ApprovalsUtil.java
private static String generateSchema( final Class<?> type ) throws JAXBException, IOException {
	final StringWriter stringWriter = new StringWriter();

	final JAXBContext jaxbContext =
			JAXBContextFactory.createContext( new Class<?>[] { type }, Collections.emptyMap() );
	jaxbContext.generateSchema( new SchemaOutputResolver() {
		@Override
		public final Result createOutput( final String namespaceURI, final String suggestedFileName )
				throws IOException {
			final StreamResult result = new StreamResult( stringWriter );
			result.setSystemId( suggestedFileName );
			return result;
		}
	} );

	return stringWriter.toString();
}
 
源代码8 项目: aion-germany   文件: SchemaGen.java
public static void main(String[] args) throws Exception {
	final File baseDir = new File("./data/static_data");

	class MySchemaOutputResolver extends SchemaOutputResolver {

		@Override
		public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
			return new StreamResult(new File(baseDir, "static_data1.xsd"));
		}
	}
	JAXBContext context = JAXBContext.newInstance(StaticData.class);
	context.generateSchema(new MySchemaOutputResolver());
}
 
源代码9 项目: openjdk-jdk8u   文件: 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;
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: 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;
}
 
源代码11 项目: openjdk-jdk9   文件: 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;
}
 
源代码12 项目: hottub   文件: 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;
}
 
源代码13 项目: openjdk-8-source   文件: 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;
}
 
源代码14 项目: openjdk-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;
}
 
源代码15 项目: 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());
}
 
源代码16 项目: 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);
}
 
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!");
}
 
源代码18 项目: TencentKona-8   文件: JAXBRIContextWrapper.java
@Override
public void generateSchema(SchemaOutputResolver outputResolver)
        throws IOException {
    context.generateSchema(outputResolver);
}
 
源代码19 项目: TencentKona-8   文件: XmlSchemaGenerator.java
/**
 * Write out the schema documents.
 */
public void write(SchemaOutputResolver resolver, ErrorListener errorListener) throws IOException {
    if(resolver==null)
        throw new IllegalArgumentException();

    if(logger.isLoggable(Level.FINE)) {
        // debug logging to see what's going on.
        logger.log(Level.FINE,"Writing XML Schema for "+toString(),new StackRecorder());
    }

    // make it fool-proof
    resolver = new FoolProofResolver(resolver);
    this.errorListener = errorListener;

    Map<String, String> schemaLocations = types.getSchemaLocations();

    Map<Namespace,Result> out = new HashMap<Namespace,Result>();
    Map<Namespace,String> systemIds = new HashMap<Namespace,String>();

    // we create a Namespace object for the XML Schema namespace
    // as a side-effect, but we don't want to generate it.
    namespaces.remove(WellKnownNamespace.XML_SCHEMA);

    // first create the outputs for all so that we can resolve references among
    // schema files when we write
    for( Namespace n : namespaces.values() ) {
        String schemaLocation = schemaLocations.get(n.uri);
        if(schemaLocation!=null) {
            systemIds.put(n,schemaLocation);
        } else {
            Result output = resolver.createOutput(n.uri,"schema"+(out.size()+1)+".xsd");
            if(output!=null) {  // null result means no schema for that namespace
                out.put(n,output);
                systemIds.put(n,output.getSystemId());
            }
        }
        //Clear the namespace specific set with already written classes
        n.resetWritten();
    }

    // then write'em all
    for( Map.Entry<Namespace,Result> e : out.entrySet() ) {
        Result result = e.getValue();
        e.getKey().writeTo( result, systemIds );
        if(result instanceof StreamResult) {
            OutputStream outputStream = ((StreamResult)result).getOutputStream();
            if(outputStream != null) {
                outputStream.close(); // fix for bugid: 6291301
            } else {
                final Writer writer = ((StreamResult)result).getWriter();
                if(writer != null) writer.close();
            }
        }
    }
}
 
源代码20 项目: TencentKona-8   文件: FoolProofResolver.java
public FoolProofResolver(SchemaOutputResolver resolver) {
    assert resolver!=null;
    this.resolver = resolver;
}
 
源代码21 项目: TencentKona-8   文件: JAXBModelImpl.java
public void generateSchema(SchemaOutputResolver outputResolver, ErrorListener errorListener) throws IOException {
    getSchemaGenerator().write(outputResolver,errorListener);
}
 
源代码22 项目: jdk8u60   文件: JAXBRIContextWrapper.java
@Override
public void generateSchema(SchemaOutputResolver outputResolver)
        throws IOException {
    context.generateSchema(outputResolver);
}
 
源代码23 项目: jdk8u60   文件: XmlSchemaGenerator.java
/**
 * Write out the schema documents.
 */
public void write(SchemaOutputResolver resolver, ErrorListener errorListener) throws IOException {
    if(resolver==null)
        throw new IllegalArgumentException();

    if(logger.isLoggable(Level.FINE)) {
        // debug logging to see what's going on.
        logger.log(Level.FINE,"Wrigin XML Schema for "+toString(),new StackRecorder());
    }

    // make it fool-proof
    resolver = new FoolProofResolver(resolver);
    this.errorListener = errorListener;

    Map<String, String> schemaLocations = types.getSchemaLocations();

    Map<Namespace,Result> out = new HashMap<Namespace,Result>();
    Map<Namespace,String> systemIds = new HashMap<Namespace,String>();

    // we create a Namespace object for the XML Schema namespace
    // as a side-effect, but we don't want to generate it.
    namespaces.remove(WellKnownNamespace.XML_SCHEMA);

    // first create the outputs for all so that we can resolve references among
    // schema files when we write
    for( Namespace n : namespaces.values() ) {
        String schemaLocation = schemaLocations.get(n.uri);
        if(schemaLocation!=null) {
            systemIds.put(n,schemaLocation);
        } else {
            Result output = resolver.createOutput(n.uri,"schema"+(out.size()+1)+".xsd");
            if(output!=null) {  // null result means no schema for that namespace
                out.put(n,output);
                systemIds.put(n,output.getSystemId());
            }
        }
    }

    // then write'em all
    for( Map.Entry<Namespace,Result> e : out.entrySet() ) {
        Result result = e.getValue();
        e.getKey().writeTo( result, systemIds );
        if(result instanceof StreamResult) {
            OutputStream outputStream = ((StreamResult)result).getOutputStream();
            if(outputStream != null) {
                outputStream.close(); // fix for bugid: 6291301
            } else {
                final Writer writer = ((StreamResult)result).getWriter();
                if(writer != null) writer.close();
            }
        }
    }
}
 
源代码24 项目: jdk8u60   文件: FoolProofResolver.java
public FoolProofResolver(SchemaOutputResolver resolver) {
    assert resolver!=null;
    this.resolver = resolver;
}
 
源代码25 项目: jdk8u60   文件: JAXBModelImpl.java
public void generateSchema(SchemaOutputResolver outputResolver, ErrorListener errorListener) throws IOException {
    getSchemaGenerator().write(outputResolver,errorListener);
}
 
源代码26 项目: openjdk-jdk8u   文件: JAXBRIContextWrapper.java
@Override
public void generateSchema(SchemaOutputResolver outputResolver)
        throws IOException {
    context.generateSchema(outputResolver);
}
 
源代码27 项目: openjdk-jdk8u   文件: XmlSchemaGenerator.java
/**
 * Write out the schema documents.
 */
public void write(SchemaOutputResolver resolver, ErrorListener errorListener) throws IOException {
    if(resolver==null)
        throw new IllegalArgumentException();

    if(logger.isLoggable(Level.FINE)) {
        // debug logging to see what's going on.
        logger.log(Level.FINE,"Writing XML Schema for "+toString(),new StackRecorder());
    }

    // make it fool-proof
    resolver = new FoolProofResolver(resolver);
    this.errorListener = errorListener;

    Map<String, String> schemaLocations = types.getSchemaLocations();

    Map<Namespace,Result> out = new HashMap<Namespace,Result>();
    Map<Namespace,String> systemIds = new HashMap<Namespace,String>();

    // we create a Namespace object for the XML Schema namespace
    // as a side-effect, but we don't want to generate it.
    namespaces.remove(WellKnownNamespace.XML_SCHEMA);

    // first create the outputs for all so that we can resolve references among
    // schema files when we write
    for( Namespace n : namespaces.values() ) {
        String schemaLocation = schemaLocations.get(n.uri);
        if(schemaLocation!=null) {
            systemIds.put(n,schemaLocation);
        } else {
            Result output = resolver.createOutput(n.uri,"schema"+(out.size()+1)+".xsd");
            if(output!=null) {  // null result means no schema for that namespace
                out.put(n,output);
                systemIds.put(n,output.getSystemId());
            }
        }
        //Clear the namespace specific set with already written classes
        n.resetWritten();
    }

    // then write'em all
    for( Map.Entry<Namespace,Result> e : out.entrySet() ) {
        Result result = e.getValue();
        e.getKey().writeTo( result, systemIds );
        if(result instanceof StreamResult) {
            OutputStream outputStream = ((StreamResult)result).getOutputStream();
            if(outputStream != null) {
                outputStream.close(); // fix for bugid: 6291301
            } else {
                final Writer writer = ((StreamResult)result).getWriter();
                if(writer != null) writer.close();
            }
        }
    }
}
 
源代码28 项目: openjdk-jdk8u   文件: FoolProofResolver.java
public FoolProofResolver(SchemaOutputResolver resolver) {
    assert resolver!=null;
    this.resolver = resolver;
}
 
源代码29 项目: openjdk-jdk8u   文件: ConfigReader.java
/**
 * This returns the SchemaOutputResolver to generate the schemas
 */
public SchemaOutputResolver getSchemaOutputResolver(){
    return schemaOutputResolver;
}
 
源代码30 项目: openjdk-jdk8u   文件: JAXBModelImpl.java
public void generateSchema(SchemaOutputResolver outputResolver, ErrorListener errorListener) throws IOException {
    getSchemaGenerator().write(outputResolver,errorListener);
}