本文整理汇总了Java中javax.xml.bind.SchemaOutputResolver类的典型用法代码示例。如果您正苦于以下问题:Java SchemaOutputResolver类的具体用法?Java SchemaOutputResolver怎么用?Java SchemaOutputResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SchemaOutputResolver类属于javax.xml.bind包,在下文中一共展示了SchemaOutputResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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();
}
}
示例2: generate
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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);
}
}
示例3: extractSchemaResult
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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();
}
示例4: main
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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"));
}
});
}
示例5: main
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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();
}
}
示例6: generateSchema
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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);
}
}
示例7: schemaCollection
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
@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);
}
示例8: generateJaxbSchemas
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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;
}
示例9: main
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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.");
}
示例10: main
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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.");
}
示例11: storeSchema
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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;
}
});
}
示例12: generateSchema
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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);
}
示例13: generateSchema
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
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();
}
}
示例14: generateSchema
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
/**
* 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);
}
示例15: generateSchema
import javax.xml.bind.SchemaOutputResolver; //导入依赖的package包/类
@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);
}
}