1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ws.scout.registry;
18
19 import java.io.Serializable;
20 import java.util.Properties;
21 import java.util.Set;
22
23 import javax.xml.registry.Connection;
24 import javax.xml.registry.InvalidRequestException;
25 import javax.xml.registry.JAXRException;
26 import javax.xml.registry.RegistryService;
27
28 import org.apache.commons.configuration.ConfigurationException;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.juddi.v3.client.config.UDDIClerkManager;
32
33
34
35
36
37
38
39
40 public class ConnectionImpl implements Connection, Serializable
41 {
42 public static final String JUDDI_CLIENT_CONFIG_FILE = "scout.juddi.client.config.file";
43 public static final String DEFAULT_JUDDI_CLIENT_CONFIG_FILE = "META-INF/jaxr-uddi.xml";
44 public static final String DEFAULT_UDDI_VERSION = "2.0";
45
46 private static final long serialVersionUID = 3542404895814764176L;
47 private static Log log = LogFactory.getLog(ConnectionImpl.class);
48 private boolean closed = false;
49 private boolean synchronous = true;
50 private Set credentials;
51 private final IRegistryBase registry;
52 private final String postalScheme;
53 private final int maxRows;
54 private String uddiVersion;
55 UDDIClerkManager manager = null;
56
57 public ConnectionImpl(Properties properties) throws InvalidRequestException
58 {
59 postalScheme = properties.getProperty(ConnectionFactoryImpl.POSTALADDRESSSCHEME_PROPERTY);
60 String val = properties.getProperty(ConnectionFactoryImpl.MAXROWS_PROPERTY);
61 maxRows = (val == null) ? -1 : Integer.valueOf(val);
62 uddiVersion = properties.getProperty(ConnectionFactoryImpl.UDDI_VERSION_PROPERTY, DEFAULT_UDDI_VERSION);
63
64 String uddiConfigFile = properties.getProperty(JUDDI_CLIENT_CONFIG_FILE);
65 if (isUDDIv3(uddiVersion)) {
66 String nodeName = null;
67 String managerName = null;
68 if (manager==null && uddiConfigFile!=null) {
69 try {
70 manager = new UDDIClerkManager(uddiConfigFile, properties);
71 manager.start();
72 } catch (ConfigurationException e) {
73 log.error(e.getMessage(),e);
74 }
75 }
76 if (manager !=null) {
77 try {
78 managerName = manager.getName();
79 nodeName = manager.getClientConfig().getHomeNode().getName();
80 } catch (ConfigurationException e) {
81 log.error(e.getMessage(),e);
82 }
83 }
84 registry = new RegistryV3Impl(properties, nodeName, managerName);
85 } else {
86 registry = new RegistryImpl(properties);
87 }
88
89
90
91
92 }
93
94 private boolean isUDDIv3(String version) {
95 if (version.startsWith("3")) return true;
96 return false;
97 }
98
99 public RegistryService getRegistryService() throws JAXRException
100 {
101 RegistryServiceImpl reg = new RegistryServiceImpl(registry, postalScheme, maxRows, uddiVersion);
102 reg.setConnection(this);
103 return reg;
104 }
105
106 public void close()
107 {
108 closed = true;
109 }
110
111 public boolean isClosed()
112 {
113 return closed;
114 }
115
116 public Set getCredentials()
117 {
118 return credentials;
119 }
120
121 public void setCredentials(Set credentials)
122 {
123 this.credentials = credentials;
124 }
125
126 public boolean isSynchronous()
127 {
128 return synchronous;
129 }
130
131 public void setSynchronous(boolean synchronous)
132 {
133 this.synchronous = synchronous;
134 }
135 }