use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.
the class AbsModuleGeneratedObjectFactoryTest method parseGeneratedFile.
private void parseGeneratedFile(ModuleMXBeanEntry moduleMXBeanEntry) throws IOException {
Optional<String> copyright = Optional.absent();
GeneratedObject generatedObject = new AbsModuleGeneratedObjectFactory().toGeneratedObject(moduleMXBeanEntry, copyright);
Entry<FullyQualifiedName, File> entry = generatedObject.persist(generatorOutputPath).get();
File dstFile = entry.getValue();
parse(dstFile);
}
use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.
the class ConcreteModuleGeneratedObjectFactoryTest method test.
@Test
public void test() throws Exception {
FullyQualifiedName fqn = new FullyQualifiedName("foo.bar", "Baz");
FullyQualifiedName abstractFQN = new FullyQualifiedName("foo.bar", "AbstractBaz");
String nullableDescription = null;
ModuleMXBeanEntry moduleMXBeanEntry = mockModuleMXBeanEntry(fqn, abstractFQN, nullableDescription);
Optional<String> copyright = Optional.absent();
Optional<String> header = Optional.absent();
GeneratedObject go = new ConcreteModuleGeneratedObjectFactory().toGeneratedObject(moduleMXBeanEntry, copyright, header);
Entry<FullyQualifiedName, File> entry = go.persist(generatorOutputPath).get();
File dstFile = entry.getValue();
Node c = parse(dstFile);
assertEquals(fqn.getPackageName(), ((ASTCompilationUnit) c).getPackageDeclaration().getPackageNameImage());
assertEquals(fqn.getTypeName(), c.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getImage());
assertHasMethodNamed(c, "customValidation");
assertHasMethodNamed(c, "createInstance");
}
use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.
the class AbsFactoryGeneratedObjectFactory method getServiceIfcsInitialization.
private static String getServiceIfcsInitialization(List<FullyQualifiedName> providedServices) {
String generic = format("Class<? extends %s>", AbstractServiceInterface.class.getCanonicalName());
StringBuilder result = new StringBuilder("static {\n");
if (!providedServices.isEmpty()) {
result.append(format("java.util.Set<%1$s> serviceIfcs2 = new java.util.HashSet<>();\n", generic));
for (FullyQualifiedName fqn : providedServices) {
result.append(format("serviceIfcs2.add(%s.class);\n", fqn));
}
result.append("serviceIfcs = java.util.Collections.unmodifiableSet(serviceIfcs2);\n");
} else {
result.append("serviceIfcs = java.util.Collections.emptySet();\n");
}
result.append("}\n");
// add isModuleImplementingServiceInterface and getImplementedServiceIntefaces methods
result.append(format("\n" + "@Override\n" + "public final boolean isModuleImplementingServiceInterface(Class<? extends %1$s> serviceInterface) " + "{\n" + "for (Class<?> ifc: serviceIfcs) {\n" + "if (serviceInterface.isAssignableFrom(ifc)){\n" + "return true;\n" + "}\n" + "}\n" + "return false;\n" + "}\n" + "\n" + "@Override\n" + "public java.util.Set<Class<? extends %1$s>> getImplementedServiceIntefaces() {\n" + "return serviceIfcs;\n" + "}\n", AbstractServiceInterface.class.getCanonicalName()));
return result.toString();
}
use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.
the class AbsModuleGeneratedObjectFactory method toGeneratedObject.
public GeneratedObject toGeneratedObject(FullyQualifiedName abstractFQN, Optional<String> copyright, Optional<String> header, Optional<String> classJavaDoc, Optional<FullyQualifiedName> extended, List<FullyQualifiedName> implementedInterfaces, List<ModuleField> moduleFields, Optional<FullyQualifiedName> maybeRegistratorType, List<? extends Method> methods, QName yangModuleQName) {
JavaFileInputBuilder b = new JavaFileInputBuilder();
Annotation moduleQNameAnnotation = Annotation.createModuleQNameANnotation(yangModuleQName);
b.addClassAnnotation(moduleQNameAnnotation);
b.setFqn(abstractFQN);
b.setTypeName(TypeName.absClassType);
b.setCopyright(copyright);
b.setHeader(header);
b.setClassJavaDoc(classJavaDoc);
for (FullyQualifiedName implemented : implementedInterfaces) {
b.addImplementsFQN(implemented);
}
if (extended.isPresent()) {
b.addExtendsFQN(extended.get());
}
if (classJavaDoc.isPresent()) {
b.addClassAnnotation(format("@%s(value=\"%s\")", Description.class.getCanonicalName(), classJavaDoc.get()));
}
// add logger:
b.addToBody(getLoggerDefinition(abstractFQN));
b.addToBody("//attributes start");
for (ModuleField moduleField : moduleFields) {
b.addToBody(moduleField.toString() + "\n");
}
b.addToBody("//attributes end");
b.addToBody(getNewConstructor(abstractFQN));
b.addToBody(getCopyFromOldConstructor(abstractFQN));
b.addToBody(getRuntimeRegistratorCode(maybeRegistratorType));
b.addToBody(getValidationMethods(moduleFields));
b.addToBody(getCachesOfResolvedDependencies(moduleFields));
b.addToBody(getCachesOfResolvedIdentityRefs(moduleFields));
b.addToBody(getResolveDependencies(moduleFields));
b.addToBody(getReuseLogic(moduleFields, abstractFQN));
b.addToBody(getEqualsAndHashCode(abstractFQN));
b.addToBody(getMethods(methods));
b.addToBody(getGetLogger());
return new GeneratedObjectBuilder(b.build()).toGeneratedObject();
}
use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.
the class AbsFactoryGeneratedObjectFactory method toGeneratedObject.
public GeneratedObject toGeneratedObject(ModuleMXBeanEntry mbe, Optional<String> copyright) {
FullyQualifiedName absFactoryFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getAbstractFactoryName());
FullyQualifiedName moduleFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getStubModuleName());
Optional<String> classJavaDoc = Optional.fromNullable(mbe.getNullableDescription());
AbstractFactoryTemplate abstractFactoryTemplate = TemplateFactory.abstractFactoryTemplateFromMbe(mbe);
Optional<String> header = abstractFactoryTemplate.getHeaderString();
List<FullyQualifiedName> providedServices = new ArrayList<>();
for (String providedService : mbe.getProvidedServices().keySet()) {
providedServices.add(FullyQualifiedName.fromString(providedService));
}
return toGeneratedObject(absFactoryFQN, copyright, header, classJavaDoc, mbe.getYangModuleQName(), mbe.getGloballyUniqueName(), providedServices, moduleFQN, abstractFactoryTemplate.getFields());
}
Aggregations