protected XmlSchema getXMLSchema(Element element, String baseUri) { XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); if (baseUri != null) { schemaCollection.setBaseUri(baseUri); } if (customResolver != null) { schemaCollection.setSchemaResolver(customResolver); } return schemaCollection.read(element); }
@Override public XmlSchemaType visitDate(DateOnlyResolvedType dateOnlyTypeDefinition) { return collection.getTypeByQName(Constants.XSD_DATE); }
/** * This function is not part of the XmlSchema API. Who knows why? * * @param namespaceURI targetNamespace * @return schema, or null. */ public XmlSchema getSchemaByTargetNamespace(String namespaceURI) { for (XmlSchema schema : schemaCollection.getXmlSchemas()) { if (namespaceURI.equals(schema.getTargetNamespace())) { return schema; } } return null; }
protected XmlSchema getXMLSchema(Element element, String baseUri) { XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); if (baseUri != null) { schemaCollection.setBaseUri(baseUri); } return schemaCollection.read(element, baseUri); } }
public XmlSchema getSchemaForElement(QName name) { for (XmlSchema schema : schemaCollection.getXmlSchemas()) { if (name.getNamespaceURI().equals(schema.getTargetNamespace())) { if (schema.getElementByName(name.getLocalPart()) != null) { return schema; } else if (schema.getElementByName(name) != null) { return schema; } } } return null; }
String elementNamespace = element.getQName().getNamespaceURI(); if (elementNamespace == null || elementNamespace.equals("")) { elementNamespace = enclosingType.qname.getNamespaceURI(); elementQName = new QName(elementNamespace, element.getQName().getLocalPart()); final XmlSchemaElement refElement = xmlSchemaCollection.getElementByQName(element.getRefName());
protected static boolean findNonSchemaType(String name, WSDLASTVisitor wsdlVisitor, VisitorTypeHolder holder) { boolean result = false; TypeMappingType typeMap = wsdlVisitor.getTypeMap(); XmlSchemaCollection schemas = wsdlVisitor.getSchemas(); QName qname = new QName(typeMap.getTargetNamespace(), name); CorbaType corbaType = findCorbaType(typeMap, qname); if (corbaType != null) { if (corbaType instanceof Alias) { result = true; if (holder != null) { populateAliasSchemaType(corbaType, wsdlVisitor, holder); } } else if (((corbaType instanceof Sequence) || (corbaType instanceof Anonsequence)) && ((corbaType.getType().equals(Constants.XSD_BASE64)))) { //special case of sequence of octets result = true; if (holder != null) { holder.setCorbaType(corbaType); holder.setSchemaType(schemas.getTypeByQName(corbaType.getType())); } } } return result; }
/** * Validate that a qualified name points to some namespace in the schema. * * @param qname */ public void validateQNameNamespace(QName qname) { // astonishingly, xmlSchemaCollection has no accessor by target URL. if ("".equals(qname.getNamespaceURI())) { return; // references to the 'unqualified' namespace are OK even if there is no schema for it. } for (XmlSchema schema : schemaCollection.getXmlSchemas()) { if (schema.getTargetNamespace().equals(qname.getNamespaceURI())) { return; } } throw new InvalidXmlSchemaReferenceException(qname + " refers to unknown namespace."); }
public void visit(AST fixedNode) { // <fixed_pt_const_type> ::= "fixed" XmlSchemaType stype = null; CorbaType ctype = null; QName corbaTypeQName = CorbaConstants.NE_CORBA_FIXED; if (corbaTypeQName != null) { QName schemaTypeQName = Constants.XSD_DECIMAL; if (schemaTypeQName != null) { stype = schemas.getTypeByQName(schemaTypeQName); if (stype != null) { ctype = new CorbaType(); ctype.setQName(corbaTypeQName); ctype.setType(stype.getQName()); ctype.setName(stype.getQName().getLocalPart()); } } } schemaType = stype; corbaType = ctype; }
tname = type.getType(); XmlSchemaType stype = schemas.getTypeByQName(tname); if (stype == null) { XmlSchema xmlSchema = wsdlVisitor.getManager().getXmlSchema(tname.getNamespaceURI()); if (xmlSchema != null) { stype = xmlSchema.getTypeByName(tname); } else { stype = wsdlVisitor.getSchema().getTypeByName(tname);
public String readXMLfromSchemaFile(String path) throws Exception { InputStream is = new FileInputStream(path); XmlSchemaCollection schemaCol = new XmlSchemaCollection(); XmlSchema schema = schemaCol.read(new StreamSource(is)); ByteArrayOutputStream stream = new ByteArrayOutputStream(); schema.write(stream); is.close(); return stream.toString(); }
/** * Read an XML Schema from a complete XSD XML DOM Document into this collection. * Schemas in a collection must be unique in * the concatenation of SystemId and targetNamespace. * @param doc The schema document. * @param systemId System ID for this schema. * @param veh handler to be called to check validity of the schema. * @return the schema object. */ public XmlSchema read(Document doc, String systemId, ValidationEventHandler veh) { return read(doc, systemId, veh, null); }
private void loadCustomSchemaFile() { if (customSchemaLocation != null) { try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); Document doc = documentBuilderFactory.newDocumentBuilder().parse(new File(customSchemaLocation)); XmlSchema schema = xmlSchemaCollection.read(doc, null); schemaMap.put(schema.getTargetNamespace(), schema); } catch (Exception e) { log.info(e.getMessage()); } } }
public XmlSchema loadSingleSchemaFile(int i) throws Exception{ File file = new File(SampleSchemasDirectory + "sampleSchema" + i + ".xsd"); InputStream is = new FileInputStream(file); XmlSchemaCollection schemaCol = new XmlSchemaCollection(); XmlSchema schema = schemaCol.read(new StreamSource(is)); return schema; }
@Override public void afterPropertiesSet() throws IOException { Assert.notEmpty(xsdResources, "'xsds' must not be empty"); schemaCollection.setSchemaResolver(uriResolver); Set<XmlSchema> processedIncludes = new HashSet<XmlSchema>(); Set<XmlSchema> processedImports = new HashSet<XmlSchema>(); for (Resource xsdResource : xsdResources) { Assert.isTrue(xsdResource.exists(), xsdResource + " does not exist"); try { XmlSchema xmlSchema = schemaCollection.read(SaxUtils.createInputSource(xsdResource)); xmlSchemas.add(xmlSchema); if (inline) { inlineIncludes(xmlSchema, processedIncludes, processedImports); findImports(xmlSchema, processedImports, processedIncludes); } } catch (Exception ex) { throw new CommonsXsdSchemaException("Schema [" + xsdResource + "] could not be loaded", ex); } } if (logger.isInfoEnabled()) { logger.info("Loaded " + StringUtils.arrayToCommaDelimitedString(xsdResources)); } }
private void initialize(ResolvedType resolvedType) { collection = new XmlSchemaCollection(); final boolean empty = currentElement.isEmpty(); // We use namespace of this element if (empty) { final String target = getTargetNamespace(resolvedType); schema = new XmlSchema(target, "raml-xsd", collection); schema.setTargetNamespace(target); } schema.setElementFormDefault(XmlSchemaForm.QUALIFIED); }
public SchemaCollection() { this(new XmlSchemaCollection()); }
schemas.setBaseUri(definition.getDocumentBaseURI()); XmlSchema schema = schemas.read(el, schemaSystemId);
private void buildXmlTypeInfos() { for (final XmlSchema schema : xmlSchemaCollection.getXmlSchemas()) { // Global Elements for (final Iterator iterator = schema.getElements().getValues(); iterator.hasNext(); ) { final XmlSchemaElement globalElement = (XmlSchemaElement) iterator.next(); addGlobalElement(globalElement); } // Global Types for (final Iterator iterator = schema.getSchemaTypes().getValues(); iterator.hasNext(); ) { final XmlSchemaType globalType = (XmlSchemaType) iterator.next(); addType(globalType.getQName(), globalType); } } }
public void setSchemaResolver(URIResolver schemaResolver) { schemaCollection.setSchemaResolver(schemaResolver); }