Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServicesResource.java @ 95:0edcaf5b5c78
The path to database can be configured with a path relative to the configuration directory.
artifacts/trunk@1007 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 27 Apr 2010 16:12:37 +0000 |
parents | d348fe1fd822 |
children | 933bbc9fc11f |
rev | line source |
---|---|
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.artifactdatabase.rest; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import de.intevation.artifactdatabase.XMLUtils.ElementCreator; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import de.intevation.artifactdatabase.XMLUtils; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import de.intevation.artifacts.ArtifactDatabase; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import de.intevation.artifacts.ArtifactNamespaceContext; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import org.apache.log4j.Logger; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import org.restlet.data.MediaType; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import org.restlet.ext.xml.DomRepresentation; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import org.restlet.representation.Representation; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import org.restlet.resource.ResourceException; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import org.w3c.dom.Document; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 import org.w3c.dom.Element; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 /** |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
24 * Resource to list the available service offered by the artifact database. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
25 * |
77
48d1a9a082c2
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
72
diff
changeset
|
26 * @author <a href="mailto:sascha.teichmann@intevation">Sascha L. Teichmann</a> |
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 */ |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public class ServicesResource |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 extends BaseResource |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 { |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 private static Logger logger = Logger.getLogger(ServicesResource.class); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
88
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
33 /** |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
34 * server URL where to reach the resource. |
69c84cf7c5d7
Added javadoc to the REST package of the artifact database (complete).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
35 */ |
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 public static final String PATH = "/services"; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
88
diff
changeset
|
38 @Override |
72
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 protected Representation innerGet() |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 throws ResourceException |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 { |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 Document document = XMLUtils.newDocument(); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 ElementCreator ec = new ElementCreator( |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 document, |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 ArtifactNamespaceContext.NAMESPACE_URI, |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 ArtifactDatabase db = (ArtifactDatabase)getContext() |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 .getAttributes().get("database"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 Element root = ec.create("result"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 document.appendChild(root); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 Element type = ec.create("type"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 ec.addAttr(type, "name", "service-list"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 root.appendChild(type); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 Element factories = ec.create("services"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 root.appendChild(factories); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 String [][] factoryNames = db.serviceNamesAndDescriptions(); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 for (int i = 0; i < factoryNames.length; ++i) { |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 String [] nd = factoryNames[i]; |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 Element factoryElement = ec.create("service"); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 ec.addAttr(factoryElement, "name", nd[0]); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 ec.addAttr(factoryElement, "description", nd[1]); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 factories.appendChild(factoryElement); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 } |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 document.normalizeDocument(); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 return new DomRepresentation( |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 MediaType.APPLICATION_XML, document); |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 } |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 } |
b01e47317a78
Added '/services' url to web server to list the available services in XML.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |