当前位置: 首页>>代码示例>>Java>>正文


Java Unmarshaller.setSchema方法代码示例

本文整理汇总了Java中javax.xml.bind.Unmarshaller.setSchema方法的典型用法代码示例。如果您正苦于以下问题:Java Unmarshaller.setSchema方法的具体用法?Java Unmarshaller.setSchema怎么用?Java Unmarshaller.setSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.bind.Unmarshaller的用法示例。


在下文中一共展示了Unmarshaller.setSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromXML

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
@Override
public T fromXML(String xml) {

    try {
        JAXBContext context = JAXBContext.newInstance(type);
        Unmarshaller u = context.createUnmarshaller();

        if(schemaLocation != null) {
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

            StreamSource source = new StreamSource(getClass().getResourceAsStream(schemaLocation));
            Schema schema = schemaFactory.newSchema(source);
            u.setSchema(schema);
        }

        StringReader reader = new StringReader(xml);
        T obj = (T) u.unmarshal(reader);

        return obj;
    } catch (Exception e) {
        System.out.println("ERROR: "+e.toString());
        return null;
    }
}
 
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:25,代码来源:ConverterImpl.java

示例2: setConfFile

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
public void setConfFile(String confFile) throws Exception {
    this.confFile = confFile;

    Object root;
    try {
        JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
        Unmarshaller jaxbUnmarshaller = context.createUnmarshaller();
        final SchemaFactory schemaFact = SchemaFactory.newInstance(
                javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
        URL url = ObjectFactory.class.getResource("/xsd/httpserver.xsd");
        jaxbUnmarshaller.setSchema(schemaFact.newSchema(url));

        root = jaxbUnmarshaller.unmarshal(new File(confFile));
    } catch (Exception ex) {
        throw new Exception("parsing config file failed, message: " + ex.getMessage(), ex);
    }

    if (root instanceof Httpservers) {
        this.conf = (Httpservers) root;
    } else if (root instanceof JAXBElement) {
        this.conf = (Httpservers) ((JAXBElement<?>) root).getValue();
    } else {
        throw new Exception("invalid root element type");
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:26,代码来源:FileHttpServersConf.java

示例3: loadPluginDescriptor

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
/**
 * Loads the plugin descriptor from the specified file. The file path specified should
 * be a class path relative path. For example, if the descriptor file is located at
 * org.rhq.enterprise.server.configuration.my-descriptor.xml, then you should specify
 * /org/rhq/enterprise/server/configuration/my-descriptor.xml.
 *
 * @param pluginDescriptorURL The class path relative path of the descriptor file
 * @return The {@link PluginDescriptor}
 */
public static PluginDescriptor loadPluginDescriptor(URL pluginDescriptorURL) {
   try {
      JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);
      URL pluginSchemaURL = PluginDescriptorUtil.class.getClassLoader().getResource("rhq-plugin.xsd");
      Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
               pluginSchemaURL);
      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      ValidationEventCollector vec = new ValidationEventCollector();
      unmarshaller.setEventHandler(vec);
      unmarshaller.setSchema(pluginSchema);

      return (PluginDescriptor) unmarshaller.unmarshal(pluginDescriptorURL.openStream());
   } catch (Exception e) {
      throw new RuntimeException(e);
   }
}
 
开发者ID:rh-messaging,项目名称:Artemis-JON-plugin,代码行数:26,代码来源:PluginDescriptorUtil.java

示例4: toPluginDescriptor

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
/**
 * Transforms the given string into a plugin descriptor object.
 *
 * @param string The plugin descriptor specified as a string
 * @return The {@link PluginDescriptor}
 */
public static PluginDescriptor toPluginDescriptor(String string) {
   try {
      JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);
      URL pluginSchemaURL = PluginMetadataParser.class.getClassLoader().getResource("rhq-plugin.xsd");
      Schema pluginSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(pluginSchemaURL);

      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      ValidationEventCollector vec = new ValidationEventCollector();
      unmarshaller.setEventHandler(vec);
      unmarshaller.setSchema(pluginSchema);

      StringReader reader = new StringReader(string);

      return (PluginDescriptor) unmarshaller.unmarshal(reader);
   }
   catch (Exception e) {
      throw new RuntimeException(e);
   }
}
 
