View Javadoc

1   /*$Id: Toolbox.java,v 1.5 2004/12/07 16:50:33 jdt Exp $
2    * Created on 19-Nov-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
9    *
10  **/
11  package org.astrogrid.scripting;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  
16  import org.astrogrid.applications.delegate.CommonExecutionConnectorClient;
17  import org.astrogrid.applications.delegate.DelegateFactory;
18  import org.astrogrid.applications.parameter.protocol.DefaultProtocolLibraryFactory;
19  import org.astrogrid.applications.parameter.protocol.ExternalValue;
20  import org.astrogrid.applications.parameter.protocol.ProtocolLibrary;
21  import org.astrogrid.community.User;
22  import org.astrogrid.config.Config;
23  import org.astrogrid.config.SimpleConfig;
24  import org.astrogrid.io.Piper;
25  import org.astrogrid.portal.workflow.intf.WorkflowInterfaceException;
26  import org.astrogrid.portal.workflow.intf.WorkflowManager;
27  import org.astrogrid.portal.workflow.intf.WorkflowManagerFactory;
28  import org.astrogrid.registry.client.RegistryDelegateFactory;
29  import org.astrogrid.registry.client.admin.RegistryAdminService;
30  import org.astrogrid.registry.client.query.RegistryService;
31  import org.astrogrid.scripting.table.StarTableBuilder;
32  import org.astrogrid.store.Ivorn;
33  import org.astrogrid.store.VoSpaceClient;
34  import org.astrogrid.store.tree.TreeClient;
35  import org.astrogrid.store.tree.TreeClientFactory;
36  import org.astrogrid.store.tree.TreeClientLoginException;
37  import org.astrogrid.store.tree.TreeClientServiceException;
38  
39  /*** Top-level container object for delegates, helper objects and libraries useful for working with astrogrid.
40   * 
41   * @author Noel Winstanley nw@jb.man.ac.uk 19-Nov-2004
42   * @script-summary root scripting object
43   * @script-doc this is the <em>main</em> scripting object
44   *
45   */
46  public class Toolbox {
47      /***
48       * Commons Logger for this class
49       */
50      private static final Log logger = LogFactory.getLog("TOOLBOX");
51  
52      /*** Construct a new Toolbox
53       * 
54       */
55      public Toolbox() {
56          super();
57      }
58  
59      private final WorkflowManagerFactory workflowManagerFactory = new WorkflowManagerFactory();
60      private final ObjectBuilder oHelper = new ObjectBuilder();
61      private final XMLHelper xHelper = new XMLHelper();
62      private final IOHelper iHelper = new IOHelper();
63      private final TableHelper tHelper = new TableHelper();
64      private final TreeClientFactory treeFactory = new TreeClientFactory();
65  
66  
67      
68      // STIL
69      /*** access an object for building star tables from strngs, URLs and ExternalValues 
70       * @script-doc-exclude
71       * @deprecated
72       * */
73      public StarTableBuilder getStarTableBuilder() {
74          return getTableHelper().getBuilder();
75      }
76      //@todo somehting to output star tables again.
77      /*** @script-doc helper object for building, manipulating and writing tables */
78      public TableHelper getTableHelper() {
79          return tHelper;
80      }
81      
82      // logging
83      
84      /*** access a standard logging object */
85      public Log getLogger() {
86          return this.logger;
87      }
88      
89      // external referencing library.
90  
91      /*** access library object that 'knows' about a variety of IO protocols, and can construct {@link ExternalValue} objects to 
92       * read / write resources via these protocols.
93       * @deprecated
94       * @script-doc-exclude
95       */
96      public ProtocolLibrary getProtocolLibrary() {
97          return iHelper.getProtocolLibrary();
98      }
99  
100 
101     // objject builders
102     /*** access helper object for building objects 
103      * @return object that assists in building {@link User} objects, etc.
104      * @script-doc helper object for building account-type objects*/
105     public ObjectBuilder getObjectBuilder() {
106         return oHelper;
107     }
108 
109     /*** access helper object for working with xml 
110      * @return object that assists with constructing and manipulatingn xml.
111      * @script-doc helper object for working with io*/
112     public XMLHelper getXmlHelper() {
113         return xHelper;
114     }
115     
116     /*** helper object for working with IO */
117     public IOHelper getIoHelper() {
118         return iHelper;
119     }
120 
121 // system information and versions.
122     
123     /*** access all the system info and versions we can. 
124      * @todo lift code from 'fingerprint' for this
125      * @script-doc returns system information for the toolbox
126      */
127     public String getSystemInfo() {
128         return "systeminfo";
129     }
130     
131     /*** access the version info for this installations's scripting engine
132      * <p>
133      * at present returns a list of bugzilla numbers this engine implements.
134      * @todo implement to return richer info
135      * @script-doc returns version information for the toolbox */
136     public String getVersion() {
137         return "Iteration 07, scripting-nww-715 scripting-nww-777 scripting-nww-807 scripting-nww-805";
138     }
139 
140     /*** @script-doc accces the system configuration object 
141      * @return the system configuration object*/
142     public Config getSystemConfig() {
143         return SimpleConfig.getSingleton();
144     }
145 
146     
147 // workflow inteface    
148     
149     /*** access the workflow manager 
150      * @script-doc helper obect for building, saving, submitting and inspecting worflows.
151      * @throws WorkflowInterfaceException*/
152     public WorkflowManager getWorkflowManager() throws WorkflowInterfaceException {
153         return workflowManagerFactory.getManager();
154     }
155 
156   // access to cea services
157     //@todo add in memory cea client runner,
158     
159     /*** create a CEA client connected to the specified service endpoint */
160     public CommonExecutionConnectorClient createCeaClient(String endpoint) {
161         return DelegateFactory.createDelegate(endpoint);
162     }
163     
164     
165     // access to registry.
166     
167     /*** create client to query default registry 
168      * @returna registry client connected to the default registry location
169      * @script-doc client to query the registry 
170      * */
171     public RegistryService createRegistryClient() {
172         return RegistryDelegateFactory.createQuery();
173     }
174     
175     /*** client to administer the registry */ 
176     public RegistryAdminService createRegistryAdminClient() {
177         return RegistryDelegateFactory.createAdmin();
178     }
179 
180     //Access to VOSpace
181     
182     /*** create a client to access vospace 
183      * @param u object representing the user for whom to create the client for
184      * @return a vospace client which has the permissions of user <tt>u</tt>
185      * @see #getObjectBuilder() for how to build a <tt>User</tt> object*/
186     public ScriptVoSpaceClient createVoSpaceClient(User u) {
187         return new ScriptVoSpaceClient(u);
188     }
189     
190     /*** create a client to work with the vospace tree-model 
191      * 
192      * @param acc the ivorn of the account to connect to
193      * @param password the password for this account
194      * @return a logged-in treeclient for this account
195      * @throws TreeClientLoginException if login failed
196      * @throws TreeClientServiceException if communication failed
197      * @see #getObjectBuilder() to access a helper object for constructing an ivorn.
198      * @see ObjectBuilder#createLocalUserIvorn(String) for simplest way to create the ivorn.
199      */
200     public TreeClient createTreeClient(Ivorn acc, String password) throws TreeClientLoginException, TreeClientServiceException {        
201         TreeClient tc = treeFactory.createClient();
202         tc.login(acc,password);
203         return tc;
204     }
205     
206     
207 
208     public String toString() {
209           return "Astrogrid Toolbox" + "\n" + this.getVersion();
210        }
211 
212 }
213 
214 
215 /* 
216 $Log: Toolbox.java,v $
217 Revision 1.5  2004/12/07 16:50:33  jdt
218 merges from scripting-nww-805
219 
220 Revision 1.4.2.1  2004/12/07 14:47:58  nw
221 got table manipulation working.
222 
223 Revision 1.4  2004/12/06 20:03:03  clq2
224 nww_807a
225 
226 Revision 1.3.2.2  2004/12/06 18:10:54  nw
227 backwards compatability fix.
228 
229 Revision 1.3.2.1  2004/12/06 13:27:47  nw
230 fixes to improvide integration with external values and starTables.
231 
232 Revision 1.3  2004/11/30 15:39:56  clq2
233 scripting-nww-777
234 
235 Revision 1.1.2.1.2.1  2004/11/26 15:38:16  nw
236 improved some names, added some missing methods.
237 
238 Revision 1.1.2.1  2004/11/22 15:54:51  nw
239 deprecated existing scripting interface (which includes service lists).
240 produced new scripting interface, with more helpler objects.
241  
242 */