@Override public void parseThis(Element element, boolean isRuntime, String shortDescription, PrismContext prismContext) throws SchemaException { parse(element, ((PrismContextImpl) prismContext).getEntityResolver(), this, isRuntime, shortDescription, false, prismContext); }
public static PrismSchema parse(Element element, EntityResolver resolver, boolean isRuntime, String shortDescription, boolean allowDelayedItemDefinitions, PrismContext prismContext) throws SchemaException { return parse(element, resolver, new PrismSchemaImpl(prismContext), isRuntime, shortDescription, allowDelayedItemDefinitions, prismContext); }
/** * Creates a top-level property definition and adds it to the schema. * * This is a preferred way how to create definition in the schema. * * @param localName * element name "relative" to schema namespace * @param typeName * XSD type name of the element * @return new property definition */ @Override public PrismPropertyDefinition createPropertyDefinition(String localName, QName typeName) { QName name = new QName(getNamespace(), localName); return createPropertyDefinition(name, typeName); }
@Test public void testRoundTripGeneric() throws SchemaException { PrismSchemaImpl schema = new PrismSchemaImpl(SCHEMA_NS, PrismTestUtil.getPrismContext()); schema.createPropertyDefinition("number1", DOMUtil.XSD_INT); MutablePrismContainerDefinition<?> containerDefinition = schema.createPropertyContainerDefinition("ContainerType"); System.out.println(schema.debugDump()); System.out.println(); Document xsd = schema.serializeToXsd(); PrismSchema newSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(parsedXsd), true, "serialized schema", PrismTestUtil.getPrismContext()); assertEquals(DOMUtil.XSD_INT,number1def.getTypeName()); PrismContainerDefinition newContainerDef = schema.findContainerDefinitionByType(new ItemName(SCHEMA_NS,"ContainerType")); assertEquals(new ItemName(SCHEMA_NS,"ContainerType"),newContainerDef.getTypeName());
private PrismSchema constructSchema(PrismContext prismContext) { PrismSchemaImpl schema = new PrismSchemaImpl(NS_MY_SCHEMA, prismContext); MutableComplexTypeDefinition weaponTypeDef = schema.createComplexTypeDefinition(WEAPON_TYPE_QNAME).toMutable(); MutablePrismPropertyDefinition<?> kindPropertyDef = weaponTypeDef.createPropertyDefinition(WEAPON_KIND_QNAME, DOMUtil.XSD_STRING); kindPropertyDef.setDisplayName("Weapon kind"); weaponTypeDef.createPropertyDefinition(WEAPON_BRAND_LOCAL_NAME, PrismInternalTestUtil.WEAPONS_WEAPON_BRAND_TYPE_QNAME); weaponTypeDef.createPropertyDefinition(WEAPON_PASSWORD_LOCAL_NAME, PrismInternalTestUtil.DUMMY_PROTECTED_STRING_TYPE); weaponTypeDef.createPropertyDefinition(WEAPON_BLADE_LOCAL_NAME, PrismInternalTestUtil.EXTENSION_BLADE_TYPE_QNAME); MutablePrismPropertyDefinition<?> createTimestampPropertyDef = weaponTypeDef.createPropertyDefinition(WEAPON_CREATE_TIMESTAMP_QNAME, DOMUtil.XSD_DATETIME); createTimestampPropertyDef.setDisplayName("Create timestamp"); createTimestampPropertyDef.setOperational(true); schema.createPropertyContainerDefinition(WEAPON_LOCAL_NAME, WEAPON_TYPE_LOCAL_NAME); return schema; }
Element importElement = DOMUtil.createSubElement(schemaElement, DOMUtil.XSD_IMPORT_ELEMENT); importElement.setAttribute(DOMUtil.XSD_ATTR_NAMESPACE.getLocalPart(), namespace); description.setSchema(new PrismSchemaImpl(prismContext)); wrappedDescriptions.add(description); PrismSchemaImpl.parseSchemas(schemaElement, entityResolver, wrappedDescriptions, allowDelayedItemDefinitions, getPrismContext()); LOGGER.trace("Parsed {} schemas in {} ms",
@Override public MutablePrismSchema createPrismSchema(String namespace) { return new PrismSchemaImpl(namespace, prismContext); } }
@Override public String debugDump() { return debugDump(0); }
@Override public MutablePrismSchema createPrismSchema() { return new PrismSchemaImpl(prismContext); }
public static PrismSchema parseReportConfigurationSchema(PrismObject<ReportType> report, PrismContext context) throws SchemaException { PrismContainer xmlSchema = report.findContainer(ReportType.F_CONFIGURATION_SCHEMA); Element xmlSchemaElement = ObjectTypeUtil.findXsdElement(xmlSchema); if (xmlSchemaElement == null) { //no schema definition available return null; } return PrismSchemaImpl.parse(xmlSchemaElement, true, "schema for " + report, context); }
public static PrismSchema parse(Element element, boolean isRuntime, String shortDescription, PrismContext prismContext) throws SchemaException { return parse(element, ((PrismContextImpl) prismContext).getEntityResolver(), new PrismSchemaImpl(prismContext), isRuntime, shortDescription, false, prismContext); }
/** * Returns parsed connector schema */ public static PrismSchema parseConnectorSchema(ConnectorType connectorType, PrismContext prismContext) throws SchemaException { Element connectorSchemaElement = ConnectorTypeUtil.getConnectorXsdSchema(connectorType); if (connectorSchemaElement == null) { return null; } PrismSchema connectorSchema = PrismSchemaImpl.parse(connectorSchemaElement, true, "schema for " + connectorType, prismContext); // Make sure that the config container definition has a correct compile-time class name QName configContainerQName = new QName(connectorType.getNamespace(), ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart()); PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefinition = connectorSchema.findContainerDefinitionByElementName(configContainerQName); configurationContainerDefinition.toMutable().setCompileTimeClass(ConnectorConfigurationType.class); return connectorSchema; }
private void parsePrismSchema(SchemaDescription schemaDescription, boolean allowDelayedItemDefinitions) throws SchemaException { String namespace = schemaDescription.getNamespace(); Element domElement = schemaDescription.getDomElement(); boolean isRuntime = schemaDescription.getCompileTimeClassesPackage() == null; long started = System.currentTimeMillis(); LOGGER.trace("Parsing schema {}, namespace: {}, isRuntime: {}", schemaDescription.getSourceDescription(), namespace, isRuntime); PrismSchema schema = PrismSchemaImpl.parse(domElement, entityResolver, isRuntime, schemaDescription.getSourceDescription(), allowDelayedItemDefinitions, getPrismContext()); if (StringUtils.isEmpty(namespace)) { namespace = schema.getNamespace(); } LOGGER.trace("Parsed schema {}, namespace: {}, isRuntime: {} in {} ms", schemaDescription.getSourceDescription(), namespace, isRuntime, System.currentTimeMillis()-started); schemaDescription.setSchema(schema); detectExtensionSchema(schema); }
public static void assertConnectorSchemaSanity(ConnectorType conn, PrismContext prismContext) throws SchemaException { XmlSchemaType xmlSchemaType = conn.getSchema(); assertNotNull("xmlSchemaType is null",xmlSchemaType); Element connectorXsdSchemaElement = ConnectorTypeUtil.getConnectorXsdSchema(conn); assertNotNull("No schema", connectorXsdSchemaElement); Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaType); assertNotNull("No xsd:schema element in xmlSchemaType",xsdElement); display("XSD schema of "+conn, DOMUtil.serializeDOMToString(xsdElement)); // Try to parse the schema PrismSchema schema = null; try { schema = PrismSchemaImpl.parse(xsdElement, true, "schema of "+conn, prismContext); } catch (SchemaException e) { throw new SchemaException("Error parsing schema of "+conn+": "+e.getMessage(),e); } assertConnectorSchemaSanity(schema, conn.toString(), SchemaConstants.ICF_FRAMEWORK_URI.equals(conn.getFramework())); }
private void schemaRoundtrip(PrismContext ctx) throws SchemaException, SAXException, IOException { PrismSchema schema = constructSchema(ctx); assertSchema(schema); // WHEN Document xsdDocument = schema.serializeToXsd(); // THEN Element xsdElement = DOMUtil.getFirstChildElement(xsdDocument); System.out.println("Serialized schema"); System.out.println(DOMUtil.serializeDOMToString(xsdElement)); assertPrefix("xsd", xsdElement); Element displayNameElement = DOMUtil.findElementRecursive(xsdElement, PrismConstants.A_DISPLAY_NAME); assertPrefix(PrismConstants.PREFIX_NS_ANNOTATION, displayNameElement); // re-parse PrismSchema reparsedSchema = PrismSchemaImpl.parse(xsdElement, true, "serialized schema", ctx); System.out.println("Re-parsed schema"); System.out.println(reparsedSchema.debugDump()); assertSchema(reparsedSchema); }
@Test public void test002ConnectorSchema() throws Exception { final String TEST_NAME = "test002ConnectorSchema"; TestUtil.displayTestTitle(TEST_NAME); PrismSchema connectorSchema = connectorFactory.generateConnectorConfigurationSchema(connectorType); IntegrationTestTools.assertConnectorSchemaSanity(connectorSchema, "generated", true); assertEquals("Unexpected number of definitions", 3, connectorSchema.getDefinitions().size()); Document xsdSchemaDom = connectorSchema.serializeToXsd(); assertNotNull("No serialized connector schema", xsdSchemaDom); display("Serialized XSD connector schema", DOMUtil.serializeDOMToString(xsdSchemaDom)); // Try to re-parse PrismSchema reparsedConnectorSchema = PrismSchemaImpl.parse(DOMUtil.getFirstChildElement(xsdSchemaDom), true, "schema fetched from "+cc, PrismTestUtil.getPrismContext()); IntegrationTestTools.assertConnectorSchemaSanity(reparsedConnectorSchema, "re-parsed", true); // TODO: 3 definitions would be cleaner. But we can live with this assertEquals("Unexpected number of definitions in re-parsed schema", 6, reparsedConnectorSchema.getDefinitions().size()); }
PrismSchema schema = PrismSchemaImpl.parse(connectorXsdSchemaElement, true, "connector schema " + conn, prismContext); assertNotNull("Cannot parse schema", schema); assertFalse("Empty schema", schema.isEmpty());