import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.annotateDeprecatedIfNecessary;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.checkModuleAndModuleName;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.createDescription;
-import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.resolveListKeyTOBuilder;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.addImplementedInterfaceFromUses;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.addRawInterfaceDefinition;
import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.moduleTypeBuilder;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.encodeAngleBrackets;
+import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil.packageNameForGeneratedType;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.ACTION;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.INPUT;
import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.INSTANCE_IDENTIFIER;
import java.util.Map;
import java.util.Set;
import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
-import org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil;
import org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes;
+import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedTransferObject;
import org.opendaylight.mdsal.binding.javav2.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTOBuilder;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.MethodSignatureBuilder;
import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingNamespaceType;
*
*/
@Beta
-public final class RpcActionGenHelper {
+final class RpcActionGenHelper {
private static final QName CONTEXT_REFERENCE =
QName.create("urn:opendaylight:yang:extension:yang-ext", "2013-07-09", "context-reference").intern();
if (potential instanceof ActionNodeContainer) {
final Set<ActionDefinition> actions = ((ActionNodeContainer) potential).getActions();
for (ActionDefinition action: actions) {
- genCtx.get(module).addChildNodeType(potential, resolveOperation(potential, action, module,
- schemaContext, verboseClassComments, genTypeBuilders, genCtx, typeProvider, true));
+ genCtx.get(module).addTopLevelNodeType(resolveOperation(potential, action, module,
+ schemaContext, verboseClassComments, genTypeBuilders, genCtx, typeProvider, true,
+ BindingNamespaceType.Data));
}
}
}
//routedRPC?
if (isAction) {
- genCtx.get(module).addChildNodeType(parent, resolveOperation(parent, rpc, module, schemaContext,
- verboseClassComments, genTypeBuilders, genCtx, typeProvider, true));
+ genCtx.get(module).addTopLevelNodeType(resolveOperation(parent, rpc, module, schemaContext,
+ verboseClassComments, genTypeBuilders, genCtx, typeProvider, true,
+ BindingNamespaceType.Data));
} else {
//global RPC only
genCtx.get(module).addTopLevelNodeType(resolveOperation(parent, rpc, module, schemaContext,
- verboseClassComments, genTypeBuilders, genCtx, typeProvider, false));
+ verboseClassComments, genTypeBuilders, genCtx, typeProvider, false,
+ BindingNamespaceType.Data));
}
}
return genCtx;
}
+ //TODO: This method should be reusable for convertion of action that is in grouping.
/**
* Converts RPC, Action or routed RPC into generated type
* @return generated type
private static GeneratedTypeBuilder resolveOperation(final DataSchemaNode parent, final OperationDefinition operation,
final Module module, final SchemaContext schemaContext, final boolean verboseClassComments,
Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders, final Map<Module, ModuleContext> genCtx,
- TypeProvider typeProvider, final boolean isAction) {
+ TypeProvider typeProvider, final boolean isAction, final BindingNamespaceType namespaceType) {
//operation name
final String operationName = operation.getQName().getLocalName();
final String basePackageName = interfaceBuilder.getPackageName();
interfaceBuilder.setDescription(createDescription(operation, interfaceBuilder.getFullyQualifiedName(),
- schemaContext, verboseClassComments));
+ schemaContext, verboseClassComments, namespaceType));
final String operationComment = encodeAngleBrackets(operation.getDescription());
final MethodSignatureBuilder operationMethod = interfaceBuilder.addMethod("invoke");
//input
final ContainerSchemaNode input = operation.getInput();
final GeneratedTypeBuilder inType = resolveOperationNode(interfaceBuilder, module, operation.getInput(),
- basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders, genCtx, true);
+ basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders,
+ genCtx, true, namespaceType);
annotateDeprecatedIfNecessary(operation.getStatus(), inType);
inType.setParentTypeForBuilder(interfaceBuilder);
genCtx.get(module).addChildNodeType(input, inType);
//output
final ContainerSchemaNode output = operation.getOutput();
final GeneratedTypeBuilder outType = resolveOperationNode(interfaceBuilder, module, operation.getOutput(),
- basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders, genCtx, false);
+ basePackageName, schemaContext, operationName, verboseClassComments, typeProvider, genTypeBuilders,
+ genCtx, false, namespaceType);
annotateDeprecatedIfNecessary(operation.getStatus(), outType);
outType.setParentTypeForBuilder(interfaceBuilder);
genCtx.get(module).addChildNodeType(output, outType);
if (isAction) {
//action, routed RPC
- String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, parent.getPath(),
- BindingNamespaceType.Data);
- GeneratedTypeBuilder parentType = addRawInterfaceDefinition(packageName, parent, schemaContext,
- parent.getQName().getLocalName(), verboseClassComments, genTypeBuilders);
- parentType.addImplementsType(TREE_NODE);
- parentType.addImplementsType(augmentable(parentType));
+ checkState(parent != null, "Parent node of " + operation.getQName().getLocalName() + " can't be NULL");
+ GeneratedTypeBuilder parentType = genCtx.get(module).getChildNode(parent.getPath());
+ checkState(parentType != null, "Parent generated type for " + parent
+ + " data schema node must have been generated already");
annotateDeprecatedIfNecessary(parent.getStatus(), parentType);
- operationMethod.addParameter(parameterizedTypeFor(INSTANCE_IDENTIFIER, parentType), "ii");
-
if (parent instanceof ListSchemaNode) {
//ListAction
- final GeneratedTOBuilder keyType = resolveListKeyTOBuilder(basePackageName, (ListSchemaNode) parent);
+ GeneratedTransferObject keyType = null;
+ for (MethodSignatureBuilder method : parentType.getMethodDefinitions()) {
+ if (method.getName().equals("getKey")) {
+ keyType = (GeneratedTransferObject) method.toInstance(parentType).getReturnType();
+ }
+ }
+
operationMethod.addParameter(
parameterizedTypeFor(KEYED_INSTANCE_IDENTIFIER, parentType, keyType), "kii");
- operationMethod.setReturnType(keyType);
interfaceBuilder.addImplementsType(parameterizedTypeFor(LIST_ACTION, parentType, inType, outType));
} else {
//Action
GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, parentType, parentType,
((ContainerSchemaNode) parent).getChildNodes(), genCtx, schemaContext, verboseClassComments,
- genTypeBuilders, typeProvider);
+ genTypeBuilders, typeProvider, namespaceType);
operationMethod.addParameter(parameterizedTypeFor(INSTANCE_IDENTIFIER, parentType), "ii");
interfaceBuilder.addImplementsType(parameterizedTypeFor(ACTION, parentType, inType, outType));
}
} else {
//RPC
interfaceBuilder.addImplementsType(parameterizedTypeFor(RPC, inType, outType));
- interfaceBuilder.addImplementsType(TREE_NODE);
}
+ interfaceBuilder.addImplementsType(TREE_NODE);
operationMethod.addParameter(parameterizedTypeFor(RPC_CALLBACK, outType), "callback");
operationMethod.setComment(operationComment);
private static GeneratedTypeBuilder resolveOperationNode(GeneratedTypeBuilder parent, final Module module, final
ContainerSchemaNode operationNode, final String basePackageName, final SchemaContext schemaContext, final String
operationName, final boolean verboseClassComments, TypeProvider typeProvider, Map<String, Map<String,
- GeneratedTypeBuilder>> genTypeBuilders, final Map<Module, ModuleContext> genCtx, final boolean isInput) {
-
+ GeneratedTypeBuilder>> genTypeBuilders, final Map<Module, ModuleContext> genCtx, final boolean isInput,
+ final BindingNamespaceType namespaceType) {
final GeneratedTypeBuilder nodeType = addRawInterfaceDefinition(basePackageName, operationNode, schemaContext,
- operationName, verboseClassComments, genTypeBuilders);
+ operationName, "", verboseClassComments, genTypeBuilders, namespaceType);
addImplementedInterfaceFromUses(operationNode, nodeType, genCtx);
nodeType.addImplementsType(parameterizedTypeFor(BindingTypes.TREE_CHILD_NODE, parent, parameterizedTypeFor
(BindingTypes.ITEM, parent)));
nodeType.addImplementsType(parameterizedTypeFor(INSTANTIABLE, nodeType));
nodeType.addImplementsType(augmentable(nodeType));
GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, nodeType, nodeType, operationNode.getChildNodes(), genCtx,
- schemaContext, verboseClassComments, genTypeBuilders, typeProvider);
+ schemaContext, verboseClassComments, genTypeBuilders, typeProvider, namespaceType);
final MethodSignatureBuilder nodeMethod = nodeType.addMethod("implementedInterface");
nodeMethod.setReturnType(parameterizedTypeFor(CLASS, nodeType));