use of com.sun.tools.xjc.outline.ClassOutline 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.outline.ClassOutline 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.outline.ClassOutline in project midpoint by Evolveum.
the class SchemaProcessor method isContainer.
private boolean isContainer(JDefinedClass definedClass, Outline outline) {
ClassOutline classOutline = findClassOutline(definedClass, outline);
if (classOutline == null) {
return false;
}
boolean isContainer = hasAnnotation(classOutline, A_PRISM_CONTAINER) || hasAnnotation(classOutline, A_PRISM_OBJECT);
if (isContainer) {
return true;
}
if (!(definedClass._extends() instanceof JDefinedClass)) {
return false;
}
return isContainer((JDefinedClass) definedClass._extends(), outline);
}
use of com.sun.tools.xjc.outline.ClassOutline 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.outline.ClassOutline 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;
}
Aggregations