Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultServiceFactory.java @ 92:73d0ebae81d7
Last bunch of javadoc
artifacts/trunk@848 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 28 Mar 2010 14:16:05 +0000 |
parents | 68285f7bc476 |
children | e27cf9c84eb8 |
rev | line source |
---|---|
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.artifactdatabase; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import org.w3c.dom.Document; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import org.w3c.dom.Node; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import de.intevation.artifacts.ServiceFactory; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import de.intevation.artifacts.Service; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import org.apache.log4j.Logger; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 /** |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
12 * Trivial implementation of the ServiceFactory interface. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
13 * Name and an description are configured by the given Node given to |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
14 * #setup(Document, Node) via the 'name' and 'description' attributes. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
15 * The name of the class that provides the concrete serice is configured |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
16 * by the 'service' attribute. |
90
68285f7bc476
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
89
diff
changeset
|
17 * |
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:
69
diff
changeset
|
18 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 */ |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public class DefaultServiceFactory |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 implements ServiceFactory |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 private static Logger logger = |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 Logger.getLogger(DefaultServiceFactory.class); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
26 /** |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
27 * XPath to access the name of the service. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
28 */ |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 public static final String XPATH_NAME = "@name"; |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
30 /** |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
31 * XPath to access the description of the service. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
32 */ |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 public static final String XPATH_DESCRIPTION = "@description"; |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
34 /** |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
35 * XPath to access the class name of the service to be build by |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
36 * this factory. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
37 */ |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 public static final String XPATH_SERVICE = "@service"; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
40 /** |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
41 * Default description if no description is given in configuration. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
42 */ |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public static final String DEFAULT_DESCRIPTION = |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 "No description available"; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
46 /** |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
47 * Loaded service class if no class name is given in the configuration. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
48 */ |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 public static final String DEFAULT_SERVICE = |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 "de.intevation.artifactdatabase.DefaultService"; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
52 /** |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
53 * The name of the service factory. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
54 */ |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 protected String name; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
57 /** |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
58 * The description of the service factory. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
59 */ |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 protected String description; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
62 /** |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
63 * The loaded class used to build the concrete service. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
64 */ |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 protected Class serviceClass; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
67 /** |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
68 * Default constructor. |
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
77
diff
changeset
|
69 */ |
69
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 public DefaultServiceFactory() { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 public String getName() { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 return name; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 public String getDescription() { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 return description; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 public Service createService(Object globalContext) { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 try { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 Service service = (Service)serviceClass.newInstance(); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 service.setup(this, globalContext); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 return service; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 catch (InstantiationException ie) { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 logger.error(ie.getLocalizedMessage(), ie); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 catch (IllegalAccessException iae) { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 logger.error(iae.getLocalizedMessage(), iae); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 catch (ClassCastException cce) { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 logger.error(cce.getLocalizedMessage(), cce); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 return null; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 public void setup(Document config, Node factoryNode) { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 description = Config.getStringXPath( |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 factoryNode, XPATH_DESCRIPTION, DEFAULT_DESCRIPTION); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 name = Config.getStringXPath( |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 factoryNode, XPATH_NAME, toString()); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 String service = Config.getStringXPath( |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 factoryNode, XPATH_SERVICE, DEFAULT_SERVICE); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 try { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 serviceClass = Class.forName(service); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 catch (ClassNotFoundException cnfe) { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 logger.error(cnfe.getLocalizedMessage(), cnfe); |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 if (serviceClass == null) { |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 serviceClass = DefaultService.class; |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 } |
498bb84334d0
Added base class for services and service factories.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |