1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
54 super() ;
55 }
56
57 /***
58 * Public constructor.
59 *
60 */
61 public CommunityAccountCreatorTask(Task parent)
62 {
63
64
65 super() ;
66
67
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
118 this.configure() ;
119
120
121 try {
122
123
124 PolicyManagerResolver resolver ;
125
126
127 if (null != this.getRegistry())
128 {
129 resolver = new PolicyManagerResolver(
130 new URL(
131 this.getRegistry()
132 )
133 ) ;
134 }
135
136
137 else {
138 resolver = new PolicyManagerResolver() ;
139 }
140 if (DEBUG_FLAG) System.out.println(" PASS : Got resolver");
141
142
143 PolicyManagerDelegate delegate = resolver.resolve(
144 new Ivorn(this.account)
145 ) ;
146 if (DEBUG_FLAG) System.out.println(" PASS : Got delegate");
147
148
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