X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-jmx-generator-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyangjmxgenerator%2Fplugin%2Fftl%2FTemplateFactory.java;h=00454d8acf14507a518e63b5d71b79020ce89bfd;hp=f8f5cd6742a1182e47c7194fb3ec215316ce7ca5;hb=45757bbd6c220f0f805715c84025c75a9388770a;hpb=0eba94d9411ea40945ddc8c732640c0cc004599f diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java index f8f5cd6742..00454d8acf 100644 --- a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java +++ b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java @@ -10,12 +10,20 @@ package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import javax.management.openmbean.SimpleType; import org.opendaylight.controller.config.api.DependencyResolver; import org.opendaylight.controller.config.api.IdentityAttributeRef; import org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule; import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface; import org.opendaylight.controller.config.api.runtime.RuntimeBean; -import org.opendaylight.controller.config.spi.Module; +import org.opendaylight.controller.config.spi.AbstractModule; import org.opendaylight.controller.config.yangjmxgenerator.AbstractEntry; import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry; import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry; @@ -40,18 +48,9 @@ import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Meth import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition; import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField; import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FullyQualifiedNameHelper; -import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil; import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType; import org.opendaylight.yangtools.sal.binding.model.api.Type; - -import javax.management.openmbean.SimpleType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; +import org.opendaylight.yangtools.yang.binding.BindingMapping; public class TemplateFactory { @@ -60,7 +59,7 @@ public class TemplateFactory { * bean as value that should be persisted from this instance. */ public static Map getTOAndMXInterfaceFtlFiles( - RuntimeBeanEntry entry) { + final RuntimeBeanEntry entry) { Map result = new HashMap<>(); { // create GeneralInterfaceFtlFile for runtime MXBean. Attributes will // be transformed to getter methods @@ -110,7 +109,7 @@ public class TemplateFactory { } // FIXME: put into Type.toString - static String serializeType(Type type, boolean addWildcards) { + static String serializeType(final Type type, final boolean addWildcards) { if (type instanceof ParameterizedType){ ParameterizedType parameterizedType = (ParameterizedType) type; StringBuilder sb = new StringBuilder(); @@ -132,11 +131,11 @@ public class TemplateFactory { } } - static String serializeType(Type type) { + static String serializeType(final Type type) { return serializeType(type, false); } - private static String getReturnType(AttributeIfc attributeIfc) { + private static String getReturnType(final AttributeIfc attributeIfc) { String returnType; if (attributeIfc instanceof TypedAttribute) { Type type = ((TypedAttribute) attributeIfc).getType(); @@ -152,7 +151,7 @@ public class TemplateFactory { } public static GeneralInterfaceTemplate serviceInterfaceFromSie( - ServiceInterfaceEntry sie) { + final ServiceInterfaceEntry sie) { List extendedInterfaces = Lists .newArrayList(AbstractServiceInterface.class.getCanonicalName()); @@ -167,17 +166,18 @@ public class TemplateFactory { Lists. newArrayList()); sieTemplate.setJavadoc(sie.getNullableDescription()); - if (sie.getNullableDescription() != null) + if (sie.getNullableDescription() != null) { sieTemplate.getAnnotations().add( Annotation.createDescriptionAnnotation(sie .getNullableDescription())); + } sieTemplate.getAnnotations().addAll(Annotation.createSieAnnotations(sie)); return sieTemplate; } public static AbstractFactoryTemplate abstractFactoryTemplateFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { AbstractFactoryAttributesProcessor attrProcessor = new AbstractFactoryAttributesProcessor(); attrProcessor.processAttributes(mbe.getAttributes(), mbe.getPackageName()); @@ -191,12 +191,11 @@ public class TemplateFactory { } public static AbstractModuleTemplate abstractModuleTemplateFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { AbstractModuleAttributesProcessor attrProcessor = new AbstractModuleAttributesProcessor(mbe.getAttributes()); List moduleFields = attrProcessor.getModuleFields(); List implementedIfcs = Lists.newArrayList( - Module.class.getCanonicalName(), mbe.getFullyQualifiedName(mbe.getMXBeanInterfaceName())); for (String implementedService : mbe.getProvidedServices().keySet()) { @@ -218,21 +217,24 @@ public class TemplateFactory { .getCanonicalName()); } + List extendedClasses = Collections.singletonList(AbstractModule.class.getCanonicalName() + "<" + mbe.getAbstractModuleName() + ">"); + AbstractModuleTemplate abstractModuleTemplate = new AbstractModuleTemplate( getHeaderFromEntry(mbe), mbe.getPackageName(), - mbe.getAbstractModuleName(), implementedIfcs, moduleFields, + mbe.getAbstractModuleName(), extendedClasses, implementedIfcs, moduleFields, attrProcessor.getMethods(), generateRuntime, registratorFullyQualifiedName); - if (mbe.getNullableDescription() != null) + if (mbe.getNullableDescription() != null) { abstractModuleTemplate.getAnnotations().add( Annotation.createDescriptionAnnotation(mbe .getNullableDescription())); + } return abstractModuleTemplate; } public static StubFactoryTemplate stubFactoryTemplateFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { return new StubFactoryTemplate(getHeaderFromEntry(mbe), mbe.getPackageName(), mbe.getStubFactoryName(), mbe.getFullyQualifiedName(mbe.getAbstractFactoryName()) @@ -240,7 +242,7 @@ public class TemplateFactory { } public static GeneralInterfaceTemplate mXBeanInterfaceTemplateFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { MXBeanInterfaceAttributesProcessor attrProcessor = new MXBeanInterfaceAttributesProcessor(); attrProcessor.processAttributes(mbe.getAttributes()); GeneralInterfaceTemplate ifcTemplate = new GeneralInterfaceTemplate( @@ -252,7 +254,7 @@ public class TemplateFactory { } public static Map tOsFromMbe( - ModuleMXBeanEntry mbe) { + final ModuleMXBeanEntry mbe) { Map retVal = Maps.newHashMap(); TOAttributesProcessor processor = new TOAttributesProcessor(); processor.processAttributes(mbe.getAttributes()); @@ -273,7 +275,7 @@ public class TemplateFactory { } public static Map tOsFromRbe( - RuntimeBeanEntry rbe) { + final RuntimeBeanEntry rbe) { Map retVal = Maps.newHashMap(); TOAttributesProcessor processor = new TOAttributesProcessor(); Map yangPropertiesToTypesMap = Maps.newHashMap(rbe.getYangPropertiesToTypesMap()); @@ -314,7 +316,7 @@ public class TemplateFactory { return retVal; } - private static Header getHeaderFromEntry(AbstractEntry mbe) { + private static Header getHeaderFromEntry(final AbstractEntry mbe) { return new Header(mbe.getYangModuleName(), mbe.getYangModuleLocalname()); } @@ -324,7 +326,7 @@ public class TemplateFactory { private final List tos = Lists.newArrayList(); - void processAttributes(Map attributes) { + void processAttributes(final Map attributes) { for (Entry attrEntry : attributes.entrySet()) { AttributeIfc attributeIfc = attrEntry.getValue(); if (attributeIfc instanceof TOAttribute) { @@ -340,7 +342,7 @@ public class TemplateFactory { } } - private void createTOInternal(TOAttribute toAttribute) { + private void createTOInternal(final TOAttribute toAttribute) { Map attrs = toAttribute.getCapitalizedPropertiesToTypesMap(); // recursive processing of TO's attributes @@ -358,12 +360,12 @@ public class TemplateFactory { private List fields; private List methods; - public TOInternal(Type type, Map attrs) { + public TOInternal(final Type type, final Map attrs) { this(type.getFullyQualifiedName(), type.getName(), attrs, type.getPackageName()); } - public TOInternal(String fullyQualifiedName, String name, - Map attrs, String packageName) { + public TOInternal(final String fullyQualifiedName, final String name, + final Map attrs, final String packageName) { this.fullyQualifiedName = fullyQualifiedName; this.name = name; processAttrs(attrs, packageName); @@ -372,7 +374,7 @@ public class TemplateFactory { private final static String dependencyResolverVarName = "dependencyResolver"; private final static String dependencyResolverInjectMethodName = "injectDependencyResolver"; - private void processAttrs(Map attrs, String packageName) { + private void processAttrs(final Map attrs, final String packageName) { fields = Lists.newArrayList(); methods = Lists.newArrayList(); @@ -384,8 +386,7 @@ public class TemplateFactory { for (Entry attrEntry : attrs.entrySet()) { String innerName = attrEntry.getKey(); - String varName = BindingGeneratorUtil - .parseToValidParamName(attrEntry.getKey()); + String varName = BindingMapping.getPropertyName(attrEntry.getKey()); String fullyQualifiedName, nullableDefault = null; if (attrEntry.getValue() instanceof TypedAttribute) { @@ -447,7 +448,7 @@ public class TemplateFactory { private static class MXBeanInterfaceAttributesProcessor { private final List methods = Lists.newArrayList(); - void processAttributes(Map attributes) { + void processAttributes(final Map attributes) { for (Entry attrEntry : attributes.entrySet()) { String returnType; AttributeIfc attributeIfc = attrEntry.getValue(); @@ -471,8 +472,7 @@ public class TemplateFactory { MethodDeclaration getter = new MethodDeclaration(returnType, getterName, Collections. emptyList()); - String varName = BindingGeneratorUtil - .parseToValidParamName(attrEntry.getKey()); + String varName = BindingMapping.getPropertyName(attrEntry.getKey()); String setterName = "set" + attributeIfc.getUpperCaseCammelCase(); MethodDeclaration setter = new MethodDeclaration("void", @@ -517,8 +517,8 @@ public class TemplateFactory { private final List fields = Lists.newArrayList(); - void processAttributes(Map attributes, - String packageName) { + void processAttributes(final Map attributes, + final String packageName) { for (Entry attrEntry : attributes.entrySet()) { String type; String nullableDefaultWrapped = null; @@ -548,7 +548,7 @@ public class TemplateFactory { private final List moduleFields; private final List methods; - private Holder(List moduleFields, List methods) { + private Holder(final List moduleFields, final List methods) { this.moduleFields = Collections.unmodifiableList(moduleFields); this.methods = Collections.unmodifiableList(methods); } @@ -557,11 +557,11 @@ public class TemplateFactory { private final Holder holder; - private AbstractModuleAttributesProcessor(Map attributes) { + private AbstractModuleAttributesProcessor(final Map attributes) { this.holder = processAttributes(attributes); } - private static Holder processAttributes(Map attributes) { + private static Holder processAttributes(final Map attributes) { List moduleFields = new ArrayList<>(); List methods = new ArrayList<>(); for (Entry attrEntry : attributes.entrySet()) { @@ -605,11 +605,9 @@ public class TemplateFactory { } } - String varName = BindingGeneratorUtil - .parseToValidParamName(attrEntry.getKey()); - { - ModuleField field; + String varName = BindingMapping.getPropertyName(attrEntry.getKey()); + ModuleField field; if (isIdentity) { String identityBaseClass = getInnerTypeFromIdentity(((TypedAttribute) attributeIfc).getType()); IdentityRefModuleField identityField = new IdentityRefModuleField(type, varName, @@ -641,7 +639,8 @@ public class TemplateFactory { nullableDefaultWrapped, isDependency, dependency, isListOfDependencies, needsDepResolver); } moduleFields.add(field); - } + + String getterName = "get" + attributeIfc.getUpperCaseCammelCase(); MethodDefinition getter = new MethodDefinition(type, @@ -687,9 +686,10 @@ public class TemplateFactory { } - private static boolean needsDepResolver(AttributeIfc value) { - if(value instanceof TOAttribute) + private static boolean needsDepResolver(final AttributeIfc value) { + if(value instanceof TOAttribute) { return true; + } if(value instanceof ListAttribute) { AttributeIfc innerAttribute = ((ListAttribute) value).getInnerAttribute(); return needsDepResolver(innerAttribute); @@ -698,7 +698,7 @@ public class TemplateFactory { return false; } - private static String getInnerTypeFromIdentity(Type type) { + private static String getInnerTypeFromIdentity(final Type type) { Preconditions.checkArgument(type instanceof ParameterizedType); Type[] args = ((ParameterizedType) type).getActualTypeArguments(); Preconditions.checkArgument(args.length ==1);