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