use of org.oasisopen.odata.csdl.v4.TComplexType in project odata-client by davidmoten.
the class Util method replaceAlias.
private static void replaceAlias(Schema schema, Object x) {
if (schema.getAlias() == null) {
return;
}
if (x instanceof TEntityType) {
TEntityType p = (TEntityType) x;
// mutate types to use alias
p.setBaseType(replaceAlias(schema, p.getBaseType()));
//
p.getKeyOrPropertyOrNavigationProperty().forEach(y -> replaceAlias(schema, y));
} else if (x instanceof TComplexType) {
TComplexType p = (TComplexType) x;
// mutate types to use alias
p.setBaseType(replaceAlias(schema, p.getBaseType()));
//
p.getPropertyOrNavigationPropertyOrAnnotation().forEach(y -> replaceAlias(schema, y));
} else if (x instanceof TAction) {
TAction a = (TAction) x;
//
a.getParameterOrAnnotationOrReturnType().forEach(y -> replaceAlias(schema, y));
} else if (x instanceof TFunction) {
TFunction a = (TFunction) x;
//
a.getParameterOrAnnotation().forEach(y -> replaceAlias(schema, y));
replaceAlias(schema, a.getReturnType());
} else if (x instanceof TActionFunctionParameter) {
TActionFunctionParameter p = (TActionFunctionParameter) x;
replaceAlias(schema, p.getType());
} else if (x instanceof TActionFunctionReturnType) {
TActionFunctionReturnType p = (TActionFunctionReturnType) x;
replaceAlias(schema, p.getType());
} else if (x instanceof TProperty) {
TProperty p = (TProperty) x;
replaceAlias(schema, p.getType());
} else if (x instanceof TNavigationProperty) {
TNavigationProperty p = (TNavigationProperty) x;
replaceAlias(schema, p.getType());
} else if (x instanceof TAnnotations) {
TAnnotations a = (TAnnotations) x;
a.setTarget(replaceAlias(schema, a.getTarget()));
} else if (x instanceof TEntityContainer) {
TEntityContainer a = (TEntityContainer) x;
Util.filter(a.getEntitySetOrActionImportOrFunctionImport(), TEntitySet.class).forEach(y -> replaceAlias(schema, y));
} else if (x instanceof TEntitySet) {
TEntitySet a = (TEntitySet) x;
a.setEntityType(replaceAlias(schema, a.getEntityType()));
}
}
use of org.oasisopen.odata.csdl.v4.TComplexType in project odata-client by davidmoten.
the class Generator method writeComplexType.
private void writeComplexType(Schema schema, TComplexType complexType) {
ComplexType t = new ComplexType(complexType, names);
t.getDirectoryComplexType().mkdirs();
String simpleClassName = t.getSimpleClassName();
Imports imports = new Imports(t.getFullClassName());
Indent indent = new Indent();
StringWriter w = new StringWriter();
try (PrintWriter p = new PrintWriter(w)) {
p.format("package %s;\n\n", t.getPackage());
p.format(IMPORTSHERE);
t.printJavadoc(p, indent);
printPropertyOrder(imports, p, t.getProperties());
printJsonIncludesNonNull(indent, imports, p);
p.format("public class %s%s implements %s {\n", simpleClassName, t.getExtendsClause(imports), imports.add(ODataType.class));
indent.right();
if (!t.hasBaseType()) {
addContextPathInjectableField(imports, indent, p);
}
if (!t.hasBaseType()) {
addUnmappedFieldsField(imports, indent, p);
}
// write fields from properties
printPropertyFields(imports, indent, p, t.getProperties(), t.hasBaseType());
// write constructor
writeNoArgsConstructor(simpleClassName, indent, p, t.hasBaseType());
p.format("\n%s@%s\n", indent, imports.add(Override.class));
p.format("%spublic String odataTypeName() {\n", indent);
p.format("%sreturn \"%s\";\n", indent.right(), t.getFullType());
p.format("%s}\n", indent.left());
Set<String> methodNames = new HashSet<>();
printPropertyGetterAndSetters(t, imports, indent, p, simpleClassName, t.getFullType(), t.getProperties(), false, methodNames);
addUnmappedFieldsSetterAndGetter(imports, indent, p, methodNames);
p.format("\n%s@%s\n", indent, imports.add(Override.class));
p.format("%spublic void postInject(boolean addKeysToContextPath) {\n", indent);
p.format("%s// do nothing;\n", indent.right());
p.format("%s}\n", indent.left());
writeBuilder(t, simpleClassName, imports, indent, p);
// write copy method
writeCopyMethod(t, simpleClassName, imports, indent, p, false);
// write toString
writeToString(t, simpleClassName, imports, indent, p);
p.format("\n}\n");
writeToFile(imports, w, t.getClassFile());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations