View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/resolver/src/java/org/astrogrid/community/resolver/ant/CommunityAccountCreatorTask.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: CommunityAccountCreatorTask.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.14.1  2004/06/17 13:38:59  dave
13   *   Tidied up old CVS log entries
14   *
15   * </cvs:log>
16   *
17   *
18   */
19  package org.astrogrid.community.resolver.ant ;
20  
21  import java.net.URL ;
22  
23  import org.apache.tools.ant.Task ;
24  import org.apache.tools.ant.BuildException ;
25  
26  import org.astrogrid.store.Ivorn ;
27  
28  import org.astrogrid.community.common.policy.data.AccountData ;
29  
30  import org.astrogrid.community.client.policy.manager.PolicyManagerDelegate ;
31  import org.astrogrid.community.resolver.policy.manager.PolicyManagerResolver ;
32  
33  /***
34   * An Ant task to create a Community Account.
35   * 
36   */
37  public class CommunityAccountCreatorTask
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 CommunityAccountCreatorTask()
51          {
52          //
53          // Initialise our base class.
54          super() ;
55          }
56  
57      /***
58       * Public constructor.
59       *
60       */
61      public CommunityAccountCreatorTask(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 account identifier.
73       *
74       */
75      private String account ;
76  
77      /***
78       * Get our account identifier.
79       *
80       */
81      public String getAccount()
82          {
83          return this.account ;
84          }
85  
86      /***
87       * Set our account identifier.
88       *
89       */
90      public void setAccount(String value)
91          {
92          this.account = value ;
93          }
94  
95      /***
96       * Initialise our Task.
97       *
98       */
99      public void init()
100         throws BuildException
101         {
102         if (DEBUG_FLAG) System.out.println("----\"----");
103         if (DEBUG_FLAG) System.out.println("CommunityAccountCreatorTask.init()");
104         }
105 
106     /***
107      * Execute our Task.
108      *
109      */
110     public void execute()
111         throws BuildException
112         {
113         if (DEBUG_FLAG) System.out.println("----\"----");
114         if (DEBUG_FLAG) System.out.println("CommunityAccountCreatorTask.execute()");
115         if (DEBUG_FLAG) System.out.println("  Account : " + this.account);
116         //
117         // Load our config properties.
118         this.configure() ;
119         //
120         // Try creating our account.
121         try {
122             //
123             // Create our resolver.
124             PolicyManagerResolver resolver ;
125             //
126             // Use our registry endpoint, if we have one.
127             if (null != this.getRegistry())
128                 {
129                 resolver = new PolicyManagerResolver(
130                     new URL(
131                         this.getRegistry()
132                         )
133                     ) ;
134                 }
135             //
136             // Otherwise, just create a default resolver.
137             else {
138                 resolver = new PolicyManagerResolver() ;
139                 }
140             if (DEBUG_FLAG) System.out.println("  PASS : Got resolver");
141             //
142             // Ask our resolver for a manager delegate.
143             PolicyManagerDelegate delegate = resolver.resolve(
144                 new Ivorn(this.account)
145                 ) ;
146             if (DEBUG_FLAG) System.out.println("  PASS : Got delegate");
147             //
148             // Ask the PolicyManagerDelegate to create the Account.
149             AccountData account =  delegate.addAccount(
150                 this.account
151                 ) ;
152             if (DEBUG_FLAG) System.out.println("  PASS : Got account");
153             if (DEBUG_FLAG) System.out.println("----");
154             if (DEBUG_FLAG) System.out.println("Account - " + account.getIdent());
155             if (DEBUG_FLAG) System.out.println("  Display name : " + account.getDisplayName());
156             if (DEBUG_FLAG) System.out.println("  Description  : " + account.getDescription());
157             if (DEBUG_FLAG) System.out.println("  Home space   : " + account.getHomeSpace());
158             if (DEBUG_FLAG) System.out.println("----");
159             }
160         catch (Exception ouch)
161             {
162             throw new BuildException(ouch) ;
163             }
164         }
165     }
166