Search in sources :

Example 1 with Constructor

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

the class TemplateFactory method tOsFromMbe.

public static Map<String, GeneralClassTemplate> tOsFromMbe(final ModuleMXBeanEntry mbe) {
    final Map<String, GeneralClassTemplate> retVal = Maps.newHashMap();
    final TOAttributesProcessor processor = new TOAttributesProcessor();
    processor.processAttributes(mbe.getAttributes());
    for (final org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory.TOAttributesProcessor.TOInternal to : processor.getTOs()) {
        final List<Constructor> constructors = Lists.newArrayList();
        constructors.add(new Constructor(to.getName(), "super();"));
        final Header header = getHeaderFromEntry(mbe);
        retVal.put(to.getType(), new GeneralClassTemplate(header, mbe.getPackageName(), to.getName(), Collections.<String>emptyList(), Collections.<String>emptyList(), to.getFields(), to.getMethods(), false, false, constructors));
    }
    return retVal;
}
Also used : Header(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header) Constructor(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor)

Example 2 with Constructor

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

the class TemplateFactory method tOsFromRbe.

public static Map<String, GeneralClassTemplate> tOsFromRbe(final RuntimeBeanEntry rbe) {
    final Map<String, GeneralClassTemplate> retVal = Maps.newHashMap();
    final TOAttributesProcessor processor = new TOAttributesProcessor();
    final Map<String, AttributeIfc> yangPropertiesToTypesMap = Maps.newHashMap(rbe.getYangPropertiesToTypesMap());
    // Add TOs from output parameters
    for (final Rpc rpc : rbe.getRpcs()) {
        final AttributeIfc returnType = rpc.getReturnType();
        if (returnType == VoidAttribute.getInstance()) {
            continue;
        }
        if (returnType instanceof JavaAttribute) {
            continue;
        }
        if (returnType instanceof ListAttribute && returnType.getOpenType() instanceof SimpleType) {
            continue;
        }
        Preconditions.checkState(!yangPropertiesToTypesMap.containsKey(returnType.getAttributeYangName()), "Duplicate TO %s for %s", returnType.getAttributeYangName(), rbe);
        yangPropertiesToTypesMap.put(returnType.getAttributeYangName(), returnType);
    }
    processor.processAttributes(yangPropertiesToTypesMap);
    for (final org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory.TOAttributesProcessor.TOInternal to : processor.getTOs()) {
        final List<Constructor> constructors = Lists.newArrayList();
        constructors.add(new Constructor(to.getName(), "super();"));
        // TODO header
        retVal.put(to.getType(), new GeneralClassTemplate(null, rbe.getPackageName(), to.getName(), Collections.<String>emptyList(), Collections.<String>emptyList(), to.getFields(), to.getMethods(), false, false, constructors));
    }
    return retVal;
}
Also used : Rpc(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc) Constructor(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor) SimpleType(javax.management.openmbean.SimpleType) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)

Example 3 with Constructor

use of org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor 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

Constructor (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor)3 SimpleType (javax.management.openmbean.SimpleType)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 ListAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)1 Annotation (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation)1 Field (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field)1 Header (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header)1 Method (org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method)1 FullyQualifiedName (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName)1 GeneratedObjectBuilder (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder)1 JavaFileInputBuilder (org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder)1