1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.astrogrid.applications.description.registry;
15
16 import java.net.URL;
17
18 import javax.xml.parsers.DocumentBuilder;
19 import javax.xml.parsers.DocumentBuilderFactory;
20
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.astrogrid.applications.component.ProvidesVODescription;
27 import org.astrogrid.component.descriptor.ComponentDescriptor;
28 import org.astrogrid.registry.client.RegistryDelegateFactory;
29 import org.astrogrid.registry.client.admin.RegistryAdminService;
30 import org.exolab.castor.xml.Marshaller;
31 import org.picocontainer.Startable;
32 import org.w3c.dom.Document;
33
34 /***
35 * Component that will lodge this services' vodescription with the registry.
36 * <p />
37 * Implements the startable interface - calling {@link #start} on this component (or on the container that holds it)
38 * causes the entry to be lodged in the registry.
39 * @author Paul Harrison (pah@jb.man.ac.uk) 24-Mar-2004
40 * @version $Name: $
41 * @since iteration5
42 */
43 public class RegistryUploader implements Startable, ComponentDescriptor{
44 /***
45 * Commons Logger for this class
46 */
47 private static final Log logger = LogFactory.getLog(RegistryUploader.class);
48
49 private final ProvidesVODescription provider;
50
51 private final RegistryAdminLocator adminLocator;
52
53 /***
54 * Construct a new RegistryUploader
55 * @param provider component that provides the vodescription to upload
56 * @param adminLocator compoent that provides a registry delegate.
57 */
58 public RegistryUploader(ProvidesVODescription provider, RegistryAdminLocator adminLocator){
59 this.provider = provider;
60 this.adminLocator = adminLocator;
61 }
62
63 /*** performs the upload of the vodescription to the server.
64 * @throws Exception
65 * @see #start()
66 */
67 public void write(String endpoint) throws Exception
68 {
69 RegistryAdminService delegate;
70 if(endpoint == null)
71 {
72 delegate = adminLocator.getClient();
73 }
74 else
75 {
76 delegate = RegistryDelegateFactory.createAdmin(new URL(endpoint));
77 }
78 logger.info("registering this service with registry");
79 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
80
81 Document doc = builder.newDocument();
82 Marshaller marshaller = new Marshaller(doc);
83 marshaller.marshal(provider.getVODescription());
84 delegate.update(doc);
85
86 }
87
88 /***calls {@link #write}, logging errors.
89 * @TODO - perhaps re-enable this one day when we have a good way of getting hold of the service end point in time.
90 * @see org.picocontainer.Startable#start()
91 */
92 public void start() {
93
94
95
96
97
98
99
100 }
101
102 /***
103 * @see org.picocontainer.Startable#stop()
104 */
105 public void stop() {
106 }
107
108 /***
109 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
110 */
111 public String getName() {
112 return "Registry entry uploader";
113 }
114
115 /***
116 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
117 */
118 public String getDescription() {
119
120 try {
121 return "Registers application list with registry"
122 + "\n registry status is " + adminLocator.getClient().getCurrentStatus();
123 }
124 catch (Exception e) {
125 return "problem accessing registry \n" + e.getMessage();
126 }
127
128 }
129
130 /***
131 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
132 */
133 public Test getInstallationTest() {
134 return new InstallationTest("testAdminLocator");
135 }
136
137 /***Installation test for {@link RegistryUploader} - tests that the provided admin locator does provide a connection to a valid registry service
138 * @author Noel Winstanley nw@jb.man.ac.uk 26-Jul-2004
139 *
140 */
141 public class InstallationTest extends TestCase {
142
143 public InstallationTest(String arg0) {
144 super(arg0);
145 }
146
147 public void testAdminLocator() throws Exception{
148 RegistryAdminService delegate = adminLocator.getClient();
149 assertNotNull(delegate);
150 String status = delegate.getCurrentStatus();
151 System.out.println(status);
152 }
153
154 }
155
156 }