private void addAnnotationToDefinition(Element definitionElement, QName qname, QName value) { Element annotationElement = getOrCreateElement(new QName(W3C_XML_SCHEMA_NS_URI, "annotation"), definitionElement); Element appinfoElement = getOrCreateElement(new QName(W3C_XML_SCHEMA_NS_URI, "appinfo"), annotationElement); if (value == null) { addAnnotation(qname, appinfoElement); } else { addAnnotation(qname, value, appinfoElement); } }
@NotNull @Override public Document serializeToXsd() throws SchemaException { SchemaToDomProcessor processor = new SchemaToDomProcessor(); processor.setPrismContext(prismContext); return processor.parseSchema(this); } //endregion
/** * Adds XSD element definition. * @param name element QName * @param typeName element type QName * @param parent element under which the definition will be added */ private Element addElementDefinition(QName name, QName typeName, int minOccurs, int maxOccurs, Element parent) { Element elementDef = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "element")); parent.appendChild(elementDef); if (isMyNamespace(name)) { setAttribute(elementDef, "name", name.getLocalPart()); if (typeName.equals(DOMUtil.XSD_ANY)) { addSequenceXsdAnyDefinition(elementDef); } else { setQNameAttribute(elementDef, "type", typeName); } } else { // Need to create "ref" instead of "name" setAttribute(elementDef, "ref", name); if (typeName != null) { // Type cannot be stored directly, XSD does not allow it with "ref"s. addAnnotationToDefinition(elementDef, A_TYPE, typeName); } } setMultiplicityAttribute(elementDef, "minOccurs", minOccurs); setMultiplicityAttribute(elementDef, "maxOccurs", maxOccurs); return elementDef; }
Element complexType = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "complexType")); parent.appendChild(complexType); setAttribute(complexType, "name", definition.getTypeName().getLocalPart()); Element annotation = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "annotation")); complexType.appendChild(annotation); Element complexContent = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "complexContent")); complexType.appendChild(complexContent); Element extension = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "extension")); complexContent.appendChild(extension); setQNameAttribute(extension, "base", definition.getSuperType()); containingElement = extension; Element sequence = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "sequence")); containingElement.appendChild(sequence); for (ItemDefinition def : definitions) { if (def instanceof PrismPropertyDefinition) { addPropertyDefinition((PrismPropertyDefinition) def, sequence); } else if (def instanceof PrismContainerDefinition) { PrismContainerDefinition contDef = (PrismContainerDefinition)def; addContainerDefinition(contDef, sequence, parent); } else if (def instanceof PrismReferenceDefinition) { addReferenceDefinition((PrismReferenceDefinition) def, sequence); } else { throw new IllegalArgumentException("Unknown definition "+def+"("+def.getClass().getName()+") in complex type definition "+def); addXsdAnyDefinition(sequence);
Element property = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "element")); if (attrNamespace != null && attrNamespace.equals(getNamespace())) { setAttribute(property, "name", definition.getName().getLocalPart()); setQNameAttribute(property, "type", definition.getTypeName()); } else { setQNameAttribute(property, "ref", definition.getName()); setMultiplicityAttribute(property, "minOccurs", 0); setMultiplicityAttribute(property, "maxOccurs", definition.getMaxOccurs()); Element annotation = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "annotation")); property.appendChild(annotation); Element appinfo = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "appinfo")); annotation.appendChild(appinfo); addAnnotation(A_OBJECT_REFERENCE, appinfo); addAnnotation(A_OBJECT_REFERENCE_TARGET_TYPE, definition.getTargetTypeName(), appinfo); property = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "element")); if (attrNamespace != null && attrNamespace.equals(getNamespace())) { setAttribute(property, "name", elementName.getLocalPart()); setQNameAttribute(property, "type", definition.getTargetTypeName()); } else { setQNameAttribute(property, "ref", elementName);
Element property = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "element")); if (attrNamespace != null && attrNamespace.equals(getNamespace())) { setAttribute(property, "name", definition.getName().getLocalPart()); setQNameAttribute(property, "type", definition.getTypeName()); } else { setQNameAttribute(property, "ref", definition.getName()); setAttribute(property, "minOccurs", Integer.toString(definition.getMinOccurs())); String maxOccurs = definition.getMaxOccurs() == XSParticle.UNBOUNDED ? MAX_OCCURS_UNBOUNDED : Integer.toString(definition.getMaxOccurs()); setAttribute(property, "maxOccurs", maxOccurs); Element annotation = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "annotation")); property.appendChild(annotation); Element appinfo = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "appinfo")); annotation.appendChild(appinfo); addCommonDefinitionAnnotations(definition, appinfo); addAnnotation(A_ACCESS, A_ACCESS_CREATE, appinfo); addAnnotation(A_ACCESS, A_ACCESS_READ, appinfo); addAnnotation(A_ACCESS, A_ACCESS_UPDATE, appinfo); addAnnotation(A_INDEXED, XmlTypeConverterInternal.toXmlTextContent(definition.isIndexed(), A_INDEXED), appinfo);
init(); // here the document is initialized addComplexTypeDefinition(complexTypeDefinition, document.getDocumentElement()); addContainerDefinition((PrismContainerDefinition) definition, document.getDocumentElement(), document.getDocumentElement()); addPropertyDefinition((PrismPropertyDefinition) definition, document.getDocumentElement()); addImports();
/** * 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); } }
private void addExtraObjectClassAnnotations(ObjectClassComplexTypeDefinition definition, Element appinfo, SchemaToDomProcessor processor) { processor.addAnnotation(MidPointConstants.RA_RESOURCE_OBJECT, appinfo); processor.addRefAnnotation(MidPointConstants.RA_IDENTIFIER, identifier.getName(), appinfo); processor.addRefAnnotation(MidPointConstants.RA_SECONDARY_IDENTIFIER,identifier.getName(),appinfo); processor.addRefAnnotation(MidPointConstants.RA_DISPLAY_NAME_ATTRIBUTE, definition.getDisplayNameAttribute().getName(), appinfo); processor.addRefAnnotation(MidPointConstants.RA_DESCRIPTION_ATTRIBUTE, definition.getDescriptionAttribute().getName(), appinfo); processor.addRefAnnotation(MidPointConstants.RA_NAMING_ATTRIBUTE, definition.getNamingAttribute().getName(), appinfo); processor.addAnnotation(MidPointConstants.RA_NATIVE_OBJECT_CLASS, definition.getNativeObjectClass(), appinfo); processor.addAnnotation(MidPointConstants.RA_KIND, definition.getKind().value(), appinfo); processor.addAnnotation(MidPointConstants.RA_DEFAULT, true, appinfo); processor.addAnnotation(MidPointConstants.RA_AUXILIARY, true, appinfo); processor.addAnnotation(MidPointConstants.RA_INTENT, definition.getIntent(), appinfo);
private void addCommonDefinitionAnnotations(Definition definition, Element appinfoElement) { if (definition.getProcessing() != null) { addAnnotation(A_PROCESSING, definition.getProcessing().getValue(), appinfoElement); } if ((definition instanceof ItemDefinition) && ((ItemDefinition)definition).isOperational()) { addAnnotation(A_OPERATIONAL, "true", appinfoElement); } if (definition.getDisplayName() != null) { addAnnotation(A_DISPLAY_NAME, definition.getDisplayName(), appinfoElement); } if (definition.getDisplayOrder() != null) { addAnnotation(A_DISPLAY_ORDER, definition.getDisplayOrder().toString(), appinfoElement); } if (definition.getHelp() != null) { addAnnotation(A_HELP, definition.getHelp(), appinfoElement); } if (definition.isEmphasized()) { addAnnotation(A_EMPHASIZED, "true", appinfoElement); } }
private void addAnnotationToDefinition(Element definitionElement, QName qname) { addAnnotationToDefinition(definitionElement, qname, null); }
@Override public void addExtraPropertyAnnotations(PrismPropertyDefinition definition, Element appinfo, SchemaToDomProcessor schemaToDomProcessor) { super.addExtraPropertyAnnotations(definition, appinfo, schemaToDomProcessor); if (definition instanceof ResourceAttributeDefinition) { ResourceAttributeDefinition rad = (ResourceAttributeDefinition)definition; if (rad.getNativeAttributeName() != null) { schemaToDomProcessor.addAnnotation(MidPointConstants.RA_NATIVE_ATTRIBUTE_NAME, rad.getNativeAttributeName(), appinfo); } if (rad.getFrameworkAttributeName() != null) { schemaToDomProcessor.addAnnotation(MidPointConstants.RA_FRAMEWORK_ATTRIBUTE_NAME, rad.getFrameworkAttributeName(), appinfo); } if (rad.getReturnedByDefault() != null) { schemaToDomProcessor.addAnnotation(MidPointConstants.RA_RETURNED_BY_DEFAULT_NAME, rad.getReturnedByDefault().toString(), appinfo); } } }