Skip to content

Commit

Permalink
Include require-instance "true" support
Browse files Browse the repository at this point in the history
Fixes #48
  • Loading branch information
PrathibaJee committed May 11, 2023
1 parent 7301f85 commit af4b1f9
Show file tree
Hide file tree
Showing 12 changed files with 2,961 additions and 568 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ module.exports = {
ele[i].attribute[j]=null;
break;
} else {
if (store.association[k].lifecycleAggregate == true) {
ele[i].attribute[j].isRequireInstance = true;
}
//ele[i].attribute[j].isleafRef = true;
if (store.association[k].upperValue > 1 || store.association[k].upperValue == "*") {
ele[i].attribute[j].nodeType == "leaf-list";
Expand Down Expand Up @@ -359,7 +362,7 @@ module.exports = {
// assigin yang types - eidtey by Waseem Sattar
var attValue=ele[i].attribute[j].name.toLowerCase();
var regex=/time|date/;
var regex1=/object|namebinding|packages|allomorphs/;
var regex1=/abcd|namebinding|packages|allomorphs/;
if(regex.test(attValue)){
ele[i].attribute[j].type = "yang:date-and-time";
}else if(regex1.test(attValue)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* The above copyright information should be included in all distribution, reproduction or derivative works of this software.
*
****************************************************************************************************/
function association(name, id, nodetype, upperValue, lowerValue,assoid,strictCom,extendedCom){
function association(name, id, nodetype, upperValue, lowerValue,assoid,strictCom,extendedCom,lifecycleAggregate){
this.name = name;
this.id = id;
this.nodeType = nodetype;
Expand All @@ -19,6 +19,7 @@ function association(name, id, nodetype, upperValue, lowerValue,assoid,strictCom
this.assoid=assoid;
this.strictCom=strictCom;
this.extendedCom=extendedCom;
this.lifecycleAggregate=lifecycleAggregate;
this.constraint=undefined;
this.memberEnd=undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function ownedAttribute(id, name, type, comment, assoc, isReadOnly, isOrdered, f
this.path = undefined;
this.support = undefined;
this.isleafRef = true;
this.isRequireInstance = false;
this.isSpecTarget = false;
this.isSpecReference = false;
this.isDefinedBySpec = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ config false;
type = this.type.writeNode(layer + 1);
} else if (typeof this.type == "string") {
if (this.type.split("+")[0] == "leafref") {
type = PRE + "\ttype leafref {\r\n require-instance false;\r\n" + PRE + "\t\t" + this.type.split("+")[1] + ";\r\n" + PRE + "\t}\r\n";
if(this.isRequireInstance){
type = PRE + "\ttype leafref {\r\n" + PRE + "\t\t" + this.type.split("+")[1] + ";\r\n" + PRE + "\t}\r\n";
}else{
type = PRE + "\ttype leafref {\r\n require-instance false;\r\n" + PRE + "\t\t" + this.type.split("+")[1] + ";\r\n" + PRE + "\t}\r\n";
}
} else {
type = PRE + "\ttype " + Util.typeifyName(this.type) + ";\r\n";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function Node(name, descrip, type, maxEle, minEle, id, config, isOrdered, featur
this.presence=undefined;
this.withSuffix=false;
this.isleafRef=undefined;
this.isRequireInstance=undefined;
this.type="";
this.store="";
}
Expand Down Expand Up @@ -70,6 +71,9 @@ Node.prototype.buildChild = function (att, type, store) {

case "leaf":
obj = new leaf(att.name, att.id, att.config, att.defaultValue, att.description, att.type, att.support, att.status, att.fileName, this.store);
if(att.isRequireInstance){
obj.isRequireInstance = att.isRequireInstance;
}
break;
case "enumeration":
obj = new leaf(this.name, att.id, att.config, att.defaultValue, att.description, att, att.support, att.status, att.fileName, this.store);
Expand Down Expand Up @@ -102,6 +106,9 @@ Node.prototype.buildChild = function (att, type, store) {
//obj = new Type(att.type, att.id,undefined,undefined,undefined, att.description, undefined, att.fileName);
obj = new Type(att.type, att.id, undefined, att.valueRange, undefined, att.description, att.units, att.fileName);
obj.name = obj.getTypeName();
if(att.isRequireInstance){
obj.isRequireInstance = att.isRequireInstance;
}
break;
case "enum":
this.name = this.name.replace(/[^\w\.-]+/g,'_');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ type.prototype.writeNode = function (layer) {
s += Util.yangifyName(this.path) + ";\r\n";
}
if(this.name == "leafref"){
s += "\t\t\t\t\trequire-instance false;\r\n";
if(this.isRequireInstance == false || this.isRequireInstance){
s += "\t\t\t\t\trequire-instance false;\r\n";
}
}
var regex = /[^0-9/./*]/;
if(this.range){
Expand Down
11 changes: 10 additions & 1 deletion models/tools/xmi-to-yang/src/main/resources/parser/creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var creators = {
assoid:obj.attributes()["xmi:id"],
strictCom:false,
extendedCom:false,
lifecycleAggregate:false,
comflag:false,
name:undefined,
id:undefined,
Expand All @@ -127,6 +128,14 @@ var creators = {
}
}

for(var i=0; i < store.lifecycleAggregate.length; i++){
if(store.lifecycleAggregate[i] == props.assoid){
props.lifecycleAggregate = true;
props.comflag = true;
break;
}
}

if (obj.ownedEnd) {
obj.ownedEnd.array ? props.len = obj.ownedEnd.array.length : props.len = 1;
for (var i = 0; i < props.len; i++) {
Expand All @@ -152,7 +161,7 @@ var creators = {

if(j == store.association.length){
forProps.type = "list";
var a = new models.Association(forProps.name, forProps.id, forProps.type, forProps.upperValue, forProps.lowerValue, props.assoid, props.strictCom, props.extendedCom);
var a = new models.Association(forProps.name, forProps.id, forProps.type, forProps.upperValue, forProps.lowerValue, props.assoid, props.strictCom, props.extendedCom,props.lifecycleAggregate);
if(obj.ownedRule){
var ownedRuleId = obj.ownedRule.attributes()['constrainedElement'];
}
Expand Down
9 changes: 9 additions & 0 deletions models/tools/xmi-to-yang/src/main/resources/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var store = {
specify:[],
strictComposite:[],
extendedComposite:[],
lifecycleAggregate:[],
rootElement:[],
generalization:[],
augment:[],
Expand Down Expand Up @@ -239,6 +240,14 @@ function parseModule(file){
parsers.parseExtendedCom(obj,store);
}
break;
case "LifecycleAggregate":
newxmi = xmi[key].array ? xmi[key].array : xmi[key];
var len = xmi[key].array ? xmi[key].array.length : 1;
for(var i = 0; i < len; i++){
obj = len === 1 ? newxmi : newxmi[i];
parsers.parseLifecycleAggregate(obj, store);
}
break;
case "OpenModelStatement":
if (!xmi[key].array) {
parsers.parseOpenModelStatement(xmi[key], config, store);
Expand Down
8 changes: 8 additions & 0 deletions models/tools/xmi-to-yang/src/main/resources/parser/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ var parsers = {
}
store.extendedComposite.push(id);
},
parseLifecycleAggregate:function(xmi,store){
var id;
if(xmi.attributes()["base_Association"]){
id = xmi.attributes()["base_Association"];
}
store.lifecycleAggregate.push(id);
},
parsePackage:function(xmi, filename, store){
var props = {
len:undefined,
Expand Down Expand Up @@ -526,6 +533,7 @@ module.exports = {
parseRootElement:parsers.parseRootElement,
parseStrictCom:parsers.parseStrictCom,
parseExtendedCom:parsers.parseExtendedCom,
parseLifecycleAggregate:parsers.parseLifecycleAggregate,
parsePackage:parsers.parsePackage,
parseUmlModel:parsers.parseUmlModel,
createLifecycle:parsers.createLifecycle,
Expand Down
Loading

0 comments on commit af4b1f9

Please sign in to comment.