private static <T extends SchemaNode> T getOriginalSchema(final T choice) { @SuppressWarnings("unchecked") final T original = (T) SchemaNodeUtils.getRootOriginalIfPossible(choice); if (original != null) { return original; } return choice; }
public static SchemaNode getRootOriginalIfPossible(final SchemaNode data) { Optional<SchemaNode> previous = Optional.empty(); Optional<SchemaNode> next = getOriginalIfPossible(data); while (next.isPresent()) { previous = next; next = getOriginalIfPossible(next.get()); } return previous.orElse(null); }
/** * Returns RPC Input or Output Data container from RPC definition. * * @param schema SchemaContext in which lookup should be performed. * @param path Schema path of RPC input/output data container * @return Notification schema or null, if notification is not present in schema context. */ @Beta public static @Nullable ContainerSchemaNode getRpcDataSchema(final @NonNull SchemaContext schema, final @NonNull SchemaPath path) { requireNonNull(schema, "Schema context must not be null."); requireNonNull(path, "Schema path must not be null."); final Iterator<QName> it = path.getPathFromRoot().iterator(); checkArgument(it.hasNext(), "Rpc must have QName."); final QName rpcName = it.next(); checkArgument(it.hasNext(), "input or output must be part of path."); final QName inOrOut = it.next(); for (final RpcDefinition potential : schema.getOperations()) { if (rpcName.equals(potential.getQName())) { return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut); } } return null; }
/** * Returns RPC Input or Output Data container from RPC definition. * * @param schema SchemaContext in which lookup should be performed. * @param path Schema path of RPC input/output data container * @return Notification schema or null, if notification is not present in schema context. */ @Beta public static @Nullable ContainerSchemaNode getRpcDataSchema(final @NonNull SchemaContext schema, final @NonNull SchemaPath path) { requireNonNull(schema, "Schema context must not be null."); requireNonNull(path, "Schema path must not be null."); final Iterator<QName> it = path.getPathFromRoot().iterator(); checkArgument(it.hasNext(), "Rpc must have QName."); final QName rpcName = it.next(); checkArgument(it.hasNext(), "input or output must be part of path."); final QName inOrOut = it.next(); for (final RpcDefinition potential : schema.getOperations()) { if (rpcName.equals(potential.getQName())) { return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut); } } return null; }
private static <T extends SchemaNode> T getOriginalSchema(final T choice) { @SuppressWarnings("unchecked") final T original = (T) SchemaNodeUtils.getRootOriginalIfPossible(choice); if (original != null) { return original; } return choice; }
public static SchemaNode getRootOriginalIfPossible(final SchemaNode data) { Optional<SchemaNode> previous = Optional.empty(); Optional<SchemaNode> next = getOriginalIfPossible(data); while (next.isPresent()) { previous = next; next = getOriginalIfPossible(next.get()); } return previous.orElse(null); }
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 ContainerSchemaNode schema = SchemaNodeUtils.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."); }
private static final <T extends SchemaNode> T getOriginalSchema(final T choice) { @SuppressWarnings("unchecked") final T original = (T) SchemaNodeUtils.getRootOriginalIfPossible(choice); if (original != null) { return original; } return choice; }
private static <T extends SchemaNode> T getOriginalChecked(final T value) { final Optional<SchemaNode> original = SchemaNodeUtils.getOriginalIfPossible(value); checkArgument(original.isPresent(), "Original unmodified version of node is not present."); @SuppressWarnings("unchecked") final T ret = (T) original.get(); return ret; }
public static Optional<CaseSchemaNode> findInstantiatedCase(final ChoiceSchemaNode instantiatedChoice, final CaseSchemaNode originalDefinition) { CaseSchemaNode potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName()); if (originalDefinition.equals(potential)) { return Optional.of(potential); } if (potential != null) { SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential); if (originalDefinition.equals(potentialRoot)) { return Optional.of(potential); } } // We try to find case by name, then lookup its root definition // and compare it with original definition // This solves case, if choice was inside grouping // which was used in different module and thus namespaces are // different, but local names are still same. // // Still we need to check equality of definition, because local name is not // sufficient to uniquelly determine equality of cases // for (CaseSchemaNode caze : instantiatedChoice.findCaseNodes(originalDefinition.getQName().getLocalName())) { if (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(caze))) { return Optional.of(caze); } } return Optional.empty(); }
public static Optional<ChoiceCaseNode> findInstantiatedCase(final ChoiceSchemaNode instantiatedChoice, final ChoiceCaseNode originalDefinition) { ChoiceCaseNode potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName()); if(originalDefinition.equals(potential)) { return Optional.of(potential); } if (potential != null) { SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential); if (originalDefinition.equals(potentialRoot)) { return Optional.of(potential); } } // We try to find case by name, then lookup its root definition // and compare it with original definition // This solves case, if choice was inside grouping // which was used in different module and thus namespaces are // different, but local names are still same. // // Still we need to check equality of definition, because local name is not // sufficient to uniquelly determine equality of cases // potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName().getLocalName()); if(potential != null && (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(potential)))) { return Optional.of(potential); } return Optional.absent(); }
final SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential); if (originalDefinition.equals(potentialRoot)) { return Optional.of(potential); if (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(found))) { return Optional.of(found);
} else if (origDef.equals(SchemaNodeUtils.getRootOriginalIfPossible(sameName))) { childSchema = sameName; } else { if (potential != null && origDef.equals(SchemaNodeUtils.getRootOriginalIfPossible(potential))) { childSchema = potential; } else {
} else if (origDef.equals(SchemaNodeUtils.getRootOriginalIfPossible(sameName))) { childSchema = sameName; } else { if (potential != null && origDef.equals(SchemaNodeUtils.getRootOriginalIfPossible(potential))) { childSchema = potential; } else {
} else if (typeDef instanceof EnumTypeDefinition && BaseTypes.ENUMERATION_QNAME.equals(typeDef.getQName())) { LeafSchemaNode originalLeaf = (LeafSchemaNode) SchemaNodeUtils.getRootOriginalIfPossible(leaf); QName qname = originalLeaf.getQName(); final Module enumModule = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(),
private boolean resolveLeafSchemaNodeAsProperty(final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf, final boolean isReadOnly) { if (leaf != null && toBuilder != null) { Type returnType; final TypeDefinition<?> typeDef = CompatUtils.compatLeafType(leaf); if (typeDef instanceof UnionTypeDefinition) { // GeneratedType for this type definition should have be already created final ModuleContext mc = moduleContext(typeDef.getQName().getModule()); returnType = mc.getTypedefs().get(typeDef.getPath()); if (returnType == null) { // This may still be an inner type, try to find it returnType = mc.getInnerType(typeDef.getPath()); } } else if (typeDef instanceof EnumTypeDefinition && typeDef.getBaseType() == null) { // Annonymous enumeration (already generated, since it is inherited via uses). LeafSchemaNode originalLeaf = (LeafSchemaNode) SchemaNodeUtils.getRootOriginalIfPossible(leaf); QName qname = originalLeaf.getQName(); returnType = moduleContext(qname.getModule()).getInnerType(originalLeaf.getType().getPath()); } else { returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); } return resolveLeafSchemaNodeAsProperty(toBuilder, leaf, returnType, isReadOnly); } return false; }