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);
}
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");
}
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);
}
}
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;
}
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);
}
}
Aggregations