Search in sources :

Example 6 with FullyQualifiedName

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.

the class AbsFactoryGeneratedObjectFactory method toGeneratedObject.

public GeneratedObject toGeneratedObject(FullyQualifiedName absFactoryFQN, Optional<String> copyright, Optional<String> header, Optional<String> classJavaDoc, QName yangModuleQName, String globallyUniqueName, List<FullyQualifiedName> providedServices, FullyQualifiedName moduleFQN, List<Field> moduleFields) {
    JavaFileInputBuilder b = new JavaFileInputBuilder();
    b.addImportFQN(new FullyQualifiedName(Module.class));
    b.addImportFQN(new FullyQualifiedName(ModuleIdentifier.class));
    Annotation moduleQNameAnnotation = Annotation.createModuleQNameANnotation(yangModuleQName);
    b.addClassAnnotation(moduleQNameAnnotation);
    b.setFqn(absFactoryFQN);
    b.setTypeName(TypeName.absClassType);
    b.setCopyright(copyright);
    b.setHeader(header);
    b.setClassJavaDoc(classJavaDoc);
    b.addImplementsFQN(new FullyQualifiedName(ModuleFactory.class));
    if (classJavaDoc.isPresent()) {
        b.addClassAnnotation(format("@%s(value=\"%s\")", Description.class.getCanonicalName(), classJavaDoc.get()));
    }
    b.addToBody(format("public static final java.lang.String NAME = \"%s\";", globallyUniqueName));
    b.addToBody(format("private static final java.util.Set<Class<? extends %s>> serviceIfcs;", AbstractServiceInterface.class.getCanonicalName()));
    b.addToBody("@Override\n public final String getImplementationName() { \n return NAME; \n}");
    b.addToBody(getServiceIfcsInitialization(providedServices));
    // createModule
    b.addToBody(format("\n" + "@Override\n" + "public %s createModule(String instanceName, %s dependencyResolver, %s bundleContext) {\n" + "return instantiateModule(instanceName, dependencyResolver, bundleContext);\n" + "}\n", Module.class.getCanonicalName(), DependencyResolver.class.getCanonicalName(), BUNDLE_CONTEXT));
    b.addToBody(getCreateModule(moduleFQN, moduleFields));
    b.addToBody(format("\n" + "public %s instantiateModule(String instanceName, %s dependencyResolver, %s oldModule, %s oldInstance, %s bundleContext) {\n" + "return new %s(new %s(NAME, instanceName), dependencyResolver, oldModule, oldInstance);\n" + "}\n", moduleFQN, DependencyResolver.class.getCanonicalName(), moduleFQN, AutoCloseable.class.getCanonicalName(), BUNDLE_CONTEXT, moduleFQN, ModuleIdentifier.class.getCanonicalName()));
    b.addToBody(format("\n" + "public %s instantiateModule(String instanceName, %s dependencyResolver, %s bundleContext) {\n" + "return new %s(new %s(NAME, instanceName), dependencyResolver);\n" + "}\n", moduleFQN, DependencyResolver.class.getCanonicalName(), BUNDLE_CONTEXT, moduleFQN, ModuleIdentifier.class.getCanonicalName()));
    b.addToBody(format("\n" + "public %s handleChangedClass(%s dependencyResolver, %s old, %s bundleContext) throws Exception {\n" + // "// @Deprecated return handleChangedClass(old);\n" +
    "String instanceName = old.getModule().getIdentifier().getInstanceName();\n" + "%1$s newModule = new %1$s(new ModuleIdentifier(NAME, instanceName), dependencyResolver);\n" + "Module oldModule = old.getModule();\n" + "Class<? extends Module> oldModuleClass = oldModule.getClass();\n" + genCodeToCopyAttributes(moduleFields) + "return newModule;\n" + "}\n", moduleFQN, DependencyResolver.class.getCanonicalName(), DynamicMBeanWithInstance.class.getCanonicalName(), BUNDLE_CONTEXT));
    b.addToBody(format("\n@Deprecated\n" + "public %s handleChangedClass(%s old) throws Exception {\n" + "throw new UnsupportedOperationException(\"Class reloading is not supported\");\n" + "}\n", moduleFQN, DynamicMBeanWithInstance.class.getCanonicalName()));
    b.addToBody(format("\n" + "@Override\n" + "public java.util.Set<%s> getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory dependencyResolverFactory, %s bundleContext) {\n" + "return new java.util.HashSet<>();\n" + "}\n", moduleFQN, BUNDLE_CONTEXT));
    return new GeneratedObjectBuilder(b.build()).toGeneratedObject();
}
Also used : ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) GeneratedObjectBuilder(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder) FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) Module(org.opendaylight.controller.config.spi.Module) Annotation(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation) JavaFileInputBuilder(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder)

