'''
«IF schemaNode instanceof DataSchemaNode»
- «writeDataSchemaNode(schemaNode as DataSchemaNode)»
+ «writeDataSchemaNode(schemaNode)»
«ENDIF»
«IF schemaNode instanceof EnumTypeDefinition.EnumPair»
- «writeEnumPair(schemaNode as EnumTypeDefinition.EnumPair)»
+ «writeEnumPair(schemaNode)»
«ENDIF»
«IF schemaNode instanceof ExtensionDefinition»
- «writeExtension(schemaNode as ExtensionDefinition)»
+ «writeExtension(schemaNode)»
«ENDIF»
«IF schemaNode instanceof FeatureDefinition»
- «writeFeature(schemaNode as FeatureDefinition)»
+ «writeFeature(schemaNode)»
«ENDIF»
«IF schemaNode instanceof GroupingDefinition»
- «writeGroupingDef(schemaNode as GroupingDefinition)»
+ «writeGroupingDef(schemaNode)»
«ENDIF»
«IF schemaNode instanceof IdentitySchemaNode»
- «writeIdentity(schemaNode as IdentitySchemaNode)»
+ «writeIdentity(schemaNode)»
«ENDIF»
«IF schemaNode instanceof NotificationDefinition»
- «writeNotification(schemaNode as NotificationDefinition)»
+ «writeNotification(schemaNode)»
«ENDIF»
«IF schemaNode instanceof RpcDefinition»
- «writeRPC(schemaNode as RpcDefinition)»
+ «writeRPC(schemaNode)»
«ENDIF»
«IF schemaNode instanceof TypeDefinition<?>»
- «writeTypeDefinition(schemaNode as TypeDefinition<?>)»
+ «writeTypeDefinition(schemaNode)»
«ENDIF»
«IF schemaNode instanceof UnknownSchemaNode»
- «writeUnknownSchemaNode(schemaNode as UnknownSchemaNode)»
+ «writeUnknownSchemaNode(schemaNode)»
«ENDIF»
'''
}
'''
«FOR node : nodes»
«IF node instanceof NotificationDefinition»
- «writeNotification(node as NotificationDefinition)»
+ «writeNotification(node)»
«ELSEIF node instanceof RpcDefinition»
«writeRPC(node as RpcDefinition)»
«ENDIF»
'''
refine «path.pathFromRoot.last» {
«IF schemaNode instanceof DataSchemaNode»
- «writeDataSchemaNode(schemaNode as DataSchemaNode)»
+ «writeDataSchemaNode(schemaNode)»
«ENDIF»
}
'''
def static CharSequence writeDataSchemaNode(DataSchemaNode child) {
'''
«IF child instanceof ContainerSchemaNode»
- «writeContSchemaNode(child as ContainerSchemaNode)»
+ «writeContSchemaNode(child)»
«ENDIF»
«IF child instanceof AnyXmlSchemaNode»
- «writeAnyXmlSchemaNode(child as AnyXmlSchemaNode)»
+ «writeAnyXmlSchemaNode(child)»
«ENDIF»
«IF child instanceof LeafSchemaNode»
- «writeLeafSchemaNode(child as LeafSchemaNode)»
+ «writeLeafSchemaNode(child)»
«ENDIF»
«IF child instanceof LeafListSchemaNode»
- «writeLeafListSchemaNode(child as LeafListSchemaNode)»
+ «writeLeafListSchemaNode(child)»
«ENDIF»
«IF child instanceof ChoiceCaseNode»
- «writeChoiceCaseNode(child as ChoiceCaseNode)»
+ «writeChoiceCaseNode(child)»
«ENDIF»
«IF child instanceof ChoiceNode»
- «writeChoiceNode(child as ChoiceNode)»
+ «writeChoiceNode(child)»
«ENDIF»
«IF child instanceof ListSchemaNode»
- «writeListSchemaNode(child as ListSchemaNode)»
+ «writeListSchemaNode(child)»
«ENDIF»
'''
}
def getRestrictions(Type type) {
var Restrictions restrictions = null
if (type instanceof ConcreteType) {
- restrictions = (type as ConcreteType).restrictions
+ restrictions = type.restrictions
} else if (type instanceof GeneratedTransferObject) {
- restrictions = (type as GeneratedTransferObject).restrictions
+ restrictions = type.restrictions
}
return restrictions
}
*/
def private Object generateConstructorFromIfc(Type impl) '''
«IF (impl instanceof GeneratedType)»
- «val implType = impl as GeneratedType»
-
- «IF !(implType.methodDefinitions.empty)»
- public «type.name»«BUILDER»(«implType.fullyQualifiedName» arg) {
- «printConstructorPropertySetter(implType)»
+ «IF !(impl.methodDefinitions.empty)»
+ public «type.name»«BUILDER»(«impl.fullyQualifiedName» arg) {
+ «printConstructorPropertySetter(impl)»
}
«ENDIF»
- «FOR implTypeImplement : implType.implements»
+ «FOR implTypeImplement : impl.implements»
«generateConstructorFromIfc(implTypeImplement)»
«ENDFOR»
«ENDIF»
«IF !enclosedGeneratedTypes.empty»
«FOR innerClass : enclosedGeneratedTypes SEPARATOR "\n"»
«IF (innerClass instanceof GeneratedTransferObject)»
- «val classTemplate = new ClassTemplate(innerClass as GeneratedTransferObject)»
+ «val classTemplate = new ClassTemplate(innerClass)»
«classTemplate.generateAsInnerClass»
«ENDIF»
«IF c.name == TypeConstants.PATTERN_CONSTANT_NAME»
«val cValue = c.value»
«IF cValue instanceof List<?>»
- «val cValues = cValue as List<?>»
private static final «List.importedName»<«Pattern.importedName»> «Constants.MEMBER_PATTERN_LIST»;
public static final «List.importedName»<String> «TypeConstants.PATTERN_CONSTANT_NAME» = «ImmutableList.importedName».of(«
- FOR v : cValues SEPARATOR ", "»«
+ FOR v : cValue SEPARATOR ", "»«
IF v instanceof String»"«
- v as String»"«
+ v»"«
ENDIF»«
ENDFOR»);
«IF !enclosedGeneratedTypes.empty»
«FOR innerClass : enclosedGeneratedTypes SEPARATOR "\n"»
«IF (innerClass instanceof GeneratedTransferObject)»
- «IF (innerClass as GeneratedTransferObject).unionType»
- «val unionTemplate = new UnionTemplate(innerClass as GeneratedTransferObject)»
+ «IF innerClass.unionType»
+ «val unionTemplate = new UnionTemplate(innerClass)»
«unionTemplate.generateAsInnerClass»
«this.importMap.putAll(unionTemplate.importMap)»
«ELSE»
- «val classTemplate = new ClassTemplate(innerClass as GeneratedTransferObject)»
+ «val classTemplate = new ClassTemplate(innerClass)»
«classTemplate.generateAsInnerClass»
«this.importMap.putAll(classTemplate.importMap)»
«ENDIF»
import java.util.Set
import java.util.TreeMap
-import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil
import org.opendaylight.yangtools.binding.generator.util.Types
import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType
import org.opendaylight.yangtools.sal.binding.model.api.Type
import static org.opendaylight.yangtools.yang.binding.BindingMapping.*
import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider
import com.google.common.base.Preconditions
-import org.opendaylight.yangtools.yang.binding.BindingMapping
class YangModuleInfoTemplate {
Preconditions.checkArgument(module != null, "Module must not be null.");
this.module = module
this.ctx = ctx
- _packageName = BindingGeneratorUtil.moduleNamespaceToPackageName(module);
+ _packageName = getRootPackageName(module.getQNameModule());
_modelBindingProviderName = '''«packageName».«MODEL_BINDING_PROVIDER_CLASS_NAME»''';
}
«sorted.put(module.revision, module)»
«ENDIF»
«ENDFOR»
- set.add(«BindingGeneratorUtil.moduleNamespaceToPackageName(sorted.lastEntry().value)».«MODULE_INFO_CLASS_NAME».getInstance());
+ set.add(«getRootPackageName(sorted.lastEntry().value.QNameModule)».«MODULE_INFO_CLASS_NAME».getInstance());
«ELSE»
- set.add(«BindingGeneratorUtil.moduleNamespaceToPackageName(ctx.findModuleByName(name, rev))».«MODULE_INFO_CLASS_NAME».getInstance());
+ set.add(«getRootPackageName((ctx.findModuleByName(name, rev).QNameModule))».«MODULE_INFO_CLASS_NAME».getInstance());
«ENDIF»
«ENDFOR»
«ENDIF»
«IF !m.submodules.empty»
«FOR submodule : m.submodules»
- set.add(«BindingMapping.getClassName(submodule.name)»Info.getInstance());
+ set.add(«getClassName(submodule.name)»Info.getInstance());
«ENDFOR»
«ENDIF»
«IF m.imports.empty && m.submodules.empty»
private def imports() '''
«IF !importMap.empty»
«FOR entry : importMap.entrySet»
- «IF entry.value != BindingGeneratorUtil.moduleNamespaceToPackageName(module)»
+ «IF entry.value != getRootPackageName(module.QNameModule)»
import «entry.value».«entry.key»;
«ENDIF»
«ENDFOR»
importMap.put(typeName, typePackageName);
}
if (type instanceof ParameterizedType) {
- val ParameterizedType paramType = (type as ParameterizedType)
- val Type[] params = paramType.getActualTypeArguments()
+ val Type[] params = type.getActualTypeArguments()
if (params != null) {
for (Type param : params) {
putTypeIntoImports(param);
final def StringBuilder addActualTypeParameters(StringBuilder builder, Type type) {
if (type instanceof ParameterizedType) {
- val ParameterizedType pType = (type as ParameterizedType)
- val Type[] pTypes = pType.getActualTypeArguments();
- builder.append("<");
+ val Type[] pTypes = type.getActualTypeArguments();
+ builder.append('<');
builder.append(getParameters(pTypes));
- builder.append(">");
+ builder.append('>');
}
return builder;
}
private def generateSubInfo(Module module) '''
«FOR submodule : module.submodules»
- private static final class «BindingMapping.getClassName(submodule.name)»Info implements «YangModuleInfo.importedName» {
+ private static final class «getClassName(submodule.name)»Info implements «YangModuleInfo.importedName» {
- private static final «YangModuleInfo.importedName» INSTANCE = new «BindingMapping.getClassName(submodule.name)»Info();
+ private static final «YangModuleInfo.importedName» INSTANCE = new «getClassName(submodule.name)»Info();
private final «String.importedName» name = "«submodule.name»";
private final «String.importedName» namespace = "«submodule.namespace.toString»";
return INSTANCE;
}
- «classBody(submodule, BindingMapping.getClassName(submodule.name + "Info"))»
+ «classBody(submodule, getClassName(submodule.name + "Info"))»
}
«ENDFOR»
'''
<artifactId>yang-data-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
// find recursively
for(child : childNodes) {
if(child instanceof ContainerSchemaNode) {
- val contChild = child as ContainerSchemaNode
- val foundChild = findNodeInChildNodes(findingNode, contChild.childNodes)
+ val foundChild = findNodeInChildNodes(findingNode, child.childNodes)
if (foundChild != null)
return foundChild;
}
else if(child instanceof ListSchemaNode) {
- val listChild = child as ListSchemaNode
- val foundChild = findNodeInChildNodes(findingNode, listChild.childNodes)
+ val foundChild = findNodeInChildNodes(findingNode, child.childNodes)
if (foundChild != null)
return foundChild;
}
return
'''
«IF child instanceof ContainerSchemaNode»
- «printContainerNode(child as ContainerSchemaNode)»
+ «printContainerNode(child)»
«ENDIF»
«IF child instanceof AnyXmlSchemaNode»
- «printAnyXmlNode(child as AnyXmlSchemaNode)»
+ «printAnyXmlNode(child)»
«ENDIF»
«IF child instanceof LeafSchemaNode»
- «printLeafNode(child as LeafSchemaNode)»
+ «printLeafNode(child)»
«ENDIF»
«IF child instanceof LeafListSchemaNode»
- «printLeafListNode(child as LeafListSchemaNode)»
+ «printLeafListNode(child)»
«ENDIF»
«IF child instanceof ListSchemaNode»
- «printListNode(child as ListSchemaNode)»
+ «printListNode(child)»
«ENDIF»
«IF child instanceof ChoiceNode»
- «printChoiceNode(child as ChoiceNode)»
+ «printChoiceNode(child)»
«ENDIF»
'''
}
def CharSequence printBaseInfo(SchemaNode node) {
if(node instanceof LeafSchemaNode) {
- val LeafSchemaNode leafNode = (node as LeafSchemaNode)
return '''
«printInfo(node, "leaf")»
- «listItem("type", typeAnchorLink(leafNode.type?.path, leafNode.type.QName.localName))»
- «listItem("units", leafNode.units)»
- «listItem("default", leafNode.^default)»
+ «listItem("type", typeAnchorLink(node.type?.path, node.type.QName.localName))»
+ «listItem("units", node.units)»
+ «listItem("default", node.^default)»
</ul>
'''
} else if(node instanceof LeafListSchemaNode) {
- val LeafListSchemaNode leafListNode = (node as LeafListSchemaNode)
return '''
«printInfo(node, "leaf-list")»
- «listItem("type", leafListNode.type?.QName.localName)»
+ «listItem("type", node.type?.QName.localName)»
</ul>
'''
} else if(node instanceof ListSchemaNode) {
- val ListSchemaNode listNode = (node as ListSchemaNode)
return '''
«printInfo(node, "list")»
- «FOR keyDef : listNode.keyDefinition»
+ «FOR keyDef : node.keyDefinition»
«listItem("key definition", keyDef.localName)»
«ENDFOR»
</ul>
'''
} else if(node instanceof ChoiceNode) {
- val ChoiceNode choiceNode = (node as ChoiceNode)
return '''
«printInfo(node, "choice")»
- «listItem("default case", choiceNode.defaultCase)»
- «FOR caseNode : choiceNode.cases»
+ «listItem("default case", node.defaultCase)»
+ «FOR caseNode : node.cases»
«caseNode.printSchemaNodeInfo»
«ENDFOR»
</ul>
«listItem("description", node.description)»
«listItem("reference", node.reference)»
«IF node instanceof DataSchemaNode»
- «listItem("when condition", (node as DataSchemaNode).constraints.whenCondition?.toString)»
- «listItem("min elements", (node as DataSchemaNode).constraints.minElements?.toString)»
- «listItem("max elements", (node as DataSchemaNode).constraints.maxElements?.toString)»
+ «listItem("when condition", node.constraints.whenCondition?.toString)»
+ «listItem("min elements", node.constraints.minElements?.toString)»
+ «listItem("max elements", node.constraints.maxElements?.toString)»
«ENDIF»
'''
}
def asRestconfPath(YangInstanceIdentifier identifier) {
val it = new StringBuilder();
append(currentModule.name)
- append(":")
+ append(':')
var previous = false;
for(arg : identifier.pathArguments) {
- if(previous) append("/")
+ if(previous) append('/')
append(arg.nodeType.localName);
previous = true;
if(arg instanceof NodeIdentifierWithPredicates) {
- val nodeIdentifier = arg as NodeIdentifierWithPredicates;
- for(qname : nodeIdentifier.getKeyValues.keySet) {
+ for(qname : arg.getKeyValues.keySet) {
append("/{");
append(qname.localName)
- append("}")
+ append('}')
}
}
}
for (name : path) {
if (parent instanceof DataNodeContainer) {
- var SchemaNode node = (parent as DataNodeContainer).getDataChildByName(name)
+ var SchemaNode node = parent.getDataChildByName(name)
if (node == null && (parent instanceof Module)) {
val notifications = (parent as Module).notifications;
for (notification : notifications) {
}
if (node instanceof ChoiceNode) {
val List<DataSchemaNode> choiceCases = new ArrayList()
- for (caseNode : (node as ChoiceNode).cases) {
+ for (caseNode : node.cases) {
choiceCases.add(caseNode)
}
collectChildNodes(choiceCases, destination)
File path
static val BuildContext CTX = new DefaultBuildContext();
+ static val PATH_DELIMETER = '/'
var SchemaContext context;
var List<DataSchemaNode> configData;
var List<DataSchemaNode> operationalData;
var Module module;
var List<LeafSchemaNode> pathListParams;
- val PATH_DELIMETER = "/"
new(File targetPath) {
if (!targetPath.exists) targetPath.mkdirs
var StringBuilder path = new StringBuilder
path.append(schemaNode.QName.localName)
if (schemaNode instanceof ListSchemaNode) {
- val listKeys = (schemaNode as ListSchemaNode).keyDefinition
- for (listKey : listKeys) {
+ for (listKey : schemaNode.keyDefinition) {
pathListParams.add((schemaNode as DataNodeContainer).getDataChildByName(listKey) as LeafSchemaNode)
path.append(PATH_DELIMETER)
path.append('{')
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
+ <scope>provided</scope>
</dependency>
</dependencies>