1 package org
.argeo
.slc
.ant
.structure
;
4 import java
.util
.Vector
;
6 import org
.apache
.tools
.ant
.BuildException
;
7 import org
.apache
.tools
.ant
.Target
;
9 import org
.argeo
.slc
.ant
.SlcProjectHelper
;
10 import org
.argeo
.slc
.ant
.spring
.AbstractSpringArg
;
11 import org
.argeo
.slc
.ant
.spring
.AbstractSpringTask
;
12 import org
.argeo
.slc
.core
.structure
.SimpleSElement
;
13 import org
.argeo
.slc
.core
.structure
.StructureAware
;
14 import org
.argeo
.slc
.core
.structure
.StructureElement
;
15 import org
.argeo
.slc
.core
.structure
.StructurePath
;
16 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
17 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
19 /** Ant task that can be registered within a structure. */
20 public abstract class SAwareTask
extends AbstractSpringTask
implements
22 private TreeSPath path
;
23 private final List
<AbstractSpringArg
> sAwareArgs
= new Vector
<AbstractSpringArg
>();
26 public void init() throws BuildException
{
27 StructureRegistry registry
= getRegistry();
28 Target target
= getOwningTarget();
30 TreeSPath targetPath
= createTargetPath(target
);
31 SimpleSElement targetElement
= (SimpleSElement
) registry
32 .getElement(createTargetPath(target
));
34 if (targetElement
== null) {
35 targetElement
= new SimpleSElement(target
.getDescription(),
37 registry
.register(targetPath
, targetElement
);
42 * Includes this arg in the checks for propagation of sstructure related
45 protected void addSAwareArg(AbstractSpringArg arg
) {
51 * Called by Ant at runtime. Decides whether to call the actions depending
52 * of the mode of the underlying structure registry.
54 * @see #executeActions
55 * @see StructureRegistry
57 public final void execute() throws BuildException
{
58 // register the task in the structure
59 TreeSPath targetPath
= createTargetPath(getOwningTarget());
60 TreeSPath taskPath
= targetPath
.createChild(getTaskName()
61 + targetPath
.listChildren(getRegistry()).size());
62 getRegistry().register(taskPath
, this);
65 // notify registered args
66 for (AbstractSpringArg arg
: sAwareArgs
) {
67 Object obj
= arg
.getBeanInstance();
69 if (obj
instanceof StructureAware
) {
70 StructureAware sAwareT
= (StructureAware
) obj
;
71 sAwareT
.notifyCurrentPath(getRegistry(), taskPath
);
75 // execute depending on the registry mode
76 String mode
= getRegistry().getMode();
77 if (mode
.equals(StructureRegistry
.ALL
)) {
79 } else if (mode
.equals(StructureRegistry
.ACTIVE
)) {
80 List
<StructurePath
> activePaths
= getRegistry().getActivePaths();
82 if (activePaths
.contains(targetPath
)) {
83 if (activePaths
.contains(taskPath
)) {
91 /** Actions to be executed by the implementor. */
92 protected abstract void executeActions(String mode
);
94 /** Gets the underlying structure registry. */
95 protected StructureRegistry
getRegistry() {
96 return (StructureRegistry
) getProject().getReference(
97 SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
100 /** Creates the path for a given Ant target. */
101 protected static TreeSPath
createTargetPath(Target target
) {
102 TreeSPath projectPath
= SlcProjectHelper
.getProjectPath(target
104 return projectPath
.createChild(target
.getName());
107 /** Gets the path under which this task is registered. */
108 public TreeSPath
getPath() {
112 public String
getLabel() {
113 String description
= super.getDescription();
114 if (description
== null) {
115 return "<no task def>";