@Override
public DataContainerCodecContext<?, ?> load(final Class<? extends DataObject> 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);
}
checkArgument(stmt instanceof NotificationDefinition, "Statement %s is not a notification", stmt);
@SuppressWarnings("unchecked")
- final Class<? extends Notification> clz = (Class<? extends Notification>)
+ final Class<? extends Notification<?>> clz = (Class<? extends Notification<?>>)
factory().getRuntimeContext().getClassForSchema((NotificationDefinition) stmt);
return getNotification(clz);
}
return getOrRethrow(actionsByClass, action);
}
- NotificationCodecContext<?> getNotification(final Class<? extends Notification> notification) {
+ NotificationCodecContext<?> getNotification(final Class<? extends Notification<?>> notification) {
return (NotificationCodecContext<?>) streamChild((Class<? extends DataObject>)notification);
}
return getOrRethrow(rpcDataByPath, containerPath);
}
- DataContainerCodecContext<?,?> createDataTreeChildContext(final Class<?> key) {
+ DataContainerCodecContext<?, ?> createDataTreeChildContext(final Class<? extends DataObject> key) {
final QName qname = BindingReflections.findQName(key);
final DataSchemaNode childSchema = childNonNull(getSchema().dataChildByName(qname), key,
"%s is not top-level item.", key);
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.
*
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<? extends DataObject> caseType) {
final Class<?> choiceClass = findCaseChoice(caseType);
checkArgument(choiceClass != null, "Class %s is not a valid case representation", caseType);