X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fcodec%2Fimpl%2FSchemaRootCodecContext.java;h=e438ed54dd090c16d5a7f52207071f556bbb1ae4;hb=8437ccb9f506a241f796d34d6e4fea85ac56959b;hp=e309f6949a4ae0dce42855e2f53f965465b7587d;hpb=82684b43090a871c633a333b20fde09c9392fb17;p=mdsal.git diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/SchemaRootCodecContext.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/SchemaRootCodecContext.java index e309f6949a..e438ed54dd 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/SchemaRootCodecContext.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/SchemaRootCodecContext.java @@ -62,10 +62,37 @@ final class SchemaRootCodecContext extends DataContainerCo @Override public DataContainerCodecContext load(final Class key) { if (Notification.class.isAssignableFrom(key)) { - return createNotificationDataContext(key); + checkArgument(key.isInterface(), "Supplied class must be interface."); + final QName qname = BindingReflections.findQName(key); + final NotificationDefinition schema = getSchema().findNotification(qname).orElseThrow( + () -> new IllegalArgumentException("Supplied " + key + " is not valid notification")); + return new NotificationCodecContext<>(key, schema, factory()); } if (RpcInput.class.isAssignableFrom(key) || RpcOutput.class.isAssignableFrom(key)) { - return createRpcDataContext(key); + final QName qname = BindingReflections.findQName(key); + final QNameModule qnameModule = qname.getModule(); + final Module module = getSchema().findModule(qnameModule).orElseThrow( + () -> new IllegalArgumentException("Failed to find module for " + qnameModule)); + final String className = BindingMapping.getClassName(qname); + + for (final RpcDefinition potential : module.getRpcs()) { + final QName potentialQName = potential.getQName(); + /* + * Check if rpc and class represents data from same module and then checks if rpc local name + * produces same class name as class name appended with Input/Output based on QName associated + * with binding class. + * + * FIXME: Rework this to have more precise logic regarding Binding Specification. + */ + if (key.getSimpleName().equals(BindingMapping.getClassName(potentialQName) + className)) { + final ContainerLike schema = getRpcDataSchema(potential, qname); + checkArgument(schema != null, "Schema for %s does not define input / output.", + potentialQName); + return DataContainerCodecPrototype.from(key, schema, factory()).get(); + } + } + + throw new IllegalArgumentException("Supplied class " + key + " is not valid RPC class."); } return createDataTreeChildContext(key); } @@ -125,7 +152,7 @@ final class SchemaRootCodecContext extends DataContainerCo checkArgument(stmt instanceof NotificationDefinition, "Statement %s is not a notification", stmt); @SuppressWarnings("unchecked") - final Class clz = (Class) + final Class> clz = (Class>) factory().getRuntimeContext().getClassForSchema((NotificationDefinition) stmt); return getNotification(clz); } @@ -172,7 +199,7 @@ final class SchemaRootCodecContext extends DataContainerCo return getOrRethrow(actionsByClass, action); } - NotificationCodecContext getNotification(final Class notification) { + NotificationCodecContext getNotification(final Class> notification) { return (NotificationCodecContext) streamChild((Class)notification); } @@ -188,7 +215,7 @@ final class SchemaRootCodecContext extends DataContainerCo return getOrRethrow(rpcDataByPath, containerPath); } - DataContainerCodecContext createDataTreeChildContext(final Class key) { + DataContainerCodecContext createDataTreeChildContext(final Class key) { final QName qname = BindingReflections.findQName(key); final DataSchemaNode childSchema = childNonNull(getSchema().dataChildByName(qname), key, "%s is not top-level item.", key); @@ -225,32 +252,6 @@ final class SchemaRootCodecContext extends DataContainerCo return ((Class) type).asSubclass(target); } - ContainerNodeCodecContext createRpcDataContext(final Class key) { - checkArgument(DataContainer.class.isAssignableFrom(key)); - final QName qname = BindingReflections.findQName(key); - final QNameModule qnameModule = qname.getModule(); - final Module module = getSchema().findModule(qnameModule) - .orElseThrow(() -> new IllegalArgumentException("Failed to find module for " + qnameModule)); - final String className = BindingMapping.getClassName(qname); - - for (final RpcDefinition potential : module.getRpcs()) { - final QName potentialQName = potential.getQName(); - /* - * Check if rpc and class represents data from same module and then checks if rpc local name produces same - * class name as class name appended with Input/Output based on QName associated with binding class. - * - * FIXME: Rework this to have more precise logic regarding Binding Specification. - */ - if (key.getSimpleName().equals(BindingMapping.getClassName(potentialQName) + className)) { - final ContainerLike schema = getRpcDataSchema(potential, qname); - checkArgument(schema != null, "Schema for %s does not define input / output.", potential.getQName()); - return (ContainerNodeCodecContext) DataContainerCodecPrototype.from(key, schema, factory()).get(); - } - } - - throw new IllegalArgumentException("Supplied class " + key + " is not valid RPC class."); - } - /** * Returns RPC input or output schema based on supplied QName. * @@ -298,15 +299,6 @@ final class SchemaRootCodecContext extends DataContainerCo return null; } - NotificationCodecContext createNotificationDataContext(final Class notificationType) { - checkArgument(Notification.class.isAssignableFrom(notificationType)); - checkArgument(notificationType.isInterface(), "Supplied class must be interface."); - final QName qname = BindingReflections.findQName(notificationType); - final NotificationDefinition schema = getSchema().findNotification(qname).orElseThrow( - () -> new IllegalArgumentException("Supplied " + notificationType + " is not valid notification")); - return new NotificationCodecContext<>(notificationType, schema, factory()); - } - ChoiceNodeCodecContext createChoiceDataContext(final Class caseType) { final Class choiceClass = findCaseChoice(caseType); checkArgument(choiceClass != null, "Class %s is not a valid case representation", caseType);