import org.apache.tools.ant.BuildException;\r
import org.apache.tools.ant.Target;\r
\r
+import org.argeo.slc.ant.SlcAntException;\r
import org.argeo.slc.ant.SlcProjectHelper;\r
import org.argeo.slc.ant.spring.AbstractSpringArg;\r
import org.argeo.slc.ant.spring.AbstractSpringTask;\r
import org.argeo.slc.core.structure.SimpleSElement;\r
import org.argeo.slc.core.structure.StructureAware;\r
import org.argeo.slc.core.structure.StructureElement;\r
-import org.argeo.slc.core.structure.StructurePath;\r
import org.argeo.slc.core.structure.StructureRegistry;\r
import org.argeo.slc.core.structure.tree.TreeSPath;\r
\r
/** Ant task that can be registered within a structure. */\r
-public abstract class SAwareTask extends AbstractSpringTask implements\r
- StructureElement {\r
- private TreeSPath path;\r
+public abstract class SAwareTask extends AbstractSpringTask {\r
+ private String path;\r
+ private TreeSPath treeSPath;\r
private final List<AbstractSpringArg> sAwareArgs = new Vector<AbstractSpringArg>();\r
\r
+ private StructureElementArg structureElementArg;\r
+\r
@Override\r
public void init() throws BuildException {\r
- StructureRegistry registry = getRegistry();\r
+ StructureRegistry<TreeSPath> registry = getRegistry();\r
Target target = getOwningTarget();\r
\r
TreeSPath targetPath = createTargetPath(target);\r
}\r
\r
/**\r
- * Includes this arg in the checks for propagation of sstructure related\r
+ * Includes this arg in the checks for propagation of structure related\r
* information.\r
*/\r
protected void addSAwareArg(AbstractSpringArg arg) {\r
* @see StructureRegistry\r
*/\r
public final void execute() throws BuildException {\r
- // register the task in the structure\r
- TreeSPath targetPath = createTargetPath(getOwningTarget());\r
- TreeSPath taskPath = targetPath.createChild(getTaskName()\r
- + targetPath.listChildren(getRegistry()).size());\r
- getRegistry().register(taskPath, this);\r
- path = taskPath;\r
+ if (path == null) {\r
+ // register the task in the structure\r
+ TreeSPath targetPath = createTargetPath(getOwningTarget());\r
+ TreeSPath taskPath = targetPath.createChild(getTaskName()\r
+ + targetPath.listChildren(getRegistry()).size());\r
+\r
+ treeSPath = taskPath;\r
+ } else {\r
+ treeSPath = new TreeSPath(path);\r
+ }\r
+\r
+ if (getRegistry().getElement(treeSPath) == null) {\r
+ // No structure element registered.\r
+ if (structureElementArg != null) {\r
+ getRegistry().register(treeSPath,\r
+ structureElementArg.getStructureElement());\r
+ } else {\r
+ if (getDescription() != null) {\r
+ getRegistry().register(treeSPath,\r
+ new SimpleSElement(getDescription()));\r
+ }\r
+ }\r
+ }\r
\r
// notify registered args\r
for (AbstractSpringArg arg : sAwareArgs) {\r
Object obj = arg.getBeanInstance();\r
\r
if (obj instanceof StructureAware) {\r
- StructureAware sAwareT = (StructureAware) obj;\r
- sAwareT.notifyCurrentPath(getRegistry(), taskPath);\r
+ StructureAware<TreeSPath> sAwareT = (StructureAware<TreeSPath>) obj;\r
+ sAwareT.notifyCurrentPath(getRegistry(), treeSPath);\r
}\r
}\r
\r
if (mode.equals(StructureRegistry.ALL)) {\r
executeActions(mode);\r
} else if (mode.equals(StructureRegistry.ACTIVE)) {\r
- List<StructurePath> activePaths = getRegistry().getActivePaths();\r
+ List<TreeSPath> activePaths = getRegistry().getActivePaths();\r
\r
- if (activePaths.contains(targetPath)) {\r
- if (activePaths.contains(taskPath)) {\r
+ if (activePaths.contains(treeSPath)) {\r
+ if (activePaths.contains(treeSPath)) {\r
executeActions(mode);\r
}\r
}\r
/** Actions to be executed by the implementor. */\r
protected abstract void executeActions(String mode);\r
\r
+ /** Create a reference to an external structure element. */\r
+ public StructureElementArg createStructureElement() {\r
+ if (structureElementArg != null)\r
+ throw new SlcAntException("Arg already set.");\r
+ structureElementArg = new StructureElementArg();\r
+ return structureElementArg;\r
+ }\r
+\r
/** Gets the underlying structure registry. */\r
- protected StructureRegistry getRegistry() {\r
- return (StructureRegistry) getProject().getReference(\r
+ protected StructureRegistry<TreeSPath> getRegistry() {\r
+ return (StructureRegistry<TreeSPath>) getProject().getReference(\r
SlcProjectHelper.REF_STRUCTURE_REGISTRY);\r
}\r
\r
- /** Creates the path for a given Ant target. */\r
+ /** Creates the treeSPath for a given Ant target. */\r
protected static TreeSPath createTargetPath(Target target) {\r
- TreeSPath projectPath = SlcProjectHelper.getProjectPath(target\r
- .getProject());\r
+ TreeSPath projectPath = (TreeSPath) target.getProject().getReference(\r
+ SlcProjectHelper.REF_PROJECT_PATH);\r
return projectPath.createChild(target.getName());\r
}\r
\r
- /** Gets the path under which this task is registered. */\r
- public TreeSPath getPath() {\r
- return path;\r
+ /** Gets the treeSPath under which this task is registered. */\r
+ public TreeSPath getTreeSPath() {\r
+ return treeSPath;\r
}\r
\r
- @Override\r
- public String getDescription() {\r
+ public String getLabel() {\r
String description = super.getDescription();\r
if (description == null) {\r
return "<no task def>";\r
}\r
}\r
\r
+ public void setPath(String path) {\r
+ this.path = path;\r
+ }\r
}\r
+\r
+class StructureElementArg extends AbstractSpringArg {\r
+ public StructureElement getStructureElement() {\r
+ return (StructureElement) getBeanInstance();\r
+ }\r
+}
\ No newline at end of file