public static ResourceSchema getResourceSchema(
     PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException {
   Element resourceXsdSchema = ResourceTypeUtil.getResourceXsdSchema(resource);
   if (resourceXsdSchema == null) {
     return null;
   }
   Object userDataEntry = resource.getUserData(USER_DATA_KEY_PARSED_RESOURCE_SCHEMA);
   if (userDataEntry != null) {
     if (userDataEntry instanceof ResourceSchema) {
       return (ResourceSchema) userDataEntry;
     } else {
       throw new IllegalStateException(
           "Expected ResourceSchema under user data key "
               + USER_DATA_KEY_PARSED_RESOURCE_SCHEMA
               + "in "
               + resource
               + ", but got "
               + userDataEntry.getClass());
     }
   } else {
     InternalMonitor.recordResourceSchemaParse();
     ResourceSchemaImpl parsedSchema =
         ResourceSchemaImpl.parse(
             resourceXsdSchema, "resource schema of " + resource, prismContext);
     if (parsedSchema == null) {
       throw new IllegalStateException("Parsed schema is null: most likely an internall error");
     }
     resource.setUserData(USER_DATA_KEY_PARSED_RESOURCE_SCHEMA, parsedSchema);
     parsedSchema.setNamespace(ResourceTypeUtil.getResourceNamespace(resource));
     return parsedSchema;
   }
 }
  public static RefinedResourceSchema getRefinedSchema(
      PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException {
    if (resource == null) {
      throw new SchemaException("Could not get refined schema, resource does not exist.");
    }

    Object userDataEntry = resource.getUserData(USER_DATA_KEY_REFINED_SCHEMA);
    if (userDataEntry != null) {
      if (userDataEntry instanceof RefinedResourceSchema) {
        return (RefinedResourceSchema) userDataEntry;
      } else {
        throw new IllegalStateException(
            "Expected RefinedResourceSchema under user data key "
                + USER_DATA_KEY_REFINED_SCHEMA
                + "in "
                + resource
                + ", but got "
                + userDataEntry.getClass());
      }
    } else {
      RefinedResourceSchema refinedSchema = parse(resource, prismContext);
      resource.setUserData(USER_DATA_KEY_REFINED_SCHEMA, refinedSchema);
      return refinedSchema;
    }
  }
 public static void setParsedResourceSchemaConditional(
     ResourceType resourceType, ResourceSchema parsedSchema) {
   if (hasParsedSchema(resourceType)) {
     return;
   }
   PrismObject<ResourceType> resource = resourceType.asPrismObject();
   resource.setUserData(USER_DATA_KEY_PARSED_RESOURCE_SCHEMA, parsedSchema);
 }
  @Override
  public CompositeRefinedObjectClassDefinition determineCompositeObjectClassDefinition(
      PrismObject<ShadowType> shadow, Collection<QName> additionalAuxiliaryObjectClassQNames)
      throws SchemaException {
    ShadowType shadowType = shadow.asObjectable();

    RefinedObjectClassDefinition structuralObjectClassDefinition = null;
    ShadowKindType kind = shadowType.getKind();
    String intent = shadowType.getIntent();
    QName structuralObjectClassQName = shadowType.getObjectClass();

    if (kind != null) {
      structuralObjectClassDefinition = getRefinedDefinition(kind, intent);
    }

    if (structuralObjectClassDefinition == null) {
      // Fallback to objectclass only
      if (structuralObjectClassQName == null) {
        return null;
      }
      structuralObjectClassDefinition = getRefinedDefinition(structuralObjectClassQName);
    }

    if (structuralObjectClassDefinition == null) {
      return null;
    }
    List<QName> auxiliaryObjectClassQNames = shadowType.getAuxiliaryObjectClass();
    if (additionalAuxiliaryObjectClassQNames != null) {
      auxiliaryObjectClassQNames.addAll(additionalAuxiliaryObjectClassQNames);
    }
    Collection<RefinedObjectClassDefinition> auxiliaryObjectClassDefinitions =
        new ArrayList<>(auxiliaryObjectClassQNames.size());
    for (QName auxiliaryObjectClassQName : auxiliaryObjectClassQNames) {
      RefinedObjectClassDefinition auxiliaryObjectClassDef =
          getRefinedDefinition(auxiliaryObjectClassQName);
      if (auxiliaryObjectClassDef == null) {
        throw new SchemaException(
            "Auxiliary object class "
                + auxiliaryObjectClassQName
                + " specified in "
                + shadow
                + " does not exist");
      }
      auxiliaryObjectClassDefinitions.add(auxiliaryObjectClassDef);
    }

    return new CompositeRefinedObjectClassDefinitionImpl(
        structuralObjectClassDefinition, auxiliaryObjectClassDefinitions);
  }
 public static RefinedResourceSchema parse(
     PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException {
   return parse(resource.asObjectable(), prismContext);
 }
 public static boolean hasParsedSchema(ResourceType resourceType) {
   PrismObject<ResourceType> resource = resourceType.asPrismObject();
   return resource.getUserData(USER_DATA_KEY_PARSED_RESOURCE_SCHEMA) != null;
 }
 public static boolean hasRefinedSchema(ResourceType resourceType) {
   PrismObject<ResourceType> resource = resourceType.asPrismObject();
   return resource.getUserData(USER_DATA_KEY_REFINED_SCHEMA) != null;
 }
 public static RefinedResourceSchema getRefinedSchema(PrismObject<ResourceType> resource)
     throws SchemaException {
   return getRefinedSchema(resource, resource.getPrismContext());
 }