use of org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute in project controller by opendaylight.
the class RuntimeBeanEntry method extractSubtree.
/**
* Get direct descendants of this subtree, together with attributes defined
* in subtree.
*/
private static AttributesRpcsAndRuntimeBeans extractSubtree(final String packageName, final DataNodeContainer subtree, final TypeProviderWrapper typeProviderWrapper, final Module currentModule, final SchemaContext ctx) {
Multimap<QName, RpcDefinition> identitiesToRpcs = getIdentitiesToRpcs(ctx);
List<AttributeIfc> attributes = Lists.newArrayList();
List<RuntimeBeanEntry> runtimeBeanEntries = new ArrayList<>();
for (DataSchemaNode child : subtree.getChildNodes()) {
// runtime beans
if (child instanceof LeafSchemaNode) {
// just save the attribute
LeafSchemaNode leaf = (LeafSchemaNode) child;
attributes.add(new JavaAttribute(leaf, typeProviderWrapper));
} else if (child instanceof ContainerSchemaNode) {
ContainerSchemaNode container = (ContainerSchemaNode) child;
// this can be either TO or hierarchical RB
TOAttribute toAttribute = TOAttribute.create(container, typeProviderWrapper, packageName);
attributes.add(toAttribute);
} else if (child instanceof ListSchemaNode) {
if (isInnerStateBean(child)) {
ListSchemaNode listSchemaNode = (ListSchemaNode) child;
RuntimeBeanEntry hierarchicalChild = createHierarchical(packageName, listSchemaNode, typeProviderWrapper, currentModule, ctx);
runtimeBeanEntries.add(hierarchicalChild);
} else /* ordinary list attribute */
{
ListAttribute listAttribute = ListAttribute.create((ListSchemaNode) child, typeProviderWrapper, packageName);
attributes.add(listAttribute);
}
} else if (child instanceof LeafListSchemaNode) {
ListAttribute listAttribute = ListAttribute.create((LeafListSchemaNode) child, typeProviderWrapper);
attributes.add(listAttribute);
} else {
throw new IllegalStateException("Unexpected running-data node " + child);
}
}
Set<Rpc> rpcs = new HashSet<>();
SchemaNode subtreeSchemaNode = (SchemaNode) subtree;
for (UnknownSchemaNode unknownSchemaNode : subtreeSchemaNode.getUnknownSchemaNodes()) {
if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME.equals(unknownSchemaNode.getNodeType())) {
String localIdentityName = unknownSchemaNode.getNodeParameter();
QName identityQName = unknownSchemaNode.isAddedByUses() ? findQNameFromGrouping(subtree, ctx, unknownSchemaNode, localIdentityName) : QName.create(currentModule.getNamespace(), currentModule.getRevision(), localIdentityName);
// convert RpcDefinition to Rpc
for (RpcDefinition rpcDefinition : identitiesToRpcs.get(identityQName)) {
String name = TypeProviderWrapper.findJavaParameter(rpcDefinition);
AttributeIfc returnType;
if (rpcDefinition.getOutput() == null || rpcDefinition.getOutput().getChildNodes().isEmpty()) {
returnType = VoidAttribute.getInstance();
} else if (rpcDefinition.getOutput().getChildNodes().size() == 1) {
DataSchemaNode returnDSN = rpcDefinition.getOutput().getChildNodes().iterator().next();
returnType = getReturnTypeAttribute(returnDSN, typeProviderWrapper, packageName);
} else {
throw new IllegalArgumentException("More than one child node in rpc output is not supported. " + "Error occured in " + rpcDefinition);
}
List<JavaAttribute> parameters = new ArrayList<>();
for (DataSchemaNode childNode : sortAttributes(rpcDefinition.getInput().getChildNodes())) {
if (childNode.isAddedByUses() == false) {
// skip
// refined
// context-instance
checkArgument(childNode instanceof LeafSchemaNode, "Unexpected type of rpc input type. " + "Currently only leafs and empty output nodes are supported, got " + childNode);
JavaAttribute javaAttribute = new JavaAttribute((LeafSchemaNode) childNode, typeProviderWrapper);
parameters.add(javaAttribute);
}
}
Rpc newRpc = new Rpc(returnType, name, rpcDefinition.getQName().getLocalName(), parameters);
rpcs.add(newRpc);
}
}
}
return new AttributesRpcsAndRuntimeBeans(runtimeBeanEntries, attributes, rpcs);
}
use of org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute in project controller by opendaylight.
the class TemplateFactory method tOsFromRbe.
public static Map<String, GeneralClassTemplate> tOsFromRbe(final RuntimeBeanEntry rbe) {
final Map<String, GeneralClassTemplate> retVal = Maps.newHashMap();
final TOAttributesProcessor processor = new TOAttributesProcessor();
final Map<String, AttributeIfc> yangPropertiesToTypesMap = Maps.newHashMap(rbe.getYangPropertiesToTypesMap());
// Add TOs from output parameters
for (final Rpc rpc : rbe.getRpcs()) {
final AttributeIfc returnType = rpc.getReturnType();
if (returnType == VoidAttribute.getInstance()) {
continue;
}
if (returnType instanceof JavaAttribute) {
continue;
}
if (returnType instanceof ListAttribute && returnType.getOpenType() instanceof SimpleType) {
continue;
}
Preconditions.checkState(!yangPropertiesToTypesMap.containsKey(returnType.getAttributeYangName()), "Duplicate TO %s for %s", returnType.getAttributeYangName(), rbe);
yangPropertiesToTypesMap.put(returnType.getAttributeYangName(), returnType);
}
processor.processAttributes(yangPropertiesToTypesMap);
for (final org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory.TOAttributesProcessor.TOInternal to : processor.getTOs()) {
final List<Constructor> constructors = Lists.newArrayList();
constructors.add(new Constructor(to.getName(), "super();"));
// TODO header
retVal.put(to.getType(), new GeneralClassTemplate(null, rbe.getPackageName(), to.getName(), Collections.<String>emptyList(), Collections.<String>emptyList(), to.getFields(), to.getMethods(), false, false, constructors));
}
return retVal;
}
use of org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute in project controller by opendaylight.
the class ObjectXmlWriter method caseListAttribute.
@Override
protected AttributeWritingStrategy caseListAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
AttributeIfc innerAttribute = ((ListAttribute) getLastAttribute()).getInnerAttribute();
AttributeWritingStrategy innerStrategy = prepareWritingStrategy(key, innerAttribute, document);
return new ArrayAttributeWritingStrategy(innerStrategy);
}
use of org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute in project controller by opendaylight.
the class ObjectResolver method caseListAttribute.
@Override
protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseListAttribute(final ArrayType<?> openType) {
Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
AttributeIfc innerAttribute = ((ListAttribute) getLastAttribute()).getInnerAttribute();
return new ArrayAttributeResolvingStrategy(prepareStrategy(innerAttribute), openType);
}
use of org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute in project controller by opendaylight.
the class ObjectXmlReader method caseListAttribute.
@Override
protected AttributeReadingStrategy caseListAttribute(final ArrayType<?> openType) {
AttributeIfc lastAttribute = getLastAttribute();
Preconditions.checkState(lastAttribute instanceof ListAttribute);
AttributeReadingStrategy innerStrategy = prepareReadingStrategy(key, ((ListAttribute) lastAttribute).getInnerAttribute());
return new ArrayAttributeReadingStrategy(lastAttribute.getNullableDefault(), innerStrategy);
}
Aggregations