use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField in project controller by opendaylight.
the class AbsModuleGeneratedObjectFactory method getResolveDependencies.
private static String getResolveDependencies(final List<ModuleField> moduleFields) {
// loop through dependent fields, use dependency resolver to instantiate dependencies. Do it in loop in case field represents list of dependencies.
Map<ModuleField, String> resolveDependenciesMap = new HashMap<>();
for (ModuleField moduleField : moduleFields) {
if (moduleField.isDependent()) {
String str;
String osgi = moduleField.getDependency().getSie().getExportedOsgiClassName();
if (moduleField.isList()) {
str = format("%sDependency = new java.util.ArrayList<%s>();\n" + "for(javax.management.ObjectName dep : %1$s) {\n" + "%1$sDependency.add(dependencyResolver.resolveInstance(%2$s.class, dep, %1$sJmxAttribute));\n" + "}\n", moduleField.getName(), osgi);
} else {
str = format("%1$sDependency = dependencyResolver.resolveInstance(%2$s.class, %1$s, %1$sJmxAttribute);\n", moduleField.getName(), osgi);
}
resolveDependenciesMap.put(moduleField, str);
}
}
StringBuilder result = new StringBuilder("\n" + "protected final void resolveDependencies() {\n");
// wrap each field resolvation statement with if !=null when dependency is not mandatory
for (Map.Entry<ModuleField, String> entry : resolveDependenciesMap.entrySet()) {
if (!entry.getKey().getDependency().isMandatory()) {
checkState(entry.getValue().endsWith(";\n"));
result.append(format("if (%s!=null) {\n%s}\n", entry.getKey().getName(), entry.getValue()));
} else {
result.append(entry.getValue());
}
}
// add code to inject dependency resolver to fields that support it
for (ModuleField moduleField : moduleFields) {
if (moduleField.isNeedsDepResolver()) {
result.append(format("if (%s!=null){\n", moduleField.getName()));
if (moduleField.isList()) {
result.append(format("for(%s candidate : %s) {\n" + "candidate.injectDependencyResolver(dependencyResolver);\n" + "}\n", moduleField.getGenericInnerType(), moduleField.getName()));
} else {
result.append(format("%s.injectDependencyResolver(dependencyResolver);\n", moduleField.getName()));
}
result.append("}\n");
}
}
// identity refs need to be injected with dependencyResolver and base class
for (ModuleField moduleField : moduleFields) {
if (moduleField.isIdentityRef()) {
result.append(format("if (%s!=null) {", moduleField.getName()));
result.append(format("set%s(%s.resolveIdentity(dependencyResolver, %s.class));", moduleField.getAttributeName(), moduleField.getName(), ((IdentityRefModuleField) moduleField).getIdentityBaseClass()));
result.append("}\n");
}
}
result.append("}\n");
return result.toString();
}
use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField in project controller by opendaylight.
the class AbsModuleGeneratedObjectFactory method getCachesOfResolvedIdentityRefs.
private static String getCachesOfResolvedIdentityRefs(List<ModuleField> moduleFields) {
StringBuilder result = new StringBuilder();
for (ModuleField moduleField : moduleFields) {
if (moduleField.isIdentityRef()) {
IdentityRefModuleField field = (IdentityRefModuleField) moduleField;
result.append(format("private %s %s;\n", field.getIdentityClassType(), field.getIdentityClassName()));
}
}
return result.toString();
}
Aggregations