Search in sources :

Example 1 with Type

use of org.opendaylight.mdsal.binding.model.api.Type in project controller by opendaylight.

the class RuntimeRegistratorTest method testHierarchy.

@Test
public void testHierarchy() {
    final LeafSchemaNode leaf = mock(LeafSchemaNode.class);
    doReturn(QName.create(URI.create("urn:x"), "leaf-local-name")).when(leaf).getQName();
    doReturn(Collections.emptyList()).when(leaf).getUnknownSchemaNodes();
    doReturn(java.util.Optional.empty()).when(leaf).getDescription();
    final StringTypeDefinition leafType = mock(StringTypeDefinition.class);
    doReturn(java.util.Optional.empty()).when(leafType).getDefaultValue();
    doReturn(leafType).when(leaf).getType();
    final TypeProviderWrapper typeProviderWrapper = mock(TypeProviderWrapper.class);
    final Type mockedType = mock(Type.class);
    doReturn(mockedType).when(typeProviderWrapper).getType(leaf);
    doReturn("java.lang.String").when(mockedType).getFullyQualifiedName();
}
Also used : Type(org.opendaylight.mdsal.binding.model.api.Type) StringTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Test(org.junit.Test)

Example 2 with Type

use of org.opendaylight.mdsal.binding.model.api.Type in project controller by opendaylight.

the class JavaAttribute method getOpenType.

@Override
public OpenType<?> getOpenType() {
    final TypeDefinition<?> baseTypeDefinition = getBaseType(this.typeProviderWrapper, this.typeDefinition);
    final Type baseType = this.typeProviderWrapper.getType(baseTypeDefinition, baseTypeDefinition);
    if (isArray()) {
        return getArrayType();
    } else if (isEnum()) {
        return getEnumType(baseTypeDefinition);
    } else if (isUnion()) {
        return getCompositeTypeForUnion(baseTypeDefinition);
    } else if (isDerivedType(baseType, getType())) {
        return getCompositeType(baseType, baseTypeDefinition);
    } else if (isIdentityRef()) {
        return getCompositeTypeForIdentity();
    }
    return getSimpleType(getType());
}
Also used : CompositeType(javax.management.openmbean.CompositeType) Type(org.opendaylight.mdsal.binding.model.api.Type) SimpleType(javax.management.openmbean.SimpleType) OpenType(javax.management.openmbean.OpenType) ArrayType(javax.management.openmbean.ArrayType)

Example 3 with Type

use of org.opendaylight.mdsal.binding.model.api.Type in project controller by opendaylight.

the class TemplateFactory method getReturnType.

private static String getReturnType(final AttributeIfc attributeIfc) {
    String returnType;
    if (attributeIfc instanceof TypedAttribute) {
        final Type type = ((TypedAttribute) attributeIfc).getType();
        returnType = serializeType(type);
    } else if (attributeIfc == VoidAttribute.getInstance()) {
        return "void";
    } else {
        throw new UnsupportedOperationException("Attribute not supported: " + attributeIfc.getClass());
    }
    return returnType;
}
Also used : SimpleType(javax.management.openmbean.SimpleType) ParameterizedType(org.opendaylight.mdsal.binding.model.api.ParameterizedType) Type(org.opendaylight.mdsal.binding.model.api.Type) TypedAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TypedAttribute)

Example 4 with Type

use of org.opendaylight.mdsal.binding.model.api.Type in project controller by opendaylight.

the class TemplateFactory method serializeType.

// FIXME: put into Type.toString
static String serializeType(final Type type, final boolean addWildcards) {
    if (type instanceof ParameterizedType) {
        final ParameterizedType parameterizedType = (ParameterizedType) type;
        final StringBuilder sb = new StringBuilder();
        sb.append(parameterizedType.getRawType().getFullyQualifiedName());
        sb.append(addWildcards ? "<? extends " : "<");
        boolean first = true;
        for (final Type parameter : parameterizedType.getActualTypeArguments()) {
            if (first) {
                first = false;
            } else {
                sb.append(",");
            }
            sb.append(serializeType(parameter));
        }
        sb.append(">");
        return sb.toString();
    } else {
        return type.getFullyQualifiedName();
    }
}
Also used : ParameterizedType(org.opendaylight.mdsal.binding.model.api.ParameterizedType) SimpleType(javax.management.openmbean.SimpleType) ParameterizedType(org.opendaylight.mdsal.binding.model.api.ParameterizedType) Type(org.opendaylight.mdsal.binding.model.api.Type)

Example 5 with Type

use of org.opendaylight.mdsal.binding.model.api.Type in project controller by opendaylight.

the class ModuleMXBeanEntryTemplatesTest method mockJavaAttr.

public static JavaAttribute mockJavaAttr() {
    final JavaAttribute attr = mock(JavaAttribute.class);
    final Type typeA = mock(Type.class);
    doReturn("package").when(typeA).getName();
    doReturn("type").when(typeA).getPackageName();
    doReturn("package.type").when(typeA).getFullyQualifiedName();
    doReturn(typeA).when(attr).getType();
    doReturn("Type").when(attr).getUpperCaseCammelCase();
    doReturn("new Default()").when(attr).getNullableDefault();
    return attr;
}
Also used : Type(org.opendaylight.mdsal.binding.model.api.Type) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)

Aggregations

Type (org.opendaylight.mdsal.binding.model.api.Type)6 SimpleType (javax.management.openmbean.SimpleType)4 ArrayType (javax.management.openmbean.ArrayType)2 CompositeType (javax.management.openmbean.CompositeType)2 OpenType (javax.management.openmbean.OpenType)2 ParameterizedType (org.opendaylight.mdsal.binding.model.api.ParameterizedType)2 OpenDataException (javax.management.openmbean.OpenDataException)1 Test (org.junit.Test)1 JavaAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)1 TypedAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.TypedAttribute)1 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)1 TypeDefinition (org.opendaylight.yangtools.yang.model.api.TypeDefinition)1 EnumTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition)1 IdentityrefTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition)1 StringTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition)1 UnionTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition)1