public ConfigurationMetadata build(InputStream is) throws IOException { return build(new InputSource(is)); }
private void deserializeConfigItems(Document document) { for (Node nd = document.getDocumentElement().getFirstChild(); nd != null; nd = nd.getNextSibling()) { if (Node.ELEMENT_NODE == nd.getNodeType() && "configItem".equals(nd.getLocalName()) && MEATADATA_NAMESPACE_URI.equals(nd.getNamespaceURI())) { Element configItemElement = (Element)nd; deserializeConfigItem(document, configItemElement); } } }
private Validator getMetadataValidator() { if (null == metadataValidator) { Schema schema = getMetadataSchema(); // assert null != schema; metadataValidator = schema.newValidator(); if (null == validatorErrorHandler) { validatorErrorHandler = new ValidatorErrorHandler(); } metadataValidator.setErrorHandler(validatorErrorHandler); // assert null != metadataValidator; } return metadataValidator; }
src = new InputSource(new File(path).toURI().toString()); ConfigurationMetadataBuilder builder = new ConfigurationMetadataBuilder(false); builder.setValidation(true); ConfigurationMetadata model = null; model = builder.build(src); } catch (IOException ex) { throw new ConfigurationException(new Message("FAILED_TO_GENERATE_BEAN_EXC", LOG), ex);
private void parseXML(InputSource is) throws IOException { // parse Document document = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder parser = factory.newDocumentBuilder(); document = parser.parse(is); } catch (ParserConfigurationException ex) { throw new ConfigurationException(new Message("PARSER_CONFIGURATION_ERROR_EXC", LOG), ex); } catch (SAXException ex) { throw new ConfigurationException(new Message("PARSE_ERROR_EXC", LOG), ex); } if (doValidate) { try { Validator v = getMetadataValidator(); v.validate(new DOMSource(document)); } catch (SAXException ex) { Message msg = new Message("METADATA_VALIDATION_ERROR_EXC", LOG); throw new ConfigurationException(msg, ex); } } deserializeImports(document); deserializeConfig(document); deserializeConfigItems(document); }
public void addModel(String resource) { InputStream is = null; if (resource != null) { is = loadResource(resource); if (is == null) { throw new ConfigurationException(new Message("METADATA_RESOURCE_EXC", BUNDLE, resource)); } } ConfigurationMetadata model = null; ConfigurationMetadataBuilder builder = new ConfigurationMetadataBuilder(true); if (null != is) { try { model = builder.build(is); } catch (IOException ex) { throw new ConfigurationException(new Message("METADATA_RESOURCE_EXC", BUNDLE, resource), ex); } } else { model = new ConfigurationMetadataImpl(); } addModel(model); }
/** * The configuration metadata schema is obtained system resource * "schemas/configuration/metadata.xsd". * It requires that either the resources directory is on the classpath or that * the resources is listed in the classpath specified in the manifest of celtix.jar. * * @return the metadata schema */ private Schema getMetadataSchema() { if (null == metadataSchema) { InputStream is = DefaultResourceManager.instance() .getResourceAsStream("schemas/configuration/metadata.xsd"); if (null == is) { throw new ConfigurationException(new Message("CANNOT_FIND_CONFIG_METADATA_SCHEMA_MSG", LOG)); } try { metadataSchema = getSchema(is); } catch (ConfigurationException ex) { // should never happen as metadata schema is immutable LOG.log(Level.SEVERE, "CANNOT_CREATE_CONFIG_METADATA_SCHEMA_MSG", ex); } } return metadataSchema; }
deserializeDefaultValue(item, (Element)nd);