Search in sources :

Example 1 with ClassOutline

use of com.sun.tools.xjc.outline.ClassOutline 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 ClassOutline

use of com.sun.tools.xjc.outline.ClassOutline 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 ClassOutline

use of com.sun.tools.xjc.outline.ClassOutline in project midpoint by Evolveum.

the class SchemaProcessor method isContainer.

private boolean isContainer(JDefinedClass definedClass, Outline outline) {
    ClassOutline classOutline = findClassOutline(definedClass, outline);
    if (classOutline == null) {
        return false;
    }
    boolean isContainer = hasAnnotation(classOutline, A_PRISM_CONTAINER) || hasAnnotation(classOutline, A_PRISM_OBJECT);
    if (isContainer) {
        return true;
    }
    if (!(definedClass._extends() instanceof JDefinedClass)) {
        return false;
    }
    return isContainer((JDefinedClass) definedClass._extends(), outline);
}
Also used : ClassOutline(com.sun.tools.xjc.outline.ClassOutline)

Example 4 with ClassOutline

use of com.sun.tools.xjc.outline.ClassOutline 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 5 with ClassOutline

use of com.sun.tools.xjc.outline.ClassOutline 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)

Aggregations

ClassOutline (com.sun.tools.xjc.outline.ClassOutline)14 CClassInfo (com.sun.tools.xjc.model.CClassInfo)10 NClass (com.sun.tools.xjc.model.nav.NClass)10 Map (java.util.Map)9 HashMap (java.util.HashMap)8 QName (javax.xml.namespace.QName)8 Entry (java.util.Map.Entry)7 ArrayList (java.util.ArrayList)4 PrismContainerArrayList (com.evolveum.midpoint.prism.xjc.PrismContainerArrayList)3 PrismReferenceArrayList (com.evolveum.midpoint.prism.xjc.PrismReferenceArrayList)3 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)2 JCodeModel (com.sun.codemodel.JCodeModel)2 JDefinedClass (com.sun.codemodel.JDefinedClass)2 Outline (com.sun.tools.xjc.outline.Outline)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Containerable (com.evolveum.midpoint.prism.Containerable)1 Objectable (com.evolveum.midpoint.prism.Objectable)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 Referencable (com.evolveum.midpoint.prism.Referencable)1