private boolean isMyNamespace(QName qname) { return getNamespace().equals(qname.getNamespaceURI()); }
/** * Adds import definition to XSD. * It adds imports of namespaces that accumulated during schema processing in the importNamespaces list. * @param schema */ private void addImports() { for (String namespace : importNamespaces) { if (W3C_XML_SCHEMA_NS_URI.equals(namespace)) { continue; } if (getNamespace().equals(namespace)) { //we don't want to import target namespace continue; } rootXsdElement.insertBefore(createImport(namespace), rootXsdElement.getFirstChild()); } }
/** * Create schema XSD DOM document. */ private void init() throws ParserConfigurationException { if (namespacePrefixMapper == null) { // TODO: clone? namespacePrefixMapper = ((SchemaRegistryImpl) prismContext.getSchemaRegistry()).getNamespacePrefixMapper(); } // We don't want the "tns" prefix to be kept in the mapper namespacePrefixMapper = namespacePrefixMapper.clone(); namespacePrefixMapper.registerPrefixLocal(getNamespace(), "tns"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Using namespace prefix mapper to serialize schema:\n{}",DebugUtil.dump(namespacePrefixMapper)); } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(false); DocumentBuilder db = dbf.newDocumentBuilder(); document = db.newDocument(); Element root = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "schema")); document.appendChild(root); rootXsdElement = document.getDocumentElement(); setAttribute(rootXsdElement, "targetNamespace", getNamespace()); setAttribute(rootXsdElement, "elementFormDefault", "qualified"); DOMUtil.setNamespaceDeclaration(rootXsdElement, "tns", getNamespace()); if (attributeQualified) { setAttribute(rootXsdElement, "attributeFormDefault", "qualified"); } }
if (attrNamespace != null && attrNamespace.equals(getNamespace())) { setAttribute(property, "name", definition.getName().getLocalPart()); setQNameAttribute(property, "type", definition.getTypeName()); if (attrNamespace != null && attrNamespace.equals(getNamespace())) { setAttribute(property, "name", elementName.getLocalPart()); setQNameAttribute(property, "type", definition.getTargetTypeName());
/** * Adds XSD definitions from PropertyContainerDefinition. This is complexType and element. * If the property container is an ResourceObjectDefinition, it will add only annotated * complexType definition. * * @param definition PropertyContainerDefinition to process * @param parent element under which the XSD definition will be added */ private void addContainerDefinition(PrismContainerDefinition definition, Element elementParent, Element complexTypeParent) { ComplexTypeDefinition complexTypeDefinition = definition.getComplexTypeDefinition(); if (complexTypeDefinition != null && // Check if the complex type is a top-level complex type. If it is then it was already processed and we can skip it schema.findComplexTypeDefinition(complexTypeDefinition.getTypeName()) == null && // If the definition is not in this schema namespace then skip it. It is only a "ref" getNamespace().equals(complexTypeDefinition.getTypeName().getNamespaceURI()) ) { addComplexTypeDefinition(complexTypeDefinition,complexTypeParent); } Element elementElement = addElementDefinition(definition.getName(), definition.getTypeName(), definition.getMinOccurs(), definition.getMaxOccurs(), elementParent); if (complexTypeDefinition == null || !complexTypeDefinition.isContainerMarker()) { // Need to add a:container annotation to the element as the complex type does not have it addAnnotationToDefinition(elementElement, A_PROPERTY_CONTAINER); } }
if (attrNamespace != null && attrNamespace.equals(getNamespace())) { setAttribute(property, "name", definition.getName().getLocalPart()); setQNameAttribute(property, "type", definition.getTypeName());