View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/resolver/src/java/org/astrogrid/community/resolver/ant/CommunityAccountSpaceResolverTask.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/06/18 13:45:20 $</cvs:date>
5    * <cvs:version>$Revision: 1.4 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: CommunityAccountSpaceResolverTask.java,v $
9    *   Revision 1.4  2004/06/18 13:45:20  dave
10   *   Merged development branch, dave-dev-200406081614, into HEAD
11   *
12   *   Revision 1.3.18.2  2004/06/17 15:17:30  dave
13   *   Removed unused imports (PMD report).
14   *
15   *   Revision 1.3.18.1  2004/06/17 13:38:59  dave
16   *   Tidied up old CVS log entries
17   *
18   * </cvs:log>
19   *
20   *
21   */
22  package org.astrogrid.community.resolver.ant ;
23  
24  import java.net.URL ;
25  
26  import org.apache.tools.ant.Task ;
27  import org.apache.tools.ant.BuildException ;
28  
29  import org.astrogrid.store.Ivorn ;
30  
31  import org.astrogrid.community.resolver.CommunityAccountSpaceResolver ;
32  
33  /***
34   * An Ant task to resolve a Community Account home space.
35   * 
36   */
37  public class CommunityAccountSpaceResolverTask
38      extends CommunityResolverTask
39      {
40      /***
41       * Our debug flag.
42       *
43       */
44      private static final boolean DEBUG_FLAG = true ;
45  
46      /***
47       * Public constructor.
48       *
49       */
50      public CommunityAccountSpaceResolverTask()
51          {
52          //
53          // Initialise our base class.
54          super() ;
55          }
56  
57      /***
58       * Public constructor.
59       *
60       */
61      public CommunityAccountSpaceResolverTask(Task parent)
62          {
63          //
64          // Initialise our base class.
65          super() ;
66          //
67          // Set our project.
68          setProject(parent.getProject()) ;
69          }
70  
71      /***
72       * Our property name.
73       *
74       */
75      private String property ;
76  
77      /***
78       * Get our property name.
79       *
80       */
81      public String getProperty()
82          {
83          return this.property ;
84          }
85  
86      /***
87       * Set our property name.
88       *
89       */
90      public void setProperty(String value)
91          {
92          this.property = value ;
93          }
94  
95      /***
96       * Our account identifier.
97       *
98       */
99      private String account ;
100 
101     /***
102      * Get our account identifier.
103      *
104      */
105     public String getAccount()
106         {
107         return this.account ;
108         }
109 
110     /***
111      * Set our account identifier.
112      *
113      */
114     public void setAccount(String value)
115         {
116         this.account = value ;
117         }
118 
119     /***
120      * Initialise our Task.
121      *
122      */
123     public void init()
124         throws BuildException
125         {
126         if (DEBUG_FLAG) System.out.println("----\"----");
127         if (DEBUG_FLAG) System.out.println("CommunityAccountSpaceResolverTask.init()");
128         }
129 
130     /***
131      * Execute our Task.
132      *
133      */
134     public void execute()
135         throws BuildException
136         {
137         if (DEBUG_FLAG) System.out.println("----\"----");
138         if (DEBUG_FLAG) System.out.println("CommunityAccountSpaceResolverTask.execute()");
139         if (DEBUG_FLAG) System.out.println("  Account : " + this.account);
140         //
141         // Load our config properties.
142         this.configure() ;
143         //
144         // Try login to the account.
145         try {
146             //
147             // Create our resolver.
148             CommunityAccountSpaceResolver resolver ;
149             //
150             // Use our registry endpoint, if we have one.
151             if (null != this.getRegistry())
152                 {
153                 resolver = new CommunityAccountSpaceResolver(
154                     new URL(
155                         this.getRegistry()
156                         )
157                     ) ;
158                 }
159             //
160             // Otherwise, just create a default resolver.
161             else {
162                 resolver = new CommunityAccountSpaceResolver() ;
163                 }
164             //
165             // Ask our resolver to get the Account home.
166             Ivorn ivorn = resolver.resolve(
167                 new Ivorn(
168                     this.account
169                     )
170                 ) ;
171             if (DEBUG_FLAG) System.out.println("----");
172             if (DEBUG_FLAG) System.out.println("Home : " + ivorn);
173             if (DEBUG_FLAG) System.out.println("----");
174             //
175             // If we have a project
176             if (null != this.getProject())
177                 {
178                 //
179                 // If we have a property name.
180                 if (null != this.property)
181                     {
182                     //
183                     // Set our project property.
184                     this.getProject().setProperty(
185                         this.property,
186                         ivorn.toString()
187                         ) ;
188                     }
189                 }
190             }
191         catch (Exception ouch)
192             {
193             throw new BuildException(ouch) ;
194             }
195         }
196     }
197