Search in sources :

Example 1 with CClassInfo

use of com.sun.tools.xjc.model.CClassInfo in project midpoint by Evolveum.

the class SchemaProcessor method updatePrismObject.

private Set<JDefinedClass> updatePrismObject(Outline outline) {
    Set<JDefinedClass> containers = new HashSet<JDefinedClass>();
    Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
    for (Map.Entry<NClass, CClassInfo> entry : set) {
        ClassOutline classOutline = outline.getClazz(entry.getValue());
        QName qname = getCClassInfoQName(entry.getValue());
        if (qname == null) {
            continue;
        }
        boolean isDirectPrismObject = hasAnnotation(classOutline, A_PRISM_OBJECT);
        boolean isIndirectPrismObject = hasParentAnnotation(classOutline, A_PRISM_OBJECT);
        if (!isIndirectPrismObject) {
            continue;
        }
        JDefinedClass definedClass = classOutline.implClass;
        createDefaultConstructor(definedClass);
        createPrismContextObjectableConstructor(definedClass);
        createAsPrismObject(definedClass);
        if (!isDirectPrismObject) {
            continue;
        }
        definedClass._implements(CLASS_MAP.get(Objectable.class));
        containers.add(definedClass);
        //inserting PrismObject field into ObjectType class
        JVar container = definedClass.field(JMod.PRIVATE, PrismObject.class, CONTAINER_FIELD_NAME);
        //create getContainer
        //            createGetContainerMethod(classOutline, container);
        //create setContainer
        createSetContainerMethod(definedClass, container);
        //create asPrismObject()
        createAsPrismContainer(classOutline, container);
        // Objectable is also Containerable, we also need these
        createAsPrismContainerValueInObject(definedClass);
        createSetContainerValueMethodInObject(definedClass, container);
        print("Creating toString, equals, hashCode methods.");
        //create toString, equals, hashCode
        createToStringMethod(definedClass, METHOD_AS_PRISM_CONTAINER);
        createEqualsMethod(classOutline, METHOD_AS_PRISM_CONTAINER);
        createHashCodeMethod(definedClass, METHOD_AS_PRISM_CONTAINER);
        //create toDebugName, toDebugType
        createToDebugName(definedClass);
        createToDebugType(definedClass);
    }
    removeCustomGeneratedMethod(outline);
    return containers;
}
Also used : QName(javax.xml.namespace.QName) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) Entry(java.util.Map.Entry) CClassInfo(com.sun.tools.xjc.model.CClassInfo) NClass(com.sun.tools.xjc.model.nav.NClass) Objectable(com.evolveum.midpoint.prism.Objectable) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 2 with CClassInfo

use of com.sun.tools.xjc.model.CClassInfo in project midpoint by Evolveum.

the class SchemaProcessor method updateFields.

