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);
}
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);
}
}
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));
}
}
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);
}
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;
}
Aggregations