Example 7 with FullyQualifiedName

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.

the class AbsModuleGeneratedObjectFactory method toGeneratedObject.

public GeneratedObject toGeneratedObject(ModuleMXBeanEntry mbe, Optional<String> copyright) {
    FullyQualifiedName abstractFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getAbstractModuleName());
    Optional<String> classJavaDoc = Optional.fromNullable(mbe.getNullableDescription());
    AbstractModuleTemplate abstractModuleTemplate = TemplateFactory.abstractModuleTemplateFromMbe(mbe);
    Optional<String> header = abstractModuleTemplate.getHeaderString();
    List<FullyQualifiedName> implementedInterfaces = Lists.transform(abstractModuleTemplate.getTypeDeclaration().getImplemented(), FullyQualifiedName::fromString);
    Optional<FullyQualifiedName> extended = Optional.fromNullable(Iterables.getFirst(Collections2.transform(abstractModuleTemplate.getTypeDeclaration().getExtended(), FullyQualifiedName::fromString), null));
    Optional<FullyQualifiedName> maybeRegistratorType;
    if (abstractModuleTemplate.isRuntime()) {
        maybeRegistratorType = Optional.of(FullyQualifiedName.fromString(abstractModuleTemplate.getRegistratorType()));
    } else {
        maybeRegistratorType = Optional.absent();
    }
    return toGeneratedObject(abstractFQN, copyright, header, classJavaDoc, extended, implementedInterfaces, abstractModuleTemplate.getModuleFields(), maybeRegistratorType, abstractModuleTemplate.getMethods(), mbe.getYangModuleQName());
}
Also used : FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) AbstractModuleTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractModuleTemplate)

Example 8 with FullyQualifiedName

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.

the class ConcreteModuleGeneratedObjectFactory method toGeneratedObject.

public GeneratedObject toGeneratedObject(ModuleMXBeanEntry mbe, Optional<String> copyright, Optional<String> header) {
    FullyQualifiedName concreteFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getStubModuleName());
    FullyQualifiedName abstractFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getAbstractModuleName());
    Optional<String> classJavaDoc = Optional.fromNullable(mbe.getNullableDescription());
    return toGeneratedObject(concreteFQN, abstractFQN, copyright, header, classJavaDoc);
}
Also used : FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName)

Example 9 with FullyQualifiedName

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName in project controller by opendaylight.

the class GenericGeneratedObjectFactory method toGeneratedObject.

public GeneratedObject toGeneratedObject(FtlTemplate template, Optional<String> copyright) {
    JavaFileInputBuilder b = new JavaFileInputBuilder();
    b.setHeader(template.getHeaderString());
    b.setFqn(new FullyQualifiedName(template.getPackageName(), template.getTypeDeclaration().getName()));
    b.setClassJavaDoc(template.getMaybeJavadoc());
    for (Annotation annotation : template.getAnnotations()) {
        b.addClassAnnotation(annotation);
    }
    // type declaration
    for (String extended : template.getTypeDeclaration().getExtended()) {
        b.addExtendsFQN(FullyQualifiedName.fromString(extended));
    }
    for (String implemented : template.getTypeDeclaration().getImplemented()) {
        b.addImplementsFQN(FullyQualifiedName.fromString(implemented));
    }
    b.setCopyright(copyright);
    b.setTypeName(template.getTypeDeclaration().toTypeName());
    // fields
    for (Field field : template.getFields()) {
        b.addToBody(field.toString());
    }
    // constructors
    for (Constructor constructor : template.getConstructors()) {
        b.addToBody(constructor.toString());
    }
    // methods
    for (Method method : template.getMethods()) {
        b.addToBody(method.toString());
    }
    return new GeneratedObjectBuilder(b.build()).toGeneratedObject();
}
Also used : Field(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field) Constructor(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor) GeneratedObjectBuilder(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder) FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) Method(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method) Annotation(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation) JavaFileInputBuilder(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder)

Aggregations

FullyQualifiedName (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName)9 Annotation (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation)3 GeneratedObjectBuilder (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder)3 JavaFileInputBuilder (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder)3 File (java.io.File)2 GeneratedObject (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject)2 ArrayList (java.util.ArrayList)1 Node (net.sourceforge.pmd.lang.ast.Node)1 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)1 Test (org.junit.Test)1 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)1 AbstractServiceInterface (org.opendaylight.controller.config.api.annotations.AbstractServiceInterface)1 Module (org.opendaylight.controller.config.spi.Module)1 ModuleFactory (org.opendaylight.controller.config.spi.ModuleFactory)1 ModuleMXBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry)1 AbstractFactoryTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractFactoryTemplate)1 AbstractModuleTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractModuleTemplate)1 Constructor (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor)1 Field (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field)1 IdentityRefModuleField (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField)1