01: package net.refractions.udig.catalog.ui;
02:
03: import java.io.Serializable;
04: import java.net.URL;
05: import java.util.Map;
06:
07: import org.eclipse.core.runtime.CoreException;
08:
09: /**
10: * Implementations of this class provide connection information based on
11: * context.
12: * <p>
13: * The connection information can be in the form of a map of connection
14: * paramters, or a url, or both.
15: * </p>
16: * <p>
17: * Implementations of this class have two responsibilties. The first is to
18: * create a set of connection paramters based on context. The second is to
19: * create a user interface capable of capturing user connection parameters.
20: * </p>
21: * <p>
22: * Implementations of this class are provided via the
23: * net.refractions.udig.catalog.ui.connectionFactory extension point.
24: * </p>
25: *
26: * @author Justin Deoliveira,Refractions Research Inc.,jdeolive@refractions.net
27: *
28: */
29: public abstract class UDIGConnectionFactory {
30:
31: /** extension point id **/
32: public static final String XPID = "net.refractions.udig.catalog.ui.connectionFactory"; //$NON-NLS-1$
33:
34: protected UDIGConnectionFactoryDescriptor descriptor;
35:
36: /**
37: * Determines if the connection factory is capable of providing some
38: * connection information based on the context object.
39: *
40: * @param object The object to be "processed" or "adapted" into connection
41: * information.
42: *
43: * @return True if the info can be returned based on the conext, otherwise
44: * false.
45: */
46: public abstract boolean canProcess(Object context);
47:
48: /**
49: * Get the connection parameters based on the provided context.
50: * <p>
51: * Context is often data from a workbench selection, but does not have to
52: * be.
53: * </p>
54: * @param object The object to be "processed" or "adapted" into a map of
55: * connection parameters.
56: * @return Map of connection parameters, or null if no such parameters could
57: * be created.
58: */
59: public abstract Map<String, Serializable> createConnectionParameters(
60: Object context);
61:
62: /**
63: * Get a connection url based on the provided context.
64: * <p>
65: * Context is often data from a workbench selection, but does not have to
66: * be.
67: * </p>
68: * @param object The object to be "processed" or "adapted" into a url.
69: *
70: * @return An url, or null if no such url can be created.
71: */
72: public abstract URL createConnectionURL(Object context);
73:
74: /**
75: * Sets the descriptor which describies the connection factory.
76: */
77: public void setDescriptor(UDIGConnectionFactoryDescriptor descriptor) {
78: this .descriptor = descriptor;
79: }
80:
81: /**
82: * This method returns the wizard page used to capture connecetion
83: * parameters. Subclasses may extend, but not overide this method.
84: *
85: * @return A wizard connection page used to capture connection parameters.
86: */
87: public UDIGConnectionPage createConnectionPage() {
88: try {
89: return descriptor.createConnectionPage();
90: } catch (CoreException e) {
91: CatalogUIPlugin.log(e.getLocalizedMessage(), e);
92: }
93:
94: return null;
95: }
96:
97: }
|