Search in sources :

Example 1 with MethodDeclaration

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDeclaration in project controller by opendaylight.

the class TemplateFactory method getTOAndMXInterfaceFtlFiles.

/**
 * Get map of file name as key, FtlFile instance representing runtime mx
 * bean as value that should be persisted from this instance.
 */
public static Map<String, FtlTemplate> getTOAndMXInterfaceFtlFiles(final RuntimeBeanEntry entry) {
    final Map<String, FtlTemplate> result = new HashMap<>();
    {
        // create GeneralInterfaceFtlFile for runtime MXBean. Attributes will
        // be transformed to getter methods
        final String mxBeanTypeName = entry.getJavaNameOfRuntimeMXBean();
        final List<String> extendedInterfaces = Collections.singletonList(RuntimeBean.class.getCanonicalName());
        final List<MethodDeclaration> methods = new ArrayList<>();
        // convert attributes to getters
        for (final AttributeIfc attributeIfc : entry.getAttributes()) {
            String returnType;
            returnType = getReturnType(attributeIfc);
            final String getterName = "get" + attributeIfc.getUpperCaseCammelCase();
            final MethodDeclaration getter = new MethodDeclaration(returnType, getterName, Collections.<Field>emptyList());
            methods.add(getter);
        }
        // add rpc methods
        for (final Rpc rpc : entry.getRpcs()) {
            // convert JavaAttribute parameters into fields
            final List<Field> fields = new ArrayList<>();
            for (final JavaAttribute ja : rpc.getParameters()) {
                final Field field = new Field(Collections.emptyList(), ja.getType().getFullyQualifiedName(), ja.getLowerCaseCammelCase(), ja.getNullableDefaultWrappedForCode());
                fields.add(field);
            }
            final MethodDeclaration operation = new MethodDeclaration(getReturnType(rpc.getReturnType()), rpc.getName(), fields);
            methods.add(operation);
        }
        // FIXME header
        final GeneralInterfaceTemplate runtimeMxBeanIfc = new GeneralInterfaceTemplate(null, entry.getPackageName(), mxBeanTypeName, extendedInterfaces, methods);
        result.put(runtimeMxBeanIfc.getTypeDeclaration().getName() + ".java", runtimeMxBeanIfc);
    }
    result.putAll(TemplateFactory.tOsFromRbe(entry));
    return result;
}
Also used : ModuleField(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField) Field(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field) IdentityRefModuleField(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField) Rpc(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc) HashMap(java.util.HashMap) MethodDeclaration(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDeclaration) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) ArrayList(java.util.ArrayList) List(java.util.List) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Rpc (org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc)1 AttributeIfc (org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)1 JavaAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)1 Field (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field)1 IdentityRefModuleField (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField)1 MethodDeclaration (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDeclaration)1 ModuleField (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField)1