Refine search
... ByteArrayInputStream xmlContentBytes = new ByteArrayInputStream (xmlContent.getBytes()); JAXBContext context = JAXBContext.newInstance(Item.getClass()); Unmarshaller unmarshaller = context.createUnmarshaller(); //note: setting schema to null will turn validator off unmarshaller.setSchema(null); Object xmlObject = Item.getClass().cast(unmarshaller.unmarshal(xmlContentBytes)); return xmlObject; ...
private Authorizations unmarshallAuthorizations() throws JAXBException { try { final XMLStreamReader xsr = XmlUtils.createSafeReader(new StreamSource(authorizationsFile)); final Unmarshaller unmarshaller = JAXB_AUTHORIZATIONS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(authorizationsSchema); final JAXBElement<Authorizations> element = unmarshaller.unmarshal(xsr, Authorizations.class); return element.getValue(); } catch (XMLStreamException e) { logger.error("Encountered an error reading authorizations file: ", e); throw new JAXBException("Error reading authorizations file", e); } }
private Tenants unmarshallTenants() throws JAXBException { final Unmarshaller unmarshaller = JAXB_TENANTS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(tenantsSchema); try { final XMLStreamReader xsr = XmlUtils.createSafeReader(new StreamSource(tenantsFile)); final JAXBElement<Tenants> element = unmarshaller.unmarshal(xsr, Tenants.class); return element.getValue(); } catch (XMLStreamException e) { throw new JAXBException("Error unmarshalling tenants", e); } }
private Authorizers loadAuthorizersConfiguration() throws Exception { final File authorizersConfigurationFile = properties.getAuthorizerConfigurationFile(); // load the authorizers from the specified file if (authorizersConfigurationFile.exists()) { try { // find the schema final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(Authorizers.class.getResource(AUTHORIZERS_XSD)); // attempt to unmarshal final XMLStreamReader xsr = XmlUtils.createSafeReader(new StreamSource(authorizersConfigurationFile)); final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(schema); final JAXBElement<Authorizers> element = unmarshaller.unmarshal(xsr, Authorizers.class); return element.getValue(); } catch (XMLStreamException | SAXException | JAXBException e) { throw new Exception("Unable to load the authorizer configuration file at: " + authorizersConfigurationFile.getAbsolutePath(), e); } } else { throw new Exception("Unable to find the authorizer configuration file at " + authorizersConfigurationFile.getAbsolutePath()); } }
private LoginIdentityProviders loadLoginIdentityProvidersConfiguration() throws Exception { final File loginIdentityProvidersConfigurationFile = properties.getLoginIdentityProviderConfigurationFile(); // load the users from the specified file if (loginIdentityProvidersConfigurationFile.exists()) { try { // find the schema final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(LoginIdentityProviders.class.getResource(LOGIN_IDENTITY_PROVIDERS_XSD)); // attempt to unmarshal XMLStreamReader xsr = XmlUtils.createSafeReader(new StreamSource(loginIdentityProvidersConfigurationFile)); final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(schema); final JAXBElement<LoginIdentityProviders> element = unmarshaller.unmarshal(xsr, LoginIdentityProviders.class); return element.getValue(); } catch (SAXException | JAXBException e) { throw new Exception("Unable to load the login identity provider configuration file at: " + loginIdentityProvidersConfigurationFile.getAbsolutePath()); } } else { throw new Exception("Unable to find the login identity provider configuration file at " + loginIdentityProvidersConfigurationFile.getAbsolutePath()); } }
public <T> T getJaxbRoot(InputStream stream, Class<T> clazz, Schema schema) throws XmlParsingException { XMLEventReader staxEventReader; try { staxEventReader = createXmlEventReader( stream ); } catch ( XMLStreamException e ) { throw new XmlParsingException( "Unable to create stax reader", e ); } ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler(); try { staxEventReader = new JpaNamespaceTransformingEventReader( staxEventReader ); JAXBContext jaxbContext = JAXBContext.newInstance( ObjectFactory.class ); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema( schema ); unmarshaller.setEventHandler( handler ); return clazz.cast( unmarshaller.unmarshal( staxEventReader ) ); } catch ( JAXBException e ) { StringBuilder builder = new StringBuilder(); builder.append( "Unable to perform unmarshalling at line number " ); builder.append( handler.getLineNumber() ); builder.append( " and column " ); builder.append( handler.getColumnNumber() ); builder.append( ". Message: " ); builder.append( handler.getMessage() ); throw new XmlParsingException( builder.toString(), e ); } }
@SuppressWarnings("unchecked") protected <T> T jaxb(XMLEventReader reader, Schema xsd, JAXBContext jaxbContext, Origin origin) { final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler(); try { final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); if ( isValidationEnabled() ) { unmarshaller.setSchema( xsd ); } else { unmarshaller.setSchema( null ); } unmarshaller.setEventHandler( handler ); return (T) unmarshaller.unmarshal( reader ); } catch ( JAXBException e ) { throw new MappingException( "Unable to perform unmarshalling at line number " + handler.getLineNumber() + " and column " + handler.getColumnNumber() + ". Message: " + handler.getMessage(), e, origin ); } }
try { JAXBContext jaxbContext = JAXBContext.newInstance( JaxbCfgHibernateConfiguration.class ); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema( schema() ); unmarshaller.setEventHandler( handler ); return (JaxbCfgHibernateConfiguration) unmarshaller.unmarshal( staxEventReader );
final Unmarshaller unmarshaller = JAXB_USERS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(usersSchema);
} else { try { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema(CORE_SCHEMA); Object resource = unmarshaller.unmarshal(element); if (resource instanceof Heap) {
final Unmarshaller unmarshaller = JAXB_USERS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(usersSchema);
jaxbContext = JAXBContext.newInstance(arg0); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema(schema); return (Customer) unmarshaller.unmarshal(arg5); } catch(JAXBException e) {
public static Unmarshaller getJaxbUnmarshaller(boolean disableSchemaValidation) throws JAXBException { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); if (!disableSchemaValidation) { unmarshaller.setSchema(schema); } return unmarshaller; }
private Unmarshaller createUnmarshaller() throws JAXBException { Unmarshaller u = jaxbContext.createUnmarshaller(); u.setSchema(schema); return u; }
private X unmarshal(XMLStreamReader xmlStreamReader) throws IOException { try { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); if (schema != null) { unmarshaller.setSchema(schema); } return unmarshaller.unmarshal(xmlStreamReader, rootElementType).getValue(); } catch (JAXBException e) { throw new IOException("Cannot unmarshal XML document.", e); } }
private Tenants unmarshallTenants() throws JAXBException { final Unmarshaller unmarshaller = JAXB_TENANTS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(tenantsSchema); final JAXBElement<Tenants> element = unmarshaller.unmarshal(new StreamSource(tenantsFile), Tenants.class); return element.getValue(); }
//Gets schema SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(xmlSchema); JAXBContext jaxbContext1= JAXBContext.newInstance(Request.class); Unmarshaller jaxbUnMarshaller1 = jaxbContext1.createUnmarshaller(); //Sets schema with unmarshaller jaxbUnMarshaller1 .setSchema(schema); Request request = (Request)jaxbUnMarshaller1.unmarshal(receiveData.getBinaryStream());
private Authorizations unmarshallAuthorizations() throws JAXBException { final Unmarshaller unmarshaller = JAXB_AUTHORIZATIONS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(authorizationsSchema); final JAXBElement<Authorizations> element = unmarshaller.unmarshal(new StreamSource(authorizationsFile), Authorizations.class); return element.getValue(); }
@Nonnull protected static Unmarshaller unmarshallerFor(@Nullable Object element) { final Unmarshaller unmarshaller; try { unmarshaller = JAXB_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(SCHEMA); } catch (JAXBException e) { throw new RuntimeException("Could not create unmarshaller to unmarshall " + element + ".", e); } return unmarshaller; }
public QaSystemManagerImpl() throws JAXBException, SAXException { JAXBContext context = JAXBContext.newInstance(ObjectFactory.class); jaxbUnmarshaller = context.createUnmarshaller(); final SchemaFactory schemaFact = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); URL url = QaSystemManagerImpl.class.getResource("/xsd/caqa-conf.xsd"); jaxbUnmarshaller.setSchema(schemaFact.newSchema(url)); }