X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fimpl%2Fconnect%2Fdom%2FBindingMapping.xtend;h=a0e1c98237ed0e963a1a3982874f46bbaca463f9;hp=9a6330ea0f1ff999ff329bde76e2d8ca71f86c03;hb=d8654e1e998855eb4a24af909c35b760e7a7c79b;hpb=13efd0b8e167e8aadd531b5ec0e72572a72bc249 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingMapping.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingMapping.xtend index 9a6330ea0f..a0e1c98237 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingMapping.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingMapping.xtend @@ -47,10 +47,18 @@ import org.opendaylight.yangtools.yang.data.api.SimpleNode import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil import org.opendaylight.controller.sal.binding.impl.util.ClassLoaderUtils import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition +import com.google.common.collect.HashMultimap +import com.google.common.collect.ArrayListMultimap +import com.google.common.collect.Multimap +import java.util.Collection +import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature class BindingMapping { + @Property val Map typeToDefinition = new HashMap(); + + @Property val Map typeToSchemaNode = new HashMap(); def QName getSchemaNode(Class cls) { @@ -91,7 +99,7 @@ class BindingMapping { } - def dispatch PathArgument toDataDomPathArgument(IdentifiableItem argument, Class parent) { + private def dispatch PathArgument toDataDomPathArgument(IdentifiableItem argument, Class parent) { val Class rawType = argument.type; val ref = Types.typeForClass(rawType); val schemaType = typeToSchemaNode.get(ref); @@ -103,13 +111,13 @@ class BindingMapping { return new NodeIdentifierWithPredicates(qname, predicates); } - def dispatch PathArgument toDataDomPathArgument(Item argument, Class parent) { + private def dispatch PathArgument toDataDomPathArgument(Item argument, Class parent) { val ref = Types.typeForClass(argument.type); val qname = typeToSchemaNode.get(ref).QName return new NodeIdentifier(qname); } - def Map toPredicates(Object identifier, ListSchemaNode node) { + private def Map toPredicates(Object identifier, ListSchemaNode node) { val keyDefinitions = node.keyDefinition; val map = new HashMap(); for (keydef : keyDefinitions) { @@ -192,7 +200,7 @@ class BindingMapping { return Collections.emptyList(); } - def getSimpleValues(DataContainer container, LeafListSchemaNode node) { + private def getSimpleValues(DataContainer container, LeafListSchemaNode node) { return Collections.emptyList(); } @@ -226,35 +234,35 @@ class BindingMapping { return it; } - private def dispatch Node getSimpleValue(Object container, QName name, ExtendedType type) { + public static def dispatch Node getSimpleValue(Object container, QName name, ExtendedType type) { getSimpleValue(container, name, type.baseType); } - private def dispatch Node getSimpleValue(Object container, QName name, StringTypeDefinition type) { + public static def dispatch Node getSimpleValue(Object container, QName name, StringTypeDefinition type) { val value = container.getValue(name, String); if(value === null) return null; return new SimpleNodeTOImpl(name, null, value); } - private def dispatch Node getSimpleValue(Object container, QName name, TypeDefinition type) { + public static def dispatch Node getSimpleValue(Object container, QName name, TypeDefinition type) { val value = container.getValue(name, Object); if(value === null) return null; return new SimpleNodeTOImpl(name, null, value); } - private def dispatch Node getSimpleValue(Object container, QName name, BooleanTypeDefinition type) { + public static def dispatch Node getSimpleValue(Object container, QName name, BooleanTypeDefinition type) { val value = container.getValue(name, Boolean); if(value === null) return null; return new SimpleNodeTOImpl(name, null, value); } - private def dispatch Node getSimpleValue(Object container, QName name, BinaryTypeDefinition type) { + public static def dispatch Node getSimpleValue(Object container, QName name, BinaryTypeDefinition type) { val Object value = container.getValue(name, Object); //Constants.BYTES_CLASS); if(value === null) return null; return new SimpleNodeTOImpl(name, null, value); } - private def T getValue(Object object, QName node, Class type) { + public static def T getValue(Object object, QName node, Class type) { val methodName = BindingGeneratorImpl.getterMethodName(node.localName, Types.typeForClass(type)); var clz = object.class; if (object instanceof DataContainer) { @@ -274,7 +282,7 @@ class BindingMapping { return value.getEncapsulatedValue(type); } - private def T getEncapsulatedValue(Object value, Class type) { + public static def T getEncapsulatedValue(Object value, Class type) { val method = value.class.getMethod("getValue"); if (method !== null && type.isAssignableFrom(method.returnType)) { return method.invoke(value) as T; @@ -303,7 +311,7 @@ class BindingMapping { return buildMethod.invoke(builder) as DataObject; } - def dispatch void fillDataObject(CompositeNode node, Object builder, ClassLoader loader, GeneratedType type, + private def dispatch void fillDataObject(CompositeNode node, Object builder, ClassLoader loader, GeneratedType type, ListSchemaNode schema) { if (schema.keyDefinition !== null && !schema.keyDefinition.empty) { @@ -311,20 +319,65 @@ class BindingMapping { val value = node.keyToBindingKey(loader, type, schema); builder.setProperty("key", value); } + node.fillBuilderFromContainer(builder,loader,type,schema); } + + - def dispatch void fillDataObject(CompositeNode node, Object builder, ClassLoader loader, GeneratedType type, + private def dispatch void fillDataObject(CompositeNode node, Object builder, ClassLoader loader, GeneratedType type, ContainerSchemaNode schema) { + node.fillBuilderFromContainer(builder,loader,type,schema); } - def Object keyToBindingKey(CompositeNode node, ClassLoader loader, GeneratedType type, ListSchemaNode schema) { + private def void fillBuilderFromContainer(CompositeNode node, Object builder, ClassLoader loader, GeneratedType type, DataNodeContainer schema) { + val Multimap> dataMap = ArrayListMultimap.create(); + for(child :node.children) { + dataMap.put(child.nodeType,node); + } + for(entry : dataMap.asMap.entrySet) { + val entrySchema = schema.getDataChildByName(entry.key); + val entryType = type.methodDefinitions.byQName(entry.key); + entry.value.addValueToBuilder(builder,loader,entryType,entrySchema); + } + } + + private def Type byQName(List signatures, QName name) { + + } + + private def dispatch addValueToBuilder(Collection> nodes, Object object, ClassLoader loader, Object object2, LeafSchemaNode container) { + + } + + + + private def dispatch addValueToBuilder(Collection> nodes, Object object, ClassLoader loader, Object object2, ContainerSchemaNode container) { + + } + + + private def dispatch addValueToBuilder(Collection> nodes, Object object, ClassLoader loader, Object object2, ListSchemaNode container) { + + } + + private def dispatch addValueToBuilder(Collection> nodes, Object object, ClassLoader loader, Object object2, LeafListSchemaNode container) { + + } + + + + + private def Object keyToBindingKey(CompositeNode node, ClassLoader loader, GeneratedType type, ListSchemaNode schema) { val keyClass = loader.loadClass(type.keyFQN); val constructor = keyClass.constructors.get(0); val keyType = type.keyTypeProperties; val args = new ArrayList(); for (key : schema.keyDefinition) { - val keyProperty = keyType.get(BindingGeneratorUtil.parseToClassName(key.localName)); + var keyProperty = keyType.get(BindingGeneratorUtil.parseToClassName(key.localName)); + if (keyProperty == null) { + keyProperty = keyType.get(BindingGeneratorUtil.parseToValidParamName(key.localName)); + } val domKeyValue = node.getFirstSimpleByName(key); val keyValue = domKeyValue.deserializeSimpleValue(loader, keyProperty.returnType, schema.getDataChildByName(key)); @@ -333,22 +386,22 @@ class BindingMapping { return ClassLoaderUtils.construct(constructor, args); } - def dispatch Object deserializeSimpleValue(SimpleNode node, ClassLoader loader, Type type, + private def dispatch Object deserializeSimpleValue(SimpleNode node, ClassLoader loader, Type type, LeafSchemaNode node2) { deserializeSimpleValueImpl(node, loader, type, node2.type); } - def dispatch Object deserializeSimpleValue(SimpleNode node, ClassLoader loader, Type type, + private def dispatch Object deserializeSimpleValue(SimpleNode node, ClassLoader loader, Type type, LeafListSchemaNode node2) { deserializeSimpleValueImpl(node, loader, type, node2.type); } - def dispatch Object deserializeSimpleValueImpl(SimpleNode node, ClassLoader loader, Type type, + private def dispatch Object deserializeSimpleValueImpl(SimpleNode node, ClassLoader loader, Type type, ExtendedType definition) { deserializeSimpleValueImpl(node, loader, type, definition.baseType); } - def dispatch Object deserializeSimpleValueImpl(SimpleNode node, ClassLoader loader, Type type, + private def dispatch Object deserializeSimpleValueImpl(SimpleNode node, ClassLoader loader, Type type, StringTypeDefinition definition) { if (type instanceof GeneratedTransferObject) { val cls = loader.getClassForType(type); @@ -359,16 +412,16 @@ class BindingMapping { return node.value; } - def Class getClassForType(ClassLoader loader, Type type) { + private def Class getClassForType(ClassLoader loader, Type type) { loader.loadClass(type.fullyQualifiedName); } - def dispatch Object deserializeSimpleValueImpl(SimpleNode node, ClassLoader loader, Type type, + private def dispatch Object deserializeSimpleValueImpl(SimpleNode node, ClassLoader loader, Type type, TypeDefinition definition) { throw new UnsupportedOperationException("TODO: auto-generated method stub") } - def Map getKeyTypeProperties(GeneratedType type) { + private def Map getKeyTypeProperties(GeneratedType type) { val method = FluentIterable.from(type.methodDefinitions).findFirst[name == "getKey"] val key = method.returnType as GeneratedTransferObject; val ret = new HashMap(); @@ -378,16 +431,16 @@ class BindingMapping { return ret; } - def void setProperty(Object object, String property, Object value) { + private def void setProperty(Object object, String property, Object value) { val cls = object.class; val valMethod = cls.getMethod("set" + property.toFirstUpper, value.class); if (valMethod != null) valMethod.invoke(object, value); } - def String getBuilderFQN(Type type) '''«type.fullyQualifiedName»Builder''' + private def String getBuilderFQN(Type type) '''«type.fullyQualifiedName»Builder''' - def String getKeyFQN(Type type) '''«type.fullyQualifiedName»Key''' + private def String getKeyFQN(Type type) '''«type.fullyQualifiedName»Key''' }