/** * Parses single schema. */ void parseSchema(@NotNull PrismSchemaImpl prismSchema, @NotNull Element xsdSchema, boolean isRuntime, boolean allowDelayedItemDefinitions, String shortDescription) throws SchemaException { this.shortDescription = shortDescription; XSSchemaSet xsSchemaSet = parseSchema(xsdSchema); if (xsSchemaSet == null) { return; } DomToSchemaPostProcessor postProcessor = new DomToSchemaPostProcessor(xsSchemaSet, prismContext); postProcessor.postprocessSchema(prismSchema, isRuntime, allowDelayedItemDefinitions, shortDescription); }
private void applyToDeclarations(XSComponent component, Consumer<XSDeclaration> consumer) { if (component == null) { return; } if (component instanceof XSDeclaration) { consumer.accept((XSDeclaration) component); } // recursion (if needed) if (component instanceof XSParticle) { applyToDeclarations(((XSParticle) component).getTerm(), consumer); } else if (component instanceof XSModelGroup) { for (XSParticle particle : ((XSModelGroup) component).getChildren()) { applyToDeclarations(particle, consumer); } } else if (component instanceof XSModelGroupDecl) { applyToDeclarations(((XSModelGroupDecl) component).getModelGroup(), consumer); } }
/** * Main entry point. */ void postprocessSchema(MutablePrismSchema prismSchema, boolean isRuntime, boolean allowDelayedItemDefinitions, String shortDescription) throws SchemaException { this.schema = prismSchema; this.isRuntime = isRuntime; this.allowDelayedItemDefinitions = allowDelayedItemDefinitions; this.shortDescription = shortDescription; // Create ComplexTypeDefinitions from all top-level complexType // definition in the XSD processComplexTypeDefinitions(xsSchemaSet); // Create SimpleTypeDefinitions from all top-level simpleType // definition in the XSD processSimpleTypeDefinitions(xsSchemaSet); // Create PropertyContainer (and possibly also Property) definition from // the top-level elements in XSD // This also creates ResourceObjectDefinition in some cases createDefinitionsFromElements(xsSchemaSet); }
XSTerm pterm = p.getTerm(); if (pterm.isModelGroup()) { addPropertyDefinitionListFromGroup(pterm.asModelGroup(), ctd, particleInherited, explicitContent); XSAnnotation annotation = selectAnnotationToUse(p.getAnnotation(), pterm.getAnnotation()); QName typeFromAnnotation = getTypeAnnotation(p.getAnnotation()); if (isObjectReference(xsType, annotation)) { processObjectReferenceDefinition(xsType, elementName, annotation, ctd, p, particleInherited); } else if (isObjectDefinition(xsType)) { if (isAny(xsType)) { if (isPropertyContainer(elementDecl)) { XSAnnotation containerAnnotation = xsType.getAnnotation(); PrismContainerDefinition<?> containerDefinition = createPropertyContainerDefinition( xsType, p, null, containerAnnotation, false); containerDefinition.toMutable().setInherited(particleInherited); ctd.add(containerDefinition); } else { MutablePrismPropertyDefinition propDef = createPropertyDefinition(xsType, elementName, DOMUtil.XSD_ANY, ctd, annotation, p); propDef.setInherited(particleInherited); } else if (isPropertyContainer(elementDecl)) {
SchemaDefinitionFactory definitionFactory = getDefinitionFactory(); MutableComplexTypeDefinition ctd = definitionFactory.createComplexTypeDefinition(complexType, prismContext, complexType.getAnnotation()); addPropertyDefinitionListFromGroup(term.asModelGroup(), ctd, inherited, explicitContent); markRuntime(ctd); QName superType = determineSupertype(complexType); if (superType != null) { ctd.setSuperType(superType); setInstantiationOrder(ctd, complexType.getAnnotation()); if (isObjectDefinition(complexType)) { ctd.setObjectMarker(true); if (isPropertyContainer(complexType)) { ctd.setContainerMarker(true); if (isObjectReference(complexType)) { ctd.setReferenceMarker(true); ctd.setDefaultNamespace(getDefaultNamespace(complexType)); ctd.setIgnoredNamespaces(getIgnoredNamespaces(complexType)); if (isAny(complexType)) { ctd.setXsdAnyMarker(true); if (isList(complexType)) {
while (iterator.hasNext()) { XSElementDecl xsElementDecl = iterator.next(); if (isDeprecated(xsElementDecl)) { QName typeQName = determineType(xsElementDecl); if (typeQName == null) { if (isPropertyContainer(xsElementDecl) || isObjectDefinition(xsType)) { ComplexTypeDefinition complexTypeDefinition = findComplexTypeDefinition(typeQName); if (complexTypeDefinition == null) { if (!allowDelayedItemDefinitions) { ComplexTypeDefinition ctd = findComplexTypeDefinition(typeQName); return createPropertyContainerDefinition(xsType, xsElementDecl, ctd, annotation, null, true); }); } else { definition = createPropertyContainerDefinition( xsType, xsElementDecl, complexTypeDefinition, annotation, null, true); } else if (isObjectReference(xsElementDecl, xsType)) { definition = processObjectReferenceDefinition(xsType, elementName, annotation, null, null, false); } else { definition = createPropertyDefinition(xsType, elementName, typeQName, null, annotation, null); definition.setSubstitutionHead(getSubstitutionHead(xsElementDecl));
private SimpleTypeDefinition processSimpleTypeDefinition(XSSimpleType simpleType) throws SchemaException { SchemaDefinitionFactory definitionFactory = getDefinitionFactory(); SimpleTypeDefinitionImpl std = (SimpleTypeDefinitionImpl) definitionFactory.createSimpleTypeDefinition(simpleType, prismContext, simpleType.getAnnotation()); SimpleTypeDefinition existingSimpleTypeDefinition = schema.findSimpleTypeDefinitionByType(std.getTypeName()); if (existingSimpleTypeDefinition != null) { // We already have this in schema. So avoid redundant work return existingSimpleTypeDefinition; } markRuntime(std); QName superType = determineSupertype(simpleType); if (superType != null) { std.setSuperType(superType); } setInstantiationOrder(std, simpleType.getAnnotation()); extractDocumentation(std, simpleType.getAnnotation()); if (getSchemaRegistry() != null) { Class<?> compileTimeClass = getSchemaRegistry().determineCompileTimeClass(std.getTypeName()); std.setCompileTimeClass(compileTimeClass); } schema.add(std); return std; }
/** * Creates appropriate instance of PropertyContainerDefinition. It may be * PropertyContainerDefinition itself or one of its subclasses * (ResourceObjectDefinition). This method also takes care of parsing all * the annotations and similar fancy stuff. * * We need to pass createResourceObject flag explicitly here. Because even * if we are in resource schema, we want PropertyContainers inside * ResourceObjects, not ResourceObjects inside ResouceObjects. */ private PrismContainerDefinition<?> createPropertyContainerDefinition(XSType xsType, XSParticle elementParticle, ComplexTypeDefinition complexTypeDefinition, XSAnnotation annotation, boolean topLevel) throws SchemaException { XSTerm elementTerm = elementParticle.getTerm(); XSElementDecl elementDecl = elementTerm.asElementDecl(); PrismContainerDefinition<?> pcd = createPropertyContainerDefinition(xsType, elementDecl, complexTypeDefinition, annotation, elementParticle, topLevel); return pcd; }
extractDocumentation(itemDef, annotation);
/** * Parses several schemas, referenced by a wrapper schema. * Provided to allow circular references (e.g. common-3 -> scripting-3 -> common-3). */ void parseSchemas(List<SchemaDescription> schemaDescriptions, Element wrapper, boolean allowDelayedItemDefinitions, String shortDescription) throws SchemaException { this.shortDescription = shortDescription; XSSchemaSet xsSchemaSet = parseSchema(wrapper); if (xsSchemaSet == null) { return; } for (SchemaDescription schemaDescription : schemaDescriptions) { DomToSchemaPostProcessor postProcessor = new DomToSchemaPostProcessor(xsSchemaSet, prismContext); PrismSchemaImpl prismSchema = (PrismSchemaImpl) schemaDescription.getSchema(); boolean isRuntime = schemaDescription.getCompileTimeClassesPackage() == null; String schemaShortDescription = schemaDescription.getSourceDescription() + " in " + shortDescription; postProcessor.postprocessSchema(prismSchema, isRuntime, allowDelayedItemDefinitions, schemaShortDescription); } }