Search in sources :

Example 1 with GeneratedObject

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject 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);
}
Also used : FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) GeneratedObject(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject) AbsModuleGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsModuleGeneratedObjectFactory) File(java.io.File)

Example 2 with GeneratedObject

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject 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");
}
Also used : ConcreteModuleGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.ConcreteModuleGeneratedObjectFactory) ASTCompilationUnit(net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) Node(net.sourceforge.pmd.lang.ast.Node) FullyQualifiedName(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName) GeneratedObject(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject) File(java.io.File) AbstractGeneratedObjectTest(org.opendaylight.controller.config.yangjmxgenerator.plugin.module.AbstractGeneratedObjectTest) Test(org.junit.Test)

Example 3 with GeneratedObject

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

the class CodeWriter method writeSie.

public File writeSie(final ServiceInterfaceEntry sie, final File outputBaseDir) {
    try {
        GeneralInterfaceTemplate generalInterfaceTemplate = TemplateFactory.serviceInterfaceFromSie(sie);
        GeneratedObject go = new GenericGeneratedObjectFactory().toGeneratedObject(generalInterfaceTemplate, COPYRIGHT);
        return go.persist(outputBaseDir).get().getValue();
    } catch (Exception e) {
        String message = "An error occurred during Service interface generating, sie:" + sie.getTypeName() + ", " + sie.getFullyQualifiedName();
        LOG.error(message, e);
        throw new RuntimeException(message, e);
    }
}
Also used : GeneralInterfaceTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate) GeneratedObject(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject) GenericGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.GenericGeneratedObjectFactory) IOException(java.io.IOException)

Example 4 with GeneratedObject

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

the class CodeWriter method persistGeneratedObjects.

private static List<File> persistGeneratedObjects(final File targetBaseDir, final File mainBaseDir, final Map<GeneratedObject, Boolean> gos) throws IOException {
    List<File> generatedFiles = new ArrayList<>();
    for (Entry<GeneratedObject, Boolean> entry : gos.entrySet()) {
        boolean overwrite = entry.getValue();
        File dst;
        if (overwrite) {
            dst = targetBaseDir;
        } else {
            dst = mainBaseDir;
        }
        Optional<Entry<FullyQualifiedName, File>> maybePersistEntry = entry.getKey().persist(dst, overwrite);
        if (maybePersistEntry.isPresent()) {
            generatedFiles.add(maybePersistEntry.get().getValue());
        }
    }
    return generatedFiles;
}
Also used : RuntimeBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) ServiceInterfaceEntry(org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) GeneratedObject(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject) File(java.io.File)

Example 5 with GeneratedObject

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

the class CodeWriter method writeMbe.

public List<File> writeMbe(final ModuleMXBeanEntry mbe, final File targetBaseDir, final File mainBaseDir) {
    try {
        List<File> generatedFiles = Lists.newArrayList();
        Map<GeneratedObject, Boolean> /*overwrite*/
        gos = new HashMap<>();
        // generate mx interface and abstract factory
        // TOs
        Map<String, GeneralClassTemplate> tosFromMbe = TemplateFactory.tOsFromMbe(mbe);
        for (GeneralClassTemplate template : tosFromMbe.values()) {
            gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(template, COPYRIGHT), true);
        }
        // MXBean interface
        GeneralInterfaceTemplate ifcTemplate = TemplateFactory.mXBeanInterfaceTemplateFromMbe(mbe);
        gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(ifcTemplate, COPYRIGHT), true);
        // generate abstract factory
        gos.put(new AbsFactoryGeneratedObjectFactory().toGeneratedObject(mbe, COPYRIGHT), true);
        // generate abstract module
        gos.put(new AbsModuleGeneratedObjectFactory().toGeneratedObject(mbe, COPYRIGHT), true);
        // generate concrete factory
        StubFactoryTemplate concreteFactory = TemplateFactory.stubFactoryTemplateFromMbe(mbe);
        gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(concreteFactory, COPYRIGHT), false);
        // generate concrete module
        gos.put(new ConcreteModuleGeneratedObjectFactory().toGeneratedObject(mbe, COPYRIGHT, Optional.<String>absent()), false);
        // write runtime bean MXBeans and registrators
        List<FtlTemplate> allFtlFiles = getRuntimeBeanFtlTemplates(mbe.getRuntimeBeans());
        for (FtlTemplate template : allFtlFiles) {
            gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(template, COPYRIGHT), true);
        }
        generatedFiles.addAll(persistGeneratedObjects(targetBaseDir, mainBaseDir, gos));
        // purge nulls
        for (Iterator<File> it = generatedFiles.iterator(); it.hasNext(); ) {
            if (it.next() == null) {
                it.remove();
            }
        }
        return generatedFiles;
    } catch (Exception e) {
        String message = "An error occurred during Module generating, mbe:" + mbe.getJavaNamePrefix();
        LOG.error(message, e);
        throw new RuntimeException(message, e);
    }
}
Also used : GeneralInterfaceTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate) HashMap(java.util.HashMap) GeneralClassTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate) AbsFactoryGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsFactoryGeneratedObjectFactory) GenericGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.GenericGeneratedObjectFactory) IOException(java.io.IOException) ConcreteModuleGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.ConcreteModuleGeneratedObjectFactory) GeneratedObject(org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject) StubFactoryTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.StubFactoryTemplate) AbsModuleGeneratedObjectFactory(org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsModuleGeneratedObjectFactory) FtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate) RuntimeRegistratorFtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.RuntimeRegistratorFtlTemplate) File(java.io.File)

Aggregations

GeneratedObject (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject)5 File (java.io.File)4 IOException (java.io.IOException)2 ModuleMXBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry)2 GeneralInterfaceTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate)2 AbsModuleGeneratedObjectFactory (org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsModuleGeneratedObjectFactory)2 ConcreteModuleGeneratedObjectFactory (org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.ConcreteModuleGeneratedObjectFactory)2 GenericGeneratedObjectFactory (org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.GenericGeneratedObjectFactory)2 FullyQualifiedName (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Node (net.sourceforge.pmd.lang.ast.Node)1 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)1 Test (org.junit.Test)1 RuntimeBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry)1 ServiceInterfaceEntry (org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry)1 FtlTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate)1 GeneralClassTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate)1 RuntimeRegistratorFtlTemplate (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.RuntimeRegistratorFtlTemplate)1