use of com.dexels.navajo.mapping.GenericMultipleDependentResource in project navajo by Dexels.
the class TslCompiler method checkDependentFieldResource.
private final void checkDependentFieldResource(Class localContextClass, String fieldName, List<String> expressionValues, List<Dependency> deps) {
if (!(HasDependentResources.class.isAssignableFrom(localContextClass))) {
return;
}
if (expressionValues == null) {
return;
}
for (int all = 0; all < expressionValues.size(); all++) {
String expressionValue = expressionValues.get(all);
DependentResource[] dependentFields = instantiatedAdapters.get(localContextClass);
if (dependentFields == null && HasDependentResources.class.isAssignableFrom(localContextClass)) {
try {
HasDependentResources hr = (HasDependentResources) localContextClass.getDeclaredConstructor().newInstance();
dependentFields = hr.getDependentResourceFields();
} catch (Throwable t) {
logger.error("Dependency detection problem:", t);
}
instantiatedAdapters.put(localContextClass, dependentFields);
}
if (dependentFields == null) {
return;
}
for (int i = 0; i < dependentFields.length; i++) {
if (fieldName.equals(dependentFields[i].getValue())) {
if (dependentFields[i] instanceof GenericMultipleDependentResource) {
Class<? extends AdapterFieldDependency> depClass = dependentFields[i].getDependencyClass();
try {
Constructor c = depClass.getConstructor(long.class, String.class, String.class, String.class);
AdapterFieldDependency afd = (AdapterFieldDependency) c.newInstance(-1, localContextClass.getName(), dependentFields[i].getType(), expressionValue);
deps.add(afd);
AdapterFieldDependency[] allDeps = (AdapterFieldDependency[]) afd.getMultipleDependencies();
for (int a = 0; a < allDeps.length; a++) {
addDependency("dependentObjects.add( new " + depClass.getName() + "(-1, \"" + allDeps[a].getJavaClass() + "\", \"" + allDeps[a].getType() + "\", \"" + allDeps[a].getId() + "\"));\n", "FIELD" + allDeps[a].getJavaClass() + ";" + allDeps[a].getType() + ";" + fieldName + ";" + allDeps[a].getId());
deps.add(allDeps[a]);
}
} catch (Exception e) {
logger.info("Error adding dependency, wasn't logged before so reduced level to info. ", e);
}
} else {
addDependency("dependentObjects.add( new AdapterFieldDependency(-1, \"" + localContextClass.getName() + "\", \"" + dependentFields[i].getType() + "\", \"" + expressionValue + "\"));\n", "FIELD" + localContextClass.getName() + ";" + dependentFields[i].getType() + ";" + fieldName + ";" + expressionValue);
Dependency d = new AdapterFieldDependency(-1, localContextClass.getName(), dependentFields[i].getType(), expressionValue);
deps.add(d);
}
}
}
}
}
Aggregations