001: package org.enhydra.shark.xpdl;
002:
003: import java.util.ArrayList;
004: import java.util.HashMap;
005: import java.util.List;
006: import java.util.Map;
007:
008: /**
009: * Structure representing info for the change of some XMLElement.
010: *
011: * @author Sasa Bojanic
012: */
013: public class XMLElementChangeInfo {
014: public static final int UPDATED = 1;
015: public static final int INSERTED = 3;
016: public static final int REMOVED = 5;
017: public static final int REPOSITIONED = 7;
018:
019: private static Map actionToNameMap = new HashMap();
020: static {
021: actionToNameMap.put(new Integer(XMLElementChangeInfo.UPDATED),
022: "UPDATED");
023: actionToNameMap.put(new Integer(XMLElementChangeInfo.INSERTED),
024: "INSERTED");
025: actionToNameMap.put(new Integer(XMLElementChangeInfo.REMOVED),
026: "REMOVED");
027: actionToNameMap.put(new Integer(
028: XMLElementChangeInfo.REPOSITIONED), "REPOSITIONED");
029: }
030:
031: protected XMLElement changedElement;
032: protected Object oldValue;
033: protected Object newValue;
034: protected List changedSubElements = new ArrayList();
035: protected int action;
036:
037: public int getAction() {
038: return this .action;
039: }
040:
041: public void setAction(int action) {
042: this .action = action;
043: }
044:
045: public List getChangedSubElements() {
046: return new ArrayList(this .changedSubElements);
047: }
048:
049: public void setChangedSubElements(List changedSubElements) {
050: if (changedSubElements != null) {
051: this .changedSubElements = new ArrayList(changedSubElements);
052: }
053: }
054:
055: public Object getNewValue() {
056: return this .newValue;
057: }
058:
059: public void setNewValue(Object newValue) {
060: this .newValue = newValue;
061: }
062:
063: public Object getOldValue() {
064: return this .oldValue;
065: }
066:
067: public void setOldValue(Object oldValue) {
068: this .oldValue = oldValue;
069: }
070:
071: public XMLElement getChangedElement() {
072: return this .changedElement;
073: }
074:
075: public void setChangedElement(XMLElement changedElement) {
076: this .changedElement = changedElement;
077: }
078:
079: public String getActionName() {
080: return (String) XMLElementChangeInfo.actionToNameMap
081: .get(new Integer(action));
082: }
083:
084: public String toString() {
085: String ret = "Action=" + getActionName() + ", Changed element=";
086: if (changedElement instanceof XMLCollectionElement) {
087: ret += ((XMLCollectionElement) changedElement).getId();
088: } else if (changedElement != null) {
089: ret += changedElement.toName();
090: } else {
091: ret += "null";
092: }
093: if (changedElement != null) {
094: if (changedElement.getParent() != null) {
095: ret += ", parent="
096: + changedElement.getParent().getClass()
097: .getName();
098: } else {
099: ret += ", parent=null";
100: }
101: }
102: return ret;
103: }
104: }
|