|
From: <br...@us...> - 2016-07-14 17:19:30
|
Revision: 4174
http://sourceforge.net/p/openlcb/svn/4174
Author: bracz
Date: 2016-07-14 17:19:28 +0000 (Thu, 14 Jul 2016)
Log Message:
-----------
Adds an escape option for CDI variable keys in the ConfigRepresentation which uses the index in the JDOM parent as key when a name is not present.
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/cdi/CdiRep.java
trunk/prototypes/java/src/org/openlcb/cdi/impl/ConfigRepresentation.java
trunk/prototypes/java/src/org/openlcb/cdi/jdom/JdomCdiRep.java
Modified: trunk/prototypes/java/src/org/openlcb/cdi/CdiRep.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/cdi/CdiRep.java 2016-07-14 17:19:10 UTC (rev 4173)
+++ trunk/prototypes/java/src/org/openlcb/cdi/CdiRep.java 2016-07-14 17:19:28 UTC (rev 4174)
@@ -31,6 +31,7 @@
public String getName();
public String getDescription();
public Map getMap();
+ public int getIndexInParent();
}
public static interface Item {
@@ -38,6 +39,7 @@
public String getDescription();
public Map getMap();
public int getOffset();
+ public int getIndexInParent();
}
public static interface Group extends Item {
Modified: trunk/prototypes/java/src/org/openlcb/cdi/impl/ConfigRepresentation.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/cdi/impl/ConfigRepresentation.java 2016-07-14 17:19:10 UTC (rev 4173)
+++ trunk/prototypes/java/src/org/openlcb/cdi/impl/ConfigRepresentation.java 2016-07-14 17:19:28 UTC (rev 4174)
@@ -174,7 +174,11 @@
origin = origin + it.getOffset();
CdiEntry entry = null;
- String name = baseName + "." + it.getName();
+ String entryName = it.getName();
+ if (entryName == null) {
+ entryName = "child" + it.getIndexInParent();
+ }
+ String name = baseName + "." + entryName;
if (it instanceof CdiRep.Group) {
entry = new GroupEntry(name, (CdiRep.Group) it, segment, origin);
} else if (it instanceof CdiRep.IntegerRep) {
@@ -333,6 +337,9 @@
this.segment = segment;
this.items = new ArrayList<>();
this.key = getName();
+ if (key == null) {
+ key = "seg" + segment.getIndexInParent();
+ }
this.origin = segment.getOrigin();
this.space = segment.getSpace();
this.size = processGroup(key, this.space, segment.getItems(), this.items, this.origin);
@@ -367,6 +374,11 @@
public int getOffset() {
return segment.getOrigin();
}
+
+ @Override
+ public int getIndexInParent() {
+ return segment.getIndexInParent();
+ }
}
/**
Modified: trunk/prototypes/java/src/org/openlcb/cdi/jdom/JdomCdiRep.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/cdi/jdom/JdomCdiRep.java 2016-07-14 17:19:10 UTC (rev 4173)
+++ trunk/prototypes/java/src/org/openlcb/cdi/jdom/JdomCdiRep.java 2016-07-14 17:19:28 UTC (rev 4174)
@@ -104,7 +104,11 @@
}
return list;
}
-
+
+ public int getIndexInParent() {
+ return e.getParent().indexOf(e);
+ }
+
Nested(Element e) { this.e = e; }
Element e;
}
@@ -214,6 +218,12 @@
else return a.getIntValue();
} catch (org.jdom2.DataConversionException e) { return 0; }
}
+
+ @Override
+ public int getIndexInParent() {
+ return e.getParent().indexOf(e);
+ }
+
}
public static class Group extends Nested implements CdiRep.Group {
@@ -236,7 +246,7 @@
else return a.getIntValue();
} catch (org.jdom2.DataConversionException e1) { return 0; }
}
-
+
@Override
public String getRepName() {
Element d = e.getChild("repname");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|