Search in sources :

Example 6 with ClassOutline

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

Example 7 with ClassOutline

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

the class SchemaProcessor method removeCustomGeneratedMethod.

/**
     * remove generated equals methods from classes which extends from prism containers/objects
     */
private void removeCustomGeneratedMethod(Outline outline) {
    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 || (!hasParentAnnotation(classOutline, A_PRISM_OBJECT) && !hasParentAnnotation(classOutline, A_PRISM_CONTAINER))) {
            continue;
        }
        JDefinedClass definedClass = classOutline.implClass;
        Iterator<JClass> iterator = definedClass._implements();
        while (iterator.hasNext()) {
            JClass clazz = iterator.next();
            if (clazz.equals(CLASS_MAP.get(Equals.class)) || clazz.equals(CLASS_MAP.get(HashCode.class))) {
                iterator.remove();
            }
        }
        boolean isMidpointContainer = hasParentAnnotation(classOutline, A_PRISM_OBJECT);
        removeOldCustomGeneratedEquals(classOutline, isMidpointContainer);
        removeOldCustomGenerated(classOutline, isMidpointContainer, METHOD_HASH_CODE);
        removeOldCustomGenerated(classOutline, isMidpointContainer, METHOD_TO_STRING);
    }
}
Also used : 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) QName(javax.xml.namespace.QName) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with ClassOutline

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

the class SchemaProcessor method addContainerName.

private void addContainerName(Outline outline, Map<String, JFieldVar> namespaceFields) {
    Map<QName, List<QName>> complexTypeToElementName = null;
    Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
    for (Map.Entry<NClass, CClassInfo> entry : set) {
        CClassInfo classInfo = entry.getValue();
        ClassOutline classOutline = outline.getClazz(classInfo);
        if (complexTypeToElementName == null) {
            complexTypeToElementName = getComplexTypeToElementName(classOutline);
        }
        QName qname = getCClassInfoQName(classInfo);
        if (qname == null || !hasParentAnnotation(classOutline, A_PRISM_OBJECT)) {
            continue;
        }
        //element name
        List<QName> qnames = complexTypeToElementName.get(qname);
        if (qnames == null || qnames.size() != 1) {
            printWarning("Found zero or more than one element names for type '" + qname + "', " + qnames + ".");
            continue;
        }
        qname = qnames.get(0);
        JDefinedClass definedClass = classOutline.implClass;
        JMethod getContainerName = definedClass.method(JMod.NONE, QName.class, METHOD_GET_CONTAINER_NAME);
        //            getContainerName.annotate(CLASS_MAP.get(XmlTransient.class));
        JBlock body = getContainerName.body();
        JFieldVar var = namespaceFields.get(qname.getNamespaceURI());
        JInvocation invocation = JExpr._new(CLASS_MAP.get(QName.class));
        if (var != null) {
            JClass schemaClass = outline.getModel().codeModel._getClass(StepSchemaConstants.CLASS_NAME);
            invocation.arg(schemaClass.staticRef(var));
            invocation.arg(qname.getLocalPart());
        } else {
            invocation.arg(qname.getNamespaceURI());
            invocation.arg(qname.getLocalPart());
        }
        body._return(invocation);
        //get container type
        JMethod getContainerType = definedClass.method(JMod.NONE, QName.class, METHOD_GET_CONTAINER_TYPE);
        //            getContainerType.annotate(CLASS_MAP.get(XmlTransient.class));
        body = getContainerType.body();
        body._return(definedClass.staticRef(COMPLEX_TYPE_FIELD_NAME));
    }
}
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) 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 9 with ClassOutline

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

the class CloneProcessor method createCloneMethod.

private void createCloneMethod(ClassOutline classOutline) {
    JDefinedClass impl = classOutline.implClass;
    JMethod cloneMethod = impl.method(JMod.PUBLIC, impl, METHOD_CLONE);
    JBlock body = cloneMethod.body();
    if (impl.isAbstract()) {
        body._return(JExpr._this());
        //don't create clone() method body on abstract prism objects
        return;
    }
    Outline outline = classOutline.parent();
    JVar object = body.decl(impl, "object", JExpr._new(impl));
    if (ProcessorUtils.hasParentAnnotation(classOutline, SchemaProcessor.A_PRISM_OBJECT)) {
        JClass type = (JClass) outline.getModel().codeModel._ref(PrismObject.class);
        JVar prism = body.decl(type, "value", JExpr.invoke(SchemaProcessor.METHOD_AS_PRISM_OBJECT).invoke(METHOD_CLONE));
        JInvocation invocation = object.invoke(SchemaProcessor.METHOD_SETUP_CONTAINER);
        invocation.arg(prism);
        body.add(invocation);
    } else if (ProcessorUtils.hasParentAnnotation(classOutline, SchemaProcessor.A_PRISM_CONTAINER)) {
        JClass type = (JClass) outline.getModel().codeModel._ref(PrismContainerValue.class);
        JVar prism = body.decl(type, "value", JExpr.invoke(SchemaProcessor.METHOD_AS_PRISM_CONTAINER_VALUE).invoke(METHOD_CLONE));
        JInvocation invocation = object.invoke(SchemaProcessor.METHOD_SETUP_CONTAINER_VALUE);
        invocation.arg(prism);
        body.add(invocation);
    } else if (ProcessorUtils.hasParentAnnotation(classOutline, SchemaProcessor.A_OBJECT_REFERENCE)) {
        JClass type = (JClass) outline.getModel().codeModel._ref(PrismReferenceValue.class);
        JVar prism = body.decl(type, "value", JExpr.invoke(SchemaProcessor.METHOD_AS_REFERENCE_VALUE).invoke(METHOD_CLONE));
        JInvocation invocation = object.invoke(SchemaProcessor.METHOD_SETUP_REFERENCE_VALUE);
        invocation.arg(prism);
        body.add(invocation);
    }
    body._return(object);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) Outline(com.sun.tools.xjc.outline.Outline)

Example 10 with ClassOutline

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

the class CloneProcessor method run.

@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws Exception {
    PluginImpl clonePlugin = new PluginImpl();
    clonePlugin.run(outline, opt, errorHandler);
    Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet();
    for (Map.Entry<NClass, CClassInfo> entry : set) {
        ClassOutline classOutline = outline.getClazz(entry.getValue());
        if (isPrism(classOutline)) {
            removeConstructors(classOutline);
            removeCloneableMethod(classOutline);
            removePrivateStaticCopyMethods(classOutline);
            createCloneMethod(classOutline);
        }
    }
    return true;
}
Also used : ClassOutline(com.sun.tools.xjc.outline.ClassOutline) CClassInfo(com.sun.tools.xjc.model.CClassInfo) NClass(com.sun.tools.xjc.model.nav.NClass) PluginImpl(net.sourceforge.ccxjc.PluginImpl) Map(java.util.Map)

Aggregations

ClassOutline (com.sun.tools.xjc.outline.ClassOutline)13 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 PrismContainerArrayList (com.evolveum.midpoint.prism.xjc.PrismContainerArrayList)3 PrismReferenceArrayList (com.evolveum.midpoint.prism.xjc.PrismReferenceArrayList)3 ArrayList (java.util.ArrayList)3 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)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 JCodeModel (com.sun.codemodel.JCodeModel)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1 JMethod (com.sun.codemodel.JMethod)1