public static RefinedResourceSchema parse(ResourceType resourceType, PrismContext prismContext)
      throws SchemaException {

    ResourceSchema originalResourceSchema = getResourceSchema(resourceType, prismContext);
    if (originalResourceSchema == null) {
      return null;
    }

    String contextDescription = "definition of " + resourceType;

    RefinedResourceSchemaImpl rSchema = new RefinedResourceSchemaImpl(originalResourceSchema);

    SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
    if (schemaHandling != null) {
      parseObjectTypeDefsFromSchemaHandling(
          rSchema,
          resourceType,
          schemaHandling,
          schemaHandling.getObjectType(),
          null,
          prismContext,
          contextDescription);
    }

    parseObjectTypesFromSchema(rSchema, resourceType, prismContext, contextDescription);

    // We need to parse associations and auxiliary object classes in a second pass. We need to have
    // all object classes parsed before correctly setting association
    // targets
    for (RefinedObjectClassDefinition rOcDef : rSchema.getRefinedDefinitions()) {
      ((RefinedObjectClassDefinitionImpl) rOcDef).parseAssociations(rSchema);
      ((RefinedObjectClassDefinitionImpl) rOcDef).parseAuxiliaryObjectClasses(rSchema);
    }

    // We can parse attributes only after we have all the object class info parsed (including
    // auxiliary object classes)
    for (RefinedObjectClassDefinition rOcDef : rSchema.getRefinedDefinitions()) {
      ((RefinedObjectClassDefinitionImpl) rOcDef).parseAttributes(rSchema, contextDescription);
    }

    return rSchema;
  }