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.manager.MetadataService;
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: HEAD $
41 * @since iteration5
42 */
43 public class RegistryUploader implements ComponentDescriptor{
44 /***
45 * Commons Logger for this class
46 */
47 private static final Log logger = LogFactory.getLog(RegistryUploader.class);
48
49 private final MetadataService 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(MetadataService 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 delegate.update(provider.returnRegistryEntry());
80
81 }
82
83 /***
84 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
85 */
86 public String getName() {
87 return "Registry entry uploader";
88 }
89
90 /***
91 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
92 */
93 public String getDescription() {
94
95 try {
96 return "Registers application list with registry"
97 + "\n registry status is " + adminLocator.getClient().getCurrentStatus();
98 }
99 catch (Exception e) {
100 return "problem accessing registry \n" + e.getMessage();
101 }
102
103 }
104
105 /***
106 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
107 */
108 public Test getInstallationTest() {
109 return new InstallationTest("testAdminLocator");
110 }
111
112 /***Installation test for {@link RegistryUploader} - tests that the provided admin locator does provide a connection to a valid registry service
113 * @author Noel Winstanley nw@jb.man.ac.uk 26-Jul-2004
114 *
115 */
116 public class InstallationTest extends TestCase {
117
118 public InstallationTest(String arg0) {
119 super(arg0);
120 }
121
122 public void testAdminLocator() throws Exception{
123 RegistryAdminService delegate = adminLocator.getClient();
124 assertNotNull(delegate);
125 String status = delegate.getCurrentStatus();
126 System.out.println(status);
127 }
128
129 }
130
131 }