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 StructureElement
{
21 private TreeSPath path
;
22 //private final DefaultTreeSAware sAware = new DefaultTreeSAware();
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
);
41 protected void addSAwareArg(AbstractSpringArg arg
) {
47 * Called by Ant at runtime. Decides whether to call the actions depending
48 * of the mode of the underlying structure registry.
50 * @see #executeActions
51 * @see StructureRegistry
53 public final void execute() throws BuildException
{
54 // register the task in the structure
55 TreeSPath targetPath
= createTargetPath(getOwningTarget());
56 TreeSPath taskPath
= targetPath
.createChild(getTaskName()
57 + targetPath
.listChildren(getRegistry()).size());
58 getRegistry().register(taskPath
, this);
61 // notify registered args
62 for (AbstractSpringArg arg
: sAwareArgs
) {
63 Object obj
= arg
.getBeanInstance();
65 if (obj
instanceof StructureAware
) {
66 StructureAware sAwareT
= (StructureAware
) obj
;
67 sAwareT
.notifyCurrentPath(getRegistry(), taskPath
);
71 // execute depending on the registry mode
72 String mode
= getRegistry().getMode();
73 if (mode
.equals(StructureRegistry
.ALL
)) {
75 } else if (mode
.equals(StructureRegistry
.ACTIVE
)) {
76 List
<StructurePath
> activePaths
= getRegistry().getActivePaths();
78 if (activePaths
.contains(targetPath
)) {
79 if (activePaths
.contains(taskPath
)) {
87 /** Actions to be executed by the implementor. */
88 protected abstract void executeActions(String mode
);
90 /** Gets the underlying structure registry. */
91 protected StructureRegistry
getRegistry() {
92 return (StructureRegistry
) getProject().getReference(
93 SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
96 /** Creates the path for a given Ant target. */
97 protected static TreeSPath
createTargetPath(Target target
) {
98 TreeSPath projectPath
= SlcProjectHelper
.getProjectPath(target
100 return projectPath
.createChild(target
.getName());
103 public TreeSPath
getPath() {
108 public String
getDescription() {
109 String description
= super.getDescription();
110 if(description
==null){
111 return "<no task def>";