private void updateFields(Outline outline) {
    Map<JDefinedClass, List<JFieldVar>> allFieldsToBeRemoved = new HashMap<>();
    Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
    for (Map.Entry<NClass, CClassInfo> entry : set) {
        ClassOutline classOutline = outline.getClazz(entry.getValue());
        JDefinedClass implClass = classOutline.implClass;
        Map<String, JFieldVar> fields = implClass.fields();
        if (fields == null) {
            continue;
        }
        print("Updating fields and get/set methods: " + classOutline.implClass.fullName());
        for (String field : fields.keySet()) {
            JFieldVar fieldVar = fields.get(field);
            // marks a:rawType fields with @Raw - this has to be executed for any bean, not only for prism containers
            if (hasAnnotation(classOutline, fieldVar, A_RAW_TYPE) != null) {
                annotateFieldAsRaw(fieldVar);
            }
        }
        if (isContainer(classOutline.implClass, outline)) {
            processContainerFields(classOutline, allFieldsToBeRemoved);
        }
        createFluentFieldMethods(classOutline, classOutline);
        print("Finished updating fields and get/set methods for " + classOutline.implClass.fullName());
    }
    allFieldsToBeRemoved.forEach((jDefinedClass, jFieldVars) -> {
        jFieldVars.forEach(field -> jDefinedClass.removeField(field));
    });
}
Also used : HashMap(java.util.HashMap) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) Entry(java.util.Map.Entry) CClassInfo(com.sun.tools.xjc.model.CClassInfo) NClass(com.sun.tools.xjc.model.nav.NClass) PrismReferenceArrayList(com.evolveum.midpoint.prism.xjc.PrismReferenceArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PrismContainerArrayList(com.evolveum.midpoint.prism.xjc.PrismContainerArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with CClassInfo

use of com.sun.tools.xjc.model.CClassInfo in project midpoint by Evolveum.

the class SchemaProcessor method addFieldQNames.

private void addFieldQNames(Outline outline, Map<String, JFieldVar> namespaceFields) {
    Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
    for (Map.Entry<NClass, CClassInfo> entry : set) {
        ClassOutline classOutline = outline.getClazz(entry.getValue());
        QName qname = getCClassInfoQName(entry.getValue());
        if (qname == null) {
            continue;
        }
        JDefinedClass implClass = classOutline.implClass;
        Map<String, JFieldVar> fields = implClass.fields();
        if (fields == null) {
            continue;
        }
        boolean isObject = hasAnnotation(classOutline, A_PRISM_OBJECT);
        List<FieldBox<QName>> boxes = new ArrayList<FieldBox<QName>>();
        for (Entry<String, JFieldVar> fieldEntry : fields.entrySet()) {
            String field = normalizeFieldName(fieldEntry.getKey());
            if ((isObject && ("oid".equals(field) || "version".equals(field)) || "serialVersionUID".equals(field) || "id".equals(field) || COMPLEX_TYPE_FIELD_NAME.equals(field))) {
                continue;
            }
            if (hasAnnotationClass(fieldEntry.getValue(), XmlAnyElement.class)) {
                continue;
            }
            String fieldName = fieldFPrefixUnderscoredUpperCase(field);
            boxes.add(new FieldBox<>(fieldName, new QName(qname.getNamespaceURI(), field)));
        }
        for (FieldBox<QName> box : boxes) {
            JFieldVar var = namespaceFields.get(qname.getNamespaceURI());
            if (var != null) {
                createQNameDefinition(outline, implClass, box.getFieldName(), var, box.getValue());
            } else {
                createPSFField(outline, implClass, box.getFieldName(), box.getValue());
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) PrismReferenceArrayList(com.evolveum.midpoint.prism.xjc.PrismReferenceArrayList) ArrayList(java.util.ArrayList) PrismContainerArrayList(com.evolveum.midpoint.prism.xjc.PrismContainerArrayList) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) Entry(java.util.Map.Entry) CClassInfo(com.sun.tools.xjc.model.CClassInfo) NClass(com.sun.tools.xjc.model.nav.NClass) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with CClassInfo

use of com.sun.tools.xjc.model.CClassInfo in project midpoint by Evolveum.

the class SchemaProcessor method updatePrismContainer.

private Set<JDefinedClass> updatePrismContainer(Outline outline) {
    Set<JDefinedClass> containers = new HashSet<JDefinedClass>();
    Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
    for (Map.Entry<NClass, CClassInfo> entry : set) {
        ClassOutline classOutline = outline.getClazz(entry.getValue());
        QName qname = getCClassInfoQName(entry.getValue());
        if (qname == null || !hasAnnotation(classOutline, A_PRISM_CONTAINER)) {
            continue;
        }
        if (hasAnnotation(classOutline, A_PRISM_OBJECT) && hasAnnotation(classOutline, A_PRISM_CONTAINER)) {
            continue;
        }
        JDefinedClass definedClass = classOutline.implClass;
        definedClass._implements(CLASS_MAP.get(Containerable.class));
        containers.add(definedClass);
        //inserting MidPointObject field into ObjectType class
        JVar containerValue = definedClass.field(JMod.PRIVATE, PrismContainerValue.class, CONTAINER_VALUE_FIELD_NAME);
        // default constructor
        createDefaultConstructor(definedClass);
        //create asPrismContainer
        //            createAsPrismContainer(classOutline, containerValue);
        createAsPrismContainerValue(definedClass, containerValue);
        //create setContainer
        JMethod setupContainerMethod = createSetContainerValueMethod(definedClass, containerValue);
        // constructor with prismContext
        createPrismContextContainerableConstructor(definedClass, setupContainerMethod);
        //create toString, equals, hashCode
        createToStringMethod(definedClass, METHOD_AS_PRISM_CONTAINER_VALUE);
        createEqualsMethod(classOutline, METHOD_AS_PRISM_CONTAINER_VALUE);
        createHashCodeMethod(definedClass, METHOD_AS_PRISM_CONTAINER_VALUE);
        //get container type
        JMethod getContainerType = definedClass.method(JMod.NONE, QName.class, METHOD_GET_CONTAINER_TYPE);
        //            getContainerType.annotate(CLASS_MAP.get(XmlTransient.class));
        JBlock body = getContainerType.body();
        body._return(definedClass.staticRef(COMPLEX_TYPE_FIELD_NAME));
    }
    removeCustomGeneratedMethod(outline);
    return containers;
}
Also used : QName(javax.xml.namespace.QName) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) Entry(java.util.Map.Entry) CClassInfo(com.sun.tools.xjc.model.CClassInfo) NClass(com.sun.tools.xjc.model.nav.NClass) Containerable(com.evolveum.midpoint.prism.Containerable) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 5 with CClassInfo

use of com.sun.tools.xjc.model.CClassInfo in project midpoint by Evolveum.

the class SchemaProcessor method updateObjectReferenceType.

private void updateObjectReferenceType(Outline outline) {
    ClassOutline objectReferenceOutline = null;
    for (Map.Entry<NClass, CClassInfo> entry : outline.getModel().beans().entrySet()) {
        QName qname = entry.getValue().getTypeName();
        if (qname == null || !OBJECT_REFERENCE_TYPE.equals(qname)) {
            continue;
        }
        objectReferenceOutline = outline.getClazz(entry.getValue());
        break;
    }
    if (objectReferenceOutline == null) {
        //object reference type class not found
        return;
    }
    updateClassAnnotation(objectReferenceOutline);
    JDefinedClass definedClass = objectReferenceOutline.implClass;
    definedClass._implements(CLASS_MAP.get(Referencable.class));
    createDefaultConstructor(definedClass);
    //add prism reference and get/set method for it
    JVar reference = definedClass.field(JMod.PRIVATE, PrismReferenceValue.class, REFERENCE_VALUE_FIELD_NAME);
    JMethod getReference = definedClass.method(JMod.PUBLIC, PrismReferenceValue.class, METHOD_AS_REFERENCE_VALUE);
    //        getReference.annotate(CLASS_MAP.get(XmlTransient.class));
    JBlock body = getReference.body();
    JBlock then = body._if(reference.eq(JExpr._null()))._then();
    JInvocation newReference = JExpr._new(CLASS_MAP.get(PrismReferenceValue.class));
    then.assign(reference, newReference);
    body._return(reference);
    JMethod setReference = definedClass.method(JMod.PUBLIC, void.class, METHOD_SETUP_REFERENCE_VALUE);
    JVar value = setReference.param(PrismReferenceValue.class, "value");
    body = setReference.body();
    body.assign(reference, value);
    //update for oid methods
    updateObjectReferenceOid(definedClass, getReference);
    //update for type methods
    updateObjectReferenceType(definedClass, getReference);
    updateObjectReferenceRelation(definedClass, getReference);
    updateObjectReferenceDescription(definedClass, getReference);
    updateObjectReferenceFilter(definedClass, getReference);
    updateObjectReferenceResolutionTime(definedClass, getReference);
    createReferenceFluentEnd(objectReferenceOutline);
}
Also used : Referencable(com.evolveum.midpoint.prism.Referencable) QName(javax.xml.namespace.QName) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) CClassInfo(com.sun.tools.xjc.model.CClassInfo) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) NClass(com.sun.tools.xjc.model.nav.NClass) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

CClassInfo (com.sun.tools.xjc.model.CClassInfo)11 NClass (com.sun.tools.xjc.model.nav.NClass)10 ClassOutline (com.sun.tools.xjc.outline.ClassOutline)10 Map (java.util.Map)9 HashMap (java.util.HashMap)8 QName (javax.xml.namespace.QName)8 Entry (java.util.Map.Entry)7 PrismContainerArrayList (com.evolveum.midpoint.prism.xjc.PrismContainerArrayList)3 PrismReferenceArrayList (com.evolveum.midpoint.prism.xjc.PrismReferenceArrayList)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Containerable (com.evolveum.midpoint.prism.Containerable)1 Objectable (com.evolveum.midpoint.prism.Objectable)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 Referencable (com.evolveum.midpoint.prism.Referencable)1 CPropertyInfo (com.sun.tools.xjc.model.CPropertyInfo)1 CTypeInfo (com.sun.tools.xjc.model.CTypeInfo)1 PluginImpl (net.sourceforge.ccxjc.PluginImpl)1