*/\r
public class TreeSPath implements StructurePath, Comparable<StructurePath> {\r
/** Default character to use a separator: /. */\r
- public static Character DEFAULT_SEPARATOR = '/';\r
+ private static Character DEFAULT_SEPARATOR = '/';\r
\r
- private TreeSPath parent;\r
- private String name;\r
private Character separator = DEFAULT_SEPARATOR;\r
\r
private String asUniqueString;\r
/** For ORM */\r
private Long tid;\r
\r
+ public TreeSPath() {\r
+\r
+ }\r
+\r
+ public TreeSPath(String asUniqueString) {\r
+ this.asUniqueString = checkAndFormatPath(asUniqueString);\r
+ }\r
+\r
public String getAsUniqueString() {\r
- if (asUniqueString == null) {\r
- String parentStr = parent != null ? parent.getAsUniqueString() : "";\r
- asUniqueString = parentStr + separator + name;\r
- }\r
return asUniqueString;\r
}\r
\r
- /** Sets all the required data from a string. */\r
- public void setAsUniqueString(String str) {\r
- TreeSPath twin = parseToCreatePath(str, getSeparator());\r
- name = twin.name;\r
- parent = twin.parent;\r
- asUniqueString = getAsUniqueString();\r
+ /**\r
+ * Sets all the required data from a string. <b>ATTENTION</b>: the path is\r
+ * not checked for performance reason. This method should be used only by\r
+ * ORM/OXM frameworks. Use constructor to create immutable tree structure\r
+ * paths.\r
+ */\r
+ void setAsUniqueString(String str) {\r
+ this.asUniqueString = str;\r
}\r
\r
/** The separator actually used by this path. */\r
\r
/** Gets the parent path. */\r
public TreeSPath getParent() {\r
- return parent;\r
+ int lastSep = getAsUniqueString().lastIndexOf(separator);\r
+ if (lastSep < 1) {\r
+ return null;\r
+ }\r
+ String parentUniqueString = getAsUniqueString().substring(0, lastSep);\r
+ return new TreeSPath(parentUniqueString);\r
}\r
\r
/** Gets the name part of the path. */\r
public String getName() {\r
- return name;\r
+ int lastSep = getAsUniqueString().lastIndexOf(separator);\r
+ return getAsUniqueString().substring(lastSep);\r
}\r
\r
/** Create a path without parent. */\r
public static TreeSPath createRootPath(String name) {\r
- TreeSPath path = new TreeSPath();\r
- path.parent = null;\r
- path.name = name;\r
- return path;\r
+ if (name.indexOf(DEFAULT_SEPARATOR) >= 0) {\r
+ throw new SlcException("Name cannot contain " + DEFAULT_SEPARATOR);\r
+ }\r
+ return new TreeSPath('/' + name);\r
}\r
\r
/** Create a child . */\r
throw new SlcException("Tree path name '" + name\r
+ "' contains separator character " + separator);\r
}\r
- TreeSPath path = new TreeSPath();\r
- path.parent = this;\r
- path.name = name;\r
- return path;\r
+ return new TreeSPath(getAsUniqueString() + '/' + name);\r
}\r
\r
- /** Parses a string to a path. */\r
+ /**\r
+ * Parses a string to a path.\r
+ * \r
+ * @deprecated use constructor instead\r
+ */\r
public static TreeSPath parseToCreatePath(String path) {\r
return parseToCreatePath(path, DEFAULT_SEPARATOR);\r
}\r
\r
- /** Parses a string to a path. */\r
- public static TreeSPath parseToCreatePath(String path, Character separator) {\r
- StringTokenizer st = new StringTokenizer(path, Character\r
- .toString(separator));\r
+ protected String checkAndFormatPath(String str) {\r
+ if (str.length() < 2) {\r
+ throw new SlcException("Path " + str + " is not short");\r
+ }\r
+ if (str.charAt(0) != separator) {\r
+ throw new SlcException("Path " + str + " have to start with "\r
+ + separator);\r
+ }\r
\r
- TreeSPath currPath = null;\r
+ StringBuffer buf = new StringBuffer(str.length() + 5);\r
+ StringTokenizer st = new StringTokenizer(str, separator.toString());\r
while (st.hasMoreTokens()) {\r
- if (currPath == null) {// begin\r
- currPath = createRootPath(st.nextToken());\r
- } else {\r
- currPath = currPath.createChild(st.nextToken());\r
- }\r
+ buf.append(separator).append(st.nextToken());\r
}\r
- return currPath;\r
+ return buf.toString();\r
+ }\r
+\r
+ /**\r
+ * Parses a string to a path.\r
+ * \r
+ * @deprecated use constructor instead\r
+ */\r
+ public static TreeSPath parseToCreatePath(String path, Character separator) {\r
+ return new TreeSPath(path);\r
}\r
\r
/** Lists the children from a registry. */\r
- public List<TreeSPath> listChildren(StructureRegistry registry) {\r
+ public List<TreeSPath> listChildren(StructureRegistry<TreeSPath> registry) {\r
return listChildrenPaths(registry, this);\r
}\r
\r
/** Lists the children from a given path from a registry. */\r
- public static List<TreeSPath> listChildrenPaths(StructureRegistry registry,\r
- TreeSPath path) {\r
+ public static List<TreeSPath> listChildrenPaths(\r
+ StructureRegistry<TreeSPath> registry, TreeSPath path) {\r
List<TreeSPath> paths = new Vector<TreeSPath>();\r
- List<StructurePath> allPaths = registry.listPaths();\r
- for (StructurePath sPath : allPaths) {\r
- TreeSPath pathT = (TreeSPath) sPath;\r
- if (pathT.parent != null && pathT.parent.equals(path)) {\r
+ List<TreeSPath> allPaths = registry.listPaths();\r
+ for (TreeSPath pathT : allPaths) {\r
+ if (pathT.getParent() != null && pathT.getParent().equals(path)) {\r
paths.add(pathT);\r
}\r
}\r
void setTid(Long tid) {\r
this.tid = tid;\r
}\r
-\r
- /**\r
- * Sets the separator character to use.\r
- * \r
- * @deprecated\r
- */\r
- public void setSeparator(Character separator) {\r
- this.separator = separator;\r
- }\r
-\r
- /** Sets the parent (for ORM). */\r
- protected void setParent(TreeSPath parent) {\r
- this.parent = parent;\r
- }\r
-\r
- /** Sets the name (for ORM). */\r
- protected void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
}\r
import org.argeo.slc.core.structure.StructureElement;\r
import org.argeo.slc.core.structure.StructureRegistry;\r
import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.NumericTRId;\r
import org.argeo.slc.core.test.TestResult;\r
-import org.argeo.slc.core.test.TestResultId;\r
import org.argeo.slc.core.test.TestResultListener;\r
import org.argeo.slc.core.test.TestResultPart;\r
\r
public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,\r
SlcExecutionAware {\r
private Log log = LogFactory.getLog(TreeTestResult.class);\r
- /** For ORM */\r
- private Long tid;\r
\r
- //private NumericTRId testResultId;\r
private List<TestResultListener> listeners = new Vector<TestResultListener>();\r
\r
private TreeSPath currentPath;\r
private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();\r
private SortedMap<TreeSPath, StructureElement> elements = new TreeMap<TreeSPath, StructureElement>();\r
\r
- private StructureRegistry<TreeSPath> registry;\r
-\r
-// public TestResultId getTestResultId() {\r
-// return testResultId;\r
-// }\r
-\r
- /**\r
- * Use of a <code>NumericTRId</code> is required by Hibernate. <b>It may\r
- * change in the future.</b>\r
- */\r
-// public NumericTRId getNumericResultId() {\r
-// return testResultId;\r
-// }\r
-\r
- /** Sets the test result id as a numeric test result id. */\r
-// public void setNumericResultId(NumericTRId testResultId) {\r
-// this.testResultId = testResultId;\r
-// }\r
-\r
/** Sets the list of listeners. */\r
public void setListeners(List<TestResultListener> listeners) {\r
this.listeners = listeners;\r
if (!elements.containsKey(p)) {\r
StructureElement elem = registry.getElement(p);\r
if (elem != null) {\r
- // elements.put(p, elem.getLabel());\r
elements.put(p, elem);\r
- } else {\r
- log.warn("An element is already registered for path "\r
- + p);\r
}\r
+ } else {\r
+ if (log.isTraceEnabled())\r
+ log.trace("An element is already registered for path "\r
+ + p + " and was not updated");\r
}\r
+\r
}\r
}\r
\r
currentPath = (TreeSPath) path;\r
- this.registry = registry;\r
}\r
\r
/** Gets the current path. */\r
log.info("Test Result #" + getUuid() + " closed.");\r
}\r
\r
- Long getTid() {\r
- return tid;\r
- }\r
-\r
- void setTid(Long tid) {\r
- this.tid = tid;\r
- }\r
-\r
- /** Gets the related registry (can be null). */\r
- public StructureRegistry<TreeSPath> getRegistry() {\r
- return registry;\r
- }\r
-\r
- /** Sets the related registry. */\r
- // public void setRegistry(StructureRegistry<TreeSPath> registry) {\r
- // this.registry = registry;\r
- // }\r
public Date getCloseDate() {\r
return closeDate;\r
}\r