Search in sources :

Example 1 with Outline

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

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 ClassOutline (com.sun.tools.xjc.outline.ClassOutline)1 Outline (com.sun.tools.xjc.outline.Outline)1