Skip to content

Commit

Permalink
Merge pull request #861 from JMRI/encapsulated-profiles
Browse files Browse the repository at this point in the history
A system connection within a profile can differ for two different computers sharing the same profile. This is confirmed working correctly for serial<->serial or serial<->simulator connections, but may still need work for other connections types.
It is possible that, since this is general, specific connections type may need adjustments to which values are per-computer or are shared.
  • Loading branch information
rhwood committed Mar 7, 2016
2 parents da4fb29 + 51787ca commit 9b22a81
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 161 deletions.
3 changes: 2 additions & 1 deletion java/src/jmri/jmrix/ConnectionConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public void initialize(Profile profile) {
// Normal if the profile has not been used on this computer
log.info("No local configuration found.");
log.debug("Null pointer thrown reading local configuration.", ex);
// TODO: notify user
}
for (Element shared : sharedConnections.getChildren(CONNECTION)) {
Element perNode = null;
Element perNode = shared;
String className = shared.getAttributeValue(CLASS);
String userName = shared.getAttributeValue(USER_NAME, "");
String systemName = shared.getAttributeValue(SYSTEM_NAME, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,9 @@ protected void getInstance() {
adapter = SerialDriverAdapter.instance();
}

/**
* Unpack the node information when reading the "connection" element
*
* @param e Element containing the connection info
*/
protected void unpackElement(Element e) {
List<Element> l = e.getChildren("node");
@Override
protected void unpackElement(Element shared, Element perNode) {
List<Element> l = shared.getChildren("node");
for (int i = 0; i < l.size(); i++) {
Element n = l.get(i);
int addr = Integer.parseInt(n.getAttributeValue("name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public boolean load(Element shared, Element perNode) {
}
}
}
loadOptions(shared.getChild("options"), adapter);
loadOptions(shared.getChild("options"), perNode.getChild("options"), adapter);
// register, so can be picked up next time
register();

if (adapter.getDisabled()) {
unpackElement(shared);
unpackElement(shared, perNode);
return result;
}
adapter.configure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ protected Element makeParameter(String name, String value) {
return p;
}

/**
* Unpack the node information when reading the "connection" element
*
* @param e Element containing the connection info
*/
protected void unpackElement(Element e) {
List<Element> l = e.getChildren("node");
@Override
protected void unpackElement(Element shared, Element perNode) {
List<Element> l = shared.getChildren("node");
for (int i = 0; i < l.size(); i++) {
Element n = l.get(i);
int addr = Integer.parseInt(n.getAttributeValue("name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ protected void getInstance() {
adapter = SerialDriverAdapter.instance();
}

/**
* Unpack the node information when reading the "connection" element
*
* @param e Element containing the connection info
*/
protected void unpackElement(Element e) {
List<Element> l = e.getChildren("node");
@Override
protected void unpackElement(Element shared, Element perNode) {
List<Element> l = shared.getChildren("node");
for (int i = 0; i < l.size(); i++) {
Element n = l.get(i);
int addr = Integer.parseInt(n.getAttributeValue("name"));
Expand Down
56 changes: 17 additions & 39 deletions java/src/jmri/jmrix/configurexml/AbstractConnectionConfigXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,40 +58,28 @@ protected void storeCommon(Element e, PortAdapter adapter) {
protected void extendElement(Element e) {
}

/**
*
* @param e
* @param adapter
* @deprecated use {@link #loadCommon(org.jdom2.Element, org.jdom2.Element, jmri.jmrix.PortAdapter)
* }
*/
@Deprecated
protected void loadCommon(Element e, PortAdapter adapter) {
this.loadCommon(e, null, adapter);
}

protected void loadCommon(Element shared, Element perNode, PortAdapter adapter) {
if (shared.getAttribute("option1") != null) {
String option1Setting = shared.getAttribute("option1").getValue();
if (perNode.getAttribute("option1") != null) {
String option1Setting = perNode.getAttribute("option1").getValue();
adapter.configureOption1(option1Setting);
}
if (shared.getAttribute("option2") != null) {
String option2Setting = shared.getAttribute("option2").getValue();
if (perNode.getAttribute("option2") != null) {
String option2Setting = perNode.getAttribute("option2").getValue();
adapter.configureOption2(option2Setting);
}
if (shared.getAttribute("option3") != null) {
String option3Setting = shared.getAttribute("option3").getValue();
if (perNode.getAttribute("option3") != null) {
String option3Setting = perNode.getAttribute("option3").getValue();
adapter.configureOption3(option3Setting);
}
if (shared.getAttribute("option4") != null) {
String option4Setting = shared.getAttribute("option4").getValue();
if (perNode.getAttribute("option4") != null) {
String option4Setting = perNode.getAttribute("option4").getValue();
adapter.configureOption4(option4Setting);
}

loadOptions(shared.getChild("options"), adapter);
loadOptions(perNode.getChild("options"), perNode.getChild("options"), adapter);

try {
adapter.setManufacturer(shared.getAttribute("manufacturer").getValue());
adapter.setManufacturer(perNode.getAttribute("manufacturer").getValue());
} catch (NullPointerException ex) { //Considered normal if not present

}
Expand Down Expand Up @@ -132,34 +120,24 @@ protected void saveOptions(Element e, PortAdapter adapter) {
e.addContent(element);
}

/**
*
* @param e
* @param adapter
* @deprecated Use {@link #loadOptions(org.jdom2.Element, org.jdom2.Element, jmri.jmrix.PortAdapter)
* }
*/
@Deprecated
protected void loadOptions(Element e, PortAdapter adapter) {
this.loadOptions(e, null, adapter);
}

protected void loadOptions(Element shared, Element perNode, PortAdapter adapter) {
if (shared == null) {
if (perNode == null) {
return;
}
List<Element> optionList = shared.getChildren("option");
List<Element> optionList = perNode.getChildren("option");
for (Element so : optionList) {
adapter.setOptionState(so.getChild("name").getText(), so.getChild("value").getText());
}
}

/**
* Customizable method if you need to add anything more
* Method to unpack additional XML structures after connection creation, but
* before connection is usable.
*
* @param e Element being created, update as needed
* @param shared connection information common to all nodes
* @param perNode connection information unique to this node
*/
protected void unpackElement(Element e) {
protected void unpackElement(Element shared, Element perNode) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ public boolean load(Element shared, Element perNode) throws Exception {
}
}

loadCommon(shared, adapter);
loadCommon(shared, perNode, adapter);
// register, so can be picked up next time
register();

if (adapter.getDisabled()) {
unpackElement(shared);
unpackElement(shared, perNode);
return result;
}
try {
Expand All @@ -181,18 +181,10 @@ public boolean load(Element shared, Element perNode) throws Exception {

// once all the configure processing has happened, do any
// extra config
unpackElement(shared);
unpackElement(shared, perNode);
return result;
}

/**
* Customizable method if you need to add anything more
*
* @param e Element being created, update as needed
*/
protected void unpackElement(Element e) {
}

/**
* Update static data from XML file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ public boolean load(Element shared, Element perNode) throws Exception {
boolean result = true;
getInstance();
// configure port name
String portName = shared.getAttribute("port").getValue();
String portName = perNode.getAttribute("port").getValue();
adapter.setPort(portName);
String baudRate = shared.getAttribute("speed").getValue();
String baudRate = perNode.getAttribute("speed").getValue();
adapter.configureBaudRate(baudRate);

loadCommon(shared, adapter);
loadCommon(shared, perNode, adapter);
// register, so can be picked up next time
register();
// try to open the port
if (adapter.getDisabled()) {
unpackElement(shared);
unpackElement(shared, perNode);
return result;
}

Expand All @@ -111,18 +111,10 @@ public boolean load(Element shared, Element perNode) throws Exception {

// once all the configure processing has happened, do any
// extra config
unpackElement(shared);
unpackElement(shared, perNode);
return result;
}

/**
* Customizable method if you need to add anything more
*
* @param e Element being created, update as needed
*/
protected void unpackElement(Element e) {
}

/**
* Update static data from XML file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public boolean load(Element shared, Element perNode) {
register();

if (adapter.getDisabled()) {
unpackElement(shared);
unpackElement(shared, perNode);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ protected void extendElement(Element e) {
}

@Override
protected void unpackElement(Element e) {
List<Element> ecosPref = e.getChildren("commandStationPreferences");
protected void unpackElement(Element shared, Element perNode) {
List<Element> ecosPref = shared.getChildren("commandStationPreferences");
EcosPreferences p = ((jmri.jmrix.ecos.EcosSystemConnectionMemo) adapter.getSystemConnectionMemo()).getPreferenceManager();
for (int i = 0; i < ecosPref.size(); i++) {
if (ecosPref.get(i).getAttribute("addTurnoutToCS") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,9 @@ protected void getInstance() {
adapter = SerialDriverAdapter.instance();
}

/**
* Unpack the node information when reading the "connection" element
*
* @param e Element containing the connection info
*/
protected void unpackElement(Element e) {
List<Element> l = e.getChildren("node");
@Override
protected void unpackElement(Element shared, Element perNode) {
List<Element> l = shared.getChildren("node");
for (int i = 0; i < l.size(); i++) {
Element n = l.get(i);
int addr = Integer.parseInt(n.getAttributeValue("name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,9 @@ protected void getInstance(Object object) {
adapter = ((ConnectionConfig) object).getAdapter();
}

/**
* Unpack the node information when reading the "connection" element
*
* @param e Element containing the connection info
*/
protected void unpackElement(Element e) {
List<Element> l = e.getChildren("node");
@Override
protected void unpackElement(Element shared, Element perNode) {
List<Element> l = shared.getChildren("node");
for (int i = 0; i < l.size(); i++) {
Element n = l.get(i);
//int addr = Integer.parseInt(n.getAttributeValue("name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,9 @@ protected void getInstance(Object object) {
adapter = ((ConnectionConfig) object).getAdapter();
}

/**
* Unpack the node information when reading the "connection" element
*
* @param e Element containing the connection info
*/
protected void unpackElement(Element e) {
List<Element> l = e.getChildren("node");
@Override
protected void unpackElement(Element shared, Element perNode) {
List<Element> l = shared.getChildren("node");
for (int i = 0; i < l.size(); i++) {
Element n = l.get(i);
//int addr = Integer.parseInt(n.getAttributeValue("name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ protected void extendElement(Element e) {
}
}

/**
* Customizable method if you need to add anything more
*
* @param e Element being created, update as needed
*/
@Override
protected void unpackElement(Element e) {
if (e.getAttribute(TRANSMIT_PREFIX) != null) {
((JsonClientSystemConnectionMemo) this.adapter.getSystemConnectionMemo()).setTransmitPrefix(e.getAttribute(TRANSMIT_PREFIX).getValue());
protected void unpackElement(Element shared, Element perNode) {
if (shared.getAttribute(TRANSMIT_PREFIX) != null) {
((JsonClientSystemConnectionMemo) this.adapter.getSystemConnectionMemo()).setTransmitPrefix(shared.getAttribute(TRANSMIT_PREFIX).getValue());
}
if (e.getAttribute(NODE_IDENTITY) != null) {
((JsonClientSystemConnectionMemo) this.adapter.getSystemConnectionMemo()).setNodeIdentity(e.getAttribute(NODE_IDENTITY).getValue());
if (shared.getAttribute(NODE_IDENTITY) != null) {
((JsonClientSystemConnectionMemo) this.adapter.getSystemConnectionMemo()).setNodeIdentity(shared.getAttribute(NODE_IDENTITY).getValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,10 @@ protected void extendElement(Element e) {
}
}

/**
* Customizable method if you need to add anything more
*
* @param e Element being created, update as needed
*/
@Override
protected void unpackElement(Element e) {
if (e.getAttribute("transmitPrefix") != null) {
((JMRIClientSystemConnectionMemo) adapter.getSystemConnectionMemo()).setTransmitPrefix(e.getAttribute("transmitPrefix").getValue());
protected void unpackElement(Element shared, Element perNode) {
if (shared.getAttribute("transmitPrefix") != null) {
((JMRIClientSystemConnectionMemo) adapter.getSystemConnectionMemo()).setTransmitPrefix(shared.getAttribute("transmitPrefix").getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean load(Element shared, Element perNode) {
register();

if (adapter.getDisabled()) {
unpackElement(shared);
unpackElement(shared, perNode);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public boolean load(Element shared, Element perNode) throws Exception {
register();

if (adapter.getDisabled()) {
unpackElement(shared);
unpackElement(shared, perNode);
return result;
}
try {
Expand All @@ -137,7 +137,7 @@ public boolean load(Element shared, Element perNode) throws Exception {

// once all the configure processing has happened, do any
// extra config
unpackElement(shared);
unpackElement(shared, perNode);

}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public boolean load(Element shared, Element perNode) {
String option4Setting = shared.getAttribute("option4").getValue();
adapter.configureOption4(option4Setting);
}
loadOptions(shared.getChild("options"), adapter);
loadOptions(shared.getChild("options"), perNode.getChild("options"), adapter);
String manufacturer;
try {
manufacturer = shared.getAttribute("manufacturer").getValue();
Expand Down

0 comments on commit 9b22a81

Please sign in to comment.