@Override public void setSchema(Schema schema) { jaxbMarshaller.setSchema(schema); }
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(locationOfMySchema); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setSchema(schema); marshaller.marshal(objectToMarshal, new DefaultHandler());
private void saveTenants(final Tenants tenants) throws JAXBException { final Marshaller marshaller = JAXB_TENANTS_CONTEXT.createMarshaller(); marshaller.setSchema(tenantsSchema); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(tenants, tenantsFile); }
private void saveAuthorizations(final Authorizations authorizations) throws JAXBException { final Marshaller marshaller = JAXB_AUTHORIZATIONS_CONTEXT.createMarshaller(); marshaller.setSchema(authorizationsSchema); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(authorizations, authorizationsFile); }
public void validateWith(URL url) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema; try { schema = factory.newSchema(url); } catch (SAXException e) { throw new RuntimeException(e.getMessage(), e); } marshaller.setSchema(schema); }
/** * Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior. * Gets called after creation of JAXB {@code Marshaller}, and after the respective properties have been set. * <p>The default implementation sets the {@link #setMarshallerProperties(Map) defined properties}, the {@link * #setValidationEventHandler(ValidationEventHandler) validation event handler}, the {@link #setSchemas(Resource[]) * schemas}, {@link #setMarshallerListener(javax.xml.bind.Marshaller.Listener) listener}, and * {@link #setAdapters(XmlAdapter[]) adapters}. */ protected void initJaxbMarshaller(Marshaller marshaller) throws JAXBException { if (this.marshallerProperties != null) { for (String name : this.marshallerProperties.keySet()) { marshaller.setProperty(name, this.marshallerProperties.get(name)); } } if (this.marshallerListener != null) { marshaller.setListener(this.marshallerListener); } if (this.validationEventHandler != null) { marshaller.setEventHandler(this.validationEventHandler); } if (this.adapters != null) { for (XmlAdapter<?, ?> adapter : this.adapters) { marshaller.setAdapter(adapter); } } if (this.schema != null) { marshaller.setSchema(this.schema); } }
private XmlMultiConfiguration(Map<String, Config> configurations) { try { Schema schema = discoverSchema(new StreamSource(CORE_SCHEMA_URL.openStream()), new StreamSource(MULTI_SCHEMA_URL.openStream())); this.configurations = configurations; ObjectFactory objectFactory = new ObjectFactory(); Configurations jaxb = objectFactory.createConfigurations().withConfiguration(configurations.entrySet().stream().map( entry -> objectFactory.createConfigurationsConfiguration().withIdentity(entry.getKey()).withConfigOrVariant(entry.getValue().unparse(objectFactory)) ).collect(toList())); JAXBContext jaxbContext = JAXBContext.newInstance(Configurations.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setSchema(schema); this.document = documentBuilder(schema).newDocument(); marshaller.marshal(jaxb, document); this.renderedDocument = documentToText(document); } catch (JAXBException | IOException | TransformerException | ParserConfigurationException | SAXException e) { throw new XmlConfigurationException(e); } }
public Document configToDocument(Configuration configuration) throws JAXBException { ConfigType configType = new ConfigType(); serviceCreationConfigurationParser.unparseServiceCreationConfiguration(configuration, configType); for (Map.Entry<String, CacheConfiguration<?, ?>> cacheConfigurationEntry : configuration.getCacheConfigurations().entrySet()) { CacheConfiguration<?, ?> cacheConfiguration = cacheConfigurationEntry.getValue(); CacheType cacheType = new CacheType().withAlias(cacheConfigurationEntry.getKey()) .withKeyType(new CacheEntryType().withValue(cacheConfiguration.getKeyType().getName())) .withValueType(new CacheEntryType().withValue(cacheConfiguration.getValueType().getName())); resourceConfigurationParser.unparseResourceConfiguration(cacheConfiguration.getResourcePools(), cacheType); CORE_CACHE_CONFIGURATION_PARSER.unparseConfiguration(cacheConfiguration, cacheType); serviceConfigurationParser.unparseServiceConfiguration(cacheConfiguration, cacheType); configType.withCacheOrCacheTemplate(cacheType); } JAXBElement<ConfigType> root = new ObjectFactory().createConfig(configType); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setSchema(schema); Document document = documentBuilder.newDocument(); marshaller.marshal(root, document); return document; }
Document document = DomUtil.createAndGetDocumentBuilder().newDocument(); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setSchema(CORE_SCHEMA); marshaller.marshal(resource, document); element = document.getDocumentElement();
public void setSchema(Schema schema) { marshaller.setSchema(schema); }
public void setSchema(Schema schema) { jaxbMarshaller.setSchema(schema); }
@SuppressWarnings("nullness") private void setMarshallerSchema(Marshaller marshaller, /*@Nullable*/ Schema schema) { if (null != marshaller) { marshaller.setSchema(schema); } }
/** * {@inheritDoc} */ @Override public void setSchema( final Schema schema ) { marshaller.setSchema( schema ); }
private void saveTenants(final Tenants tenants) throws JAXBException { final Marshaller marshaller = JAXB_TENANTS_CONTEXT.createMarshaller(); marshaller.setSchema(tenantsSchema); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(tenants, tenantsFile); }
private void saveAuthorizations(final Authorizations authorizations) throws JAXBException { final Marshaller marshaller = JAXB_AUTHORIZATIONS_CONTEXT.createMarshaller(); marshaller.setSchema(authorizationsSchema); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(authorizations, authorizationsFile); }
private Marshaller createMarshaller() throws JAXBException { Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.setProperty(Marshaller.JAXB_FRAGMENT, true); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.setSchema(schema); return m; }
MovieLibrary library = ...; // <-- your JAXB-annotated tree JAXBContext ctx = JAXBContext.newInstance(MovieLibrary.class); Marshaller marshaller = ctx.createMarshaller(); marshaller.setSchema(schema); marshaller.marshal(new JAXBElement<MovieLibrary>(new QName("movieLibrary"), MovieLibrary.class, library), new FileOutputStream("/tmp/library.xml"));
private static Marshaller getMarshaller() throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setSchema(DbPorter.retrieveSchema("/xsd/dbi-ca.xsd")); return marshaller; }
CaconfDbExporter(DataSourceWrapper datasource, String destDir, AtomicBoolean stopMe) throws DataAccessException, JAXBException { super(datasource, destDir, stopMe); JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setSchema(DbPorter.retrieveSchema("/xsd/dbi-ca.xsd")); }
public Marshaller createMarshaller(CoercionTarget target) { Class<?> type = target.getType(); JAXBContext context = getContext(type); Marshaller marshaller = createMarshaller(context); marshaller.setSchema(getSchema(context, type)); return marshaller; }