1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.sovt;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.sovt.xml.Loader;
33
34 import java.util.HashMap;
35 import java.util.Map;
36
37 /***
38 * This class holds all transformers, validators and inspectors. Different
39 * factories register instances of them which have "id" attribute specified.
40 *
41 * @author Vilmantas Baranauskas (vilmantas_baranauskas@yahoo.com)
42 */
43 public final class SovtLibrary {
44 /***
45 * Logger.
46 */
47 private static Log log = LogFactory.getLog(SovtLibrary.class);
48
49
50 /***
51 * Name of the default Sovt xml library.
52 */
53 public static final String DEFAULT_LIB = "sovt.xml";
54
55
56 /***
57 * Contains named inspectors.
58 */
59 private Map inspectors = new HashMap();
60
61 /***
62 * Contains named transformer.
63 */
64 private Map transformers = new HashMap();
65 /***
66 * Contains named validators.
67 */
68 private Map validators = new HashMap();
69
70 /***
71 * Instance of this class.
72 */
73 private static SovtLibrary instance = new SovtLibrary();
74
75
76 static {
77
78 try {
79 Loader.loadLibrary(DEFAULT_LIB);
80 } catch (InstantiationException e) {
81 log.error(
82 "Cannot load default SOVT library [" + DEFAULT_LIB + "]",
83 e
84 );
85 }
86 }
87
88 /***
89 * Creates instance of library. SovtLibrary is empty after creation.
90 */
91 private SovtLibrary() {
92 }
93
94 /***
95 * Returns instance of library.
96 *
97 * @return instance of library.
98 */
99 public static SovtLibrary getInstance() {
100 return instance;
101 }
102
103
104 /***
105 * Adds named inspector.
106 *
107 * @param id ID (name) of inspector
108 * @param inspector Inspector to add.
109 */
110 public void addInspector(String id, Inspector inspector) {
111 log.debug("Registering inspector [" + id + "]");
112 inspectors.put(id, inspector);
113 }
114
115 /***
116 * Adds named validator.
117 *
118 * @param id ID (name) of validator
119 * @param validator Validator to add.
120 */
121 public void addValidator(String id, Validator validator) {
122 log.debug("Registering validator [" + id + "]");
123 validators.put(id, validator);
124 }
125
126 /***
127 * Adds named transformer.
128 *
129 * @param id ID (name) of transformer
130 * @param transformer Transformer to add.
131 */
132 public void addTransformer(String id, Transformer transformer) {
133 log.debug("Registering transformer [" + id + "]");
134 transformers.put(id, transformer);
135 }
136
137 /***
138 * Returns named inspector.
139 *
140 * @param id ID (name) of inspector.
141 * @return Inspector or null if there is no such inspector.
142 */
143 public Inspector getInspector(String id) {
144 return (Inspector) inspectors.get(id);
145 }
146
147 /***
148 * Returns named validator.
149 *
150 * @param id ID (name) of validator.
151 * @return Validator or null if there is no such validator.
152 */
153 public Validator getValidator(String id) {
154 return (Validator) validators.get(id);
155 }
156
157 /***
158 * Returns named transformer.
159 *
160 * @param id ID (name) of transformer.
161 * @return Transformer or null if there is no such transformer.
162 */
163 public Transformer getTransformer(String id) {
164 return (Transformer) transformers.get(id);
165 }
166
167 }