开发者ID:rh-messaging,项目名称:Artemis-JON-plugin,代码行数:26,代码来源:PluginDescriptorUtil.java

示例5: deserialiseObject

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
/** Attempt to construct the specified object from this XML string
 * @param xml the XML string to parse
 * @param xsdFile the name of the XSD schema that defines the object
 * @param objclass the class of the object requested
 * @return if successful, an instance of class objclass that captures the data in the XML string
 */
static public Object deserialiseObject(String xml, String xsdFile, Class<?> objclass) throws JAXBException, SAXException, XMLStreamException
{
    Object obj = null;
    JAXBContext jaxbContext = getJAXBContext(objclass);
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    final String schemaResourceFilename = new String(xsdFile);
    URL schemaURL = MalmoMod.class.getClassLoader().getResource(schemaResourceFilename);
    Schema schema = schemaFactory.newSchema(schemaURL);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    jaxbUnmarshaller.setSchema(schema);

    StringReader stringReader = new StringReader(xml);

    XMLInputFactory xif = XMLInputFactory.newFactory();
    xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
    xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    XMLStreamReader XMLreader = xif.createXMLStreamReader(stringReader);

    obj = jaxbUnmarshaller.unmarshal(XMLreader);
    return obj;
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:28,代码来源:SchemaHelper.java

示例6: createHydrographDebugInfo

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
/**
 * Creates the object of type {@link HydrographDebugInfo} from the graph xml of type
 * {@link Document}.
 * <p>
 * The method uses jaxb framework to unmarshall the xml document
 *
 * @param graphDocument the xml document with all the graph contents to unmarshall
 * @return an object of type {@link HydrographDebugInfo}
 * @throws SAXException
 */
public static HydrographDebugInfo createHydrographDebugInfo(Document graphDocument, String debugXSDLocation) throws SAXException {
    try {
        LOG.trace("Creating DebugJAXB object.");
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(ClassLoader.getSystemResource(debugXSDLocation));
        JAXBContext context = JAXBContext.newInstance(Debug.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        unmarshaller.setSchema(schema);
        unmarshaller.setEventHandler(new ComponentValidationEventHandler());
        Debug debug = (Debug) unmarshaller.unmarshal(graphDocument);
        HydrographDebugInfo hydrographDebugInfo = new HydrographDebugInfo(debug);
        LOG.trace("DebugJAXB object created successfully");
        return hydrographDebugInfo;
    } catch (JAXBException e) {
        LOG.error("Error while creating JAXB objects from debug XML.", e);
        throw new RuntimeException("Error while creating JAXB objects from debug XML.", e);
    }
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:29,代码来源:DebugUtils.java

示例7: initialize

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
@PostConstruct
@Override
public synchronized void initialize() throws ProviderFactoryException {
    if (providersHolder.get() == null) {
        final File providersConfigFile = properties.getProvidersConfigurationFile();
        if (providersConfigFile.exists()) {
            try {
                // find the schema
                final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                final Schema schema = schemaFactory.newSchema(StandardProviderFactory.class.getResource(PROVIDERS_XSD));

                // attempt to unmarshal
                final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
                unmarshaller.setSchema(schema);

                // set the holder for later use
                final JAXBElement<Providers> element = unmarshaller.unmarshal(new StreamSource(providersConfigFile), Providers.class);
                providersHolder.set(element.getValue());
            } catch (SAXException | JAXBException e) {
                throw new ProviderFactoryException("Unable to load the providers configuration file at: " + providersConfigFile.getAbsolutePath(), e);
            }
        } else {
            throw new ProviderFactoryException("Unable to find the providers configuration file at " + providersConfigFile.getAbsolutePath());
        }
    }
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:27,代码来源:StandardProviderFactory.java

示例8: loadLoginIdentityProvidersConfiguration

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
private IdentityProviders loadLoginIdentityProvidersConfiguration() throws Exception {
    final File loginIdentityProvidersConfigurationFile = properties.getIdentityProviderConfigurationFile();

    // 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(IdentityProviders.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<IdentityProviders> element = unmarshaller.unmarshal(xsr, IdentityProviders.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());
    }
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:24,代码来源:IdentityProviderFactory.java

示例9: loadAuthorizersConfiguration

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
private Authorizers loadAuthorizersConfiguration() throws Exception {
    final File authorizersConfigurationFile = properties.getAuthorizersConfigurationFile();

    // 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 Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
            unmarshaller.setSchema(schema);
            final JAXBElement<Authorizers> element = unmarshaller.unmarshal(XmlUtils.createSafeReader(new StreamSource(authorizersConfigurationFile)), Authorizers.class);
            return element.getValue();
        } catch (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());
    }
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:23,代码来源:AuthorizerFactory.java

示例10: setSchema

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
private void setSchema(Unmarshaller u, File schemaLocation) throws Exception {
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    URI schemaURI = schemaLocation.toURI();
    File schemaFile = new File(schemaURI.getPath());
    Schema schema = sf.newSchema(schemaFile);
    u.setSchema(schema);
}
 
开发者ID:dmn-tck,项目名称:tck,代码行数:8,代码来源:SchemaValidator.java

示例11: P11Conf

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
public P11Conf(InputStream confStream, PasswordResolver passwordResolver)
        throws InvalidConfException, IOException {
    ParamUtil.requireNonNull("confStream", confStream);
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        SchemaFactory schemaFact = SchemaFactory.newInstance(
                javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFact.newSchema(getClass().getResource( "/xsd/pkcs11-conf.xsd"));
        unmarshaller.setSchema(schema);
        @SuppressWarnings("unchecked")
        JAXBElement<PKCS11ConfType> rootElement = (JAXBElement<PKCS11ConfType>)
                unmarshaller.unmarshal(confStream);
        PKCS11ConfType pkcs11Conf = rootElement.getValue();
        ModulesType modulesType = pkcs11Conf.getModules();

        Map<String, P11ModuleConf> confs = new HashMap<>();
        for (ModuleType moduleType : modulesType.getModule()) {
            P11ModuleConf conf = new P11ModuleConf(moduleType, passwordResolver);
            confs.put(conf.name(), conf);
        }

        if (!confs.containsKey(P11CryptServiceFactory.DEFAULT_P11MODULE_NAME)) {
            throw new InvalidConfException("module '"
                    + P11CryptServiceFactory.DEFAULT_P11MODULE_NAME + "' is not defined");
        }
        this.moduleConfs = Collections.unmodifiableMap(confs);
        this.moduleNames = Collections.unmodifiableSet(new HashSet<>(confs.keySet()));
    } catch (JAXBException | SAXException ex) {
        final String exceptionMsg = (ex instanceof JAXBException)
                ? getMessage((JAXBException) ex) : ex.getMessage();
        LogUtil.error(LOG, ex, exceptionMsg);
        throw new InvalidConfException("invalid PKCS#11 configuration");
    } finally {
        confStream.close();
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:38,代码来源:P11Conf.java

示例12: unmarshal

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
@SuppressWarnings( { "unchecked" })
public JaxbRoot unmarshal(Document document, Origin origin) {
	Element rootElement = document.getDocumentElement();
	if ( rootElement == null ) {
		throw new MappingException( "No root element found", origin );
	}

	final Schema validationSchema;
	final Class jaxbTarget;

	if ( "entity-mappings".equals( rootElement.getNodeName() ) ) {
		final String explicitVersion = rootElement.getAttribute( "version" );
		validationSchema = resolveSupportedOrmXsd( explicitVersion );
		jaxbTarget = JaxbEntityMappings.class;
	}
	else {
		validationSchema = hbmSchema();
		jaxbTarget = JaxbHibernateMapping.class;
	}

	final Object target;
	try {
		JAXBContext jaxbContext = JAXBContext.newInstance( jaxbTarget );
		Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
		unmarshaller.setSchema( validationSchema );
		target = unmarshaller.unmarshal( new DOMSource( document ) );
	}
	catch ( JAXBException e ) {
		throw new MappingException( "Unable to perform unmarshalling", e, origin );
	}

	return new JaxbRoot( target, origin );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:JaxbHelper.java

示例13: loadDialogFile

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
private void loadDialogFile(String fileName) throws Exception {
    FileHandle dialogFile = Gdx.files.internal("data/dialog/" + fileName + ".xml");

    if (!dialogFile.exists() || dialogFile.isDirectory())
    {
        Gdx.app.error("ERROR", "The dialog file " + fileName + ".xml doesn't exists!");
        throw new FileNotFoundException("The dialog file " + fileName + ".xml doesn't exists!");
    }

    Schema dialogSchema;

    try
    {
        dialogSchema = getSchema(dialogFile);
    } catch (Exception e)
    {
        Gdx.app.error("ERROR", "The dialog file " + fileName + ".xml is not conform to the dialog.xsd!", e);
        throw new Exception("The dialog file " + fileName + ".xml is not conform to the dialog.xsd!");
    }

    JAXBContext jaxbContext = JAXBContext.newInstance(Level.class);

    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    unmarshaller.setSchema(dialogSchema);

    dialogRoot = (Level) unmarshaller.unmarshal(dialogFile.read());

    loadCharacters();
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:30,代码来源:DialogManager.java

示例14: parseConfigurationFile

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
/**
 * Loads the configurationFile using JAXB.
 * The XML is validated as per the schema ''.
 * The XML is then parsed to return a corresponding Java object.
 * @return the Java representation of the XML inside the configuration file.
 * @throws MalformedURLException if the configuration file is not found.
 * @throws JAXBException if any error occurs during the unmarshalling of XML.
 * @throws SAXException if the schema file cannot be loaded.
 */
private Dwr parseConfigurationFile()
        throws MalformedURLException, JAXBException, SAXException {
    if (log.isDebugEnabled())
        log.debug("Unmarshalling the configuration file " + CONFIGURATION_FILE);
    URL configFileUrl = URLHelper.newExtendedURL(CONFIGURATION_FILE);
    URL configSchemaFileUrl = URLHelper.newExtendedURL(CONFIGURATION_SCHEMA_FILE);
    JAXBContext jc = JAXBHelper.obtainJAXBContext(Dwr.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(configSchemaFileUrl);
    unmarshaller.setSchema(schema);
    return (Dwr) unmarshaller.unmarshal(configFileUrl);
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:23,代码来源:ConfigurationService.java

示例15: parseConfigurationFile

import javax.xml.bind.Unmarshaller; //导入方法依赖的package包/类
/**
 * Loads the configurationFile using JAXB.
 * The XML is validated as per the schema 'com/mirotechnologies/interfaces/transform/meta/ws_xlst-config.xsd'.
 * The XML is then parsed to return a corresponding Java object.
 * @return the Java representation of the XML inside the configuration file.
 * @throws MalformedURLException if the configuration file is not found.
 * @throws JAXBException if any error occurs during the unmarshalling of XML.
 * @throws SAXException if the schema file cannot be loaded.
 */
private Config parseConfigurationFile()
        throws MalformedURLException, JAXBException, SAXException {
    if (log.isDebugEnabled()) {
        log.debug("Unmarshalling the configuration file " + CONFIGURATION_FILE);
    }
    URL configFileUrl = URLHelper.newExtendedURL(CONFIGURATION_FILE);
    URL configSchemaFileUrl = URLHelper.newExtendedURL(CONFIGURATION_SCHEMA_FILE);
    JAXBContext jc = JAXBHelper.obtainJAXBContext(Config.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(configSchemaFileUrl);
    unmarshaller.setSchema(schema);
    return (Config) unmarshaller.unmarshal(configFileUrl);
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:24,代码来源:MetaDataRepository.java


注:本文中的javax.xml.bind.Unmarshaller.setSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。