Search in sources :

Example 6 with CClassInfo

use of com.sun.tools.xjc.model.CClassInfo 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 7 with CClassInfo

use of com.sun.tools.xjc.model.CClassInfo 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 8 with CClassInfo

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

Example 9 with CClassInfo

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

the class SchemaProcessor method addComplextType.

private void addComplextType(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 = entry.getValue().getTypeName();
        if (qname == null) {
            continue;
        }
        JFieldVar var = namespaceFields.get(qname.getNamespaceURI());
        if (var != null) {
            createQNameDefinition(outline, classOutline.implClass, COMPLEX_TYPE_FIELD_NAME, var, qname);
        } else {
            createPSFField(outline, classOutline.implClass, COMPLEX_TYPE_FIELD_NAME, qname);
        }
    }
}
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 10 with CClassInfo

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

the class SchemaProcessor method isFieldReference.

private boolean isFieldReference(JFieldVar field, ClassOutline classOutline) {
    CPropertyInfo propertyInfo = classOutline.target.getProperty(field.name());
    Collection<? extends CTypeInfo> collection = propertyInfo.ref();
    if (collection == null || collection.isEmpty()) {
        return false;
    }
    CTypeInfo info = collection.iterator().next();
    if (info instanceof CClassInfo) {
        CClassInfo classInfo = (CClassInfo) info;
        if (OBJECT_REFERENCE_TYPE.equals(classInfo.getTypeName())) {
            return true;
        }
    }
    return false;
}
Also used : CClassInfo(com.sun.tools.xjc.model.CClassInfo) CTypeInfo(com.sun.tools.xjc.model.CTypeInfo) CPropertyInfo(com.sun.tools.xjc.model.CPropertyInfo)

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