1
2
3
4
5
6 package net.kwfgrid.gworkflowdl.protocol.xupdate;
7
8 import net.kwfgrid.jxupdate.jaxen.jbind.BindingFactory;
9 import net.kwfgrid.jxupdate.jaxen.jbind.BindingException;
10 import net.kwfgrid.jxupdate.jaxen.jbind.reflection.ReflectionBindingFactory;
11
12 import java.io.*;
13
14 import org.apache.log4j.Logger;
15
16 /***
17 A tool to get the latest JBind BindingFactory.
18 */
19 public class JBindFactoryProvider {
20 public static final String CURRENT_VERSION = "/gwdl-2.1_binding.xml";
21
22 /***
23 This class is never instantiated.
24 */
25 private JBindFactoryProvider() {
26
27 }
28
29 private static BindingFactory _instance;
30
31 /***
32 Get the default singleton instance of the binding factory.
33 The location of the binding definition is specified by the static member <code>CURRENT_VERSION</code>.
34 */
35 public static synchronized BindingFactory getBindingFactory() {
36 try {
37 if (_instance==null)
38 _instance = new ReflectionBindingFactory(JBindFactoryProvider.class.getResourceAsStream(CURRENT_VERSION));
39 } catch (BindingException x) {
40 Logger.getLogger(JBindFactoryProvider.class).fatal("Could not instantiate BindingFactory.", x);
41 }
42 return _instance;
43 }
44
45 /***
46 Get an instance of a binding factory with the specified binding definition.
47 @param bindingdefinition The path to the binding definition. Will be resolved by <code>JBindFactoryProvider.class.getResourceAsStream(String)</code>.
48 @return A new instance of the binding factory.
49 @exception IOException If the binding definition could not be found.
50 @exception BindingException If the factory could not be instantiated.
51 */
52 public static synchronized BindingFactory getBindingFactory(String bindingdefinition) throws IOException, BindingException {
53 InputStream stream = JBindFactoryProvider.class.getResourceAsStream(bindingdefinition);
54 if (stream == null)
55 throw new IOException("Binding definition with path "+bindingdefinition+" could not be found.");
56 return new ReflectionBindingFactory(stream);
57 }
58 }