001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.ws.scout.registry;
018:
019: import java.io.Serializable;
020: import java.net.URI;
021: import java.net.URISyntaxException;
022: import java.util.Collection;
023: import java.util.Properties;
024:
025: import javax.xml.registry.Connection;
026: import javax.xml.registry.ConnectionFactory;
027: import javax.xml.registry.FederatedConnection;
028: import javax.xml.registry.InvalidRequestException;
029: import javax.xml.registry.JAXRException;
030: import javax.xml.registry.UnsupportedCapabilityException;
031:
032: /**
033: * Our implmentation of javax.xml.registry.ConnectionFactory.
034: * Also exposes the properties as JavaBean properties to ease use
035: * with a managed environment such as an application server.
036: *
037: * @author Anil Saldhana <anil@apache.org>
038: * @author Jeremy Boynes <jboynes@apache.org>
039: */
040: public class ConnectionFactoryImpl extends ConnectionFactory implements
041: Serializable {
042: private static final long serialVersionUID = 1L;
043: private static final String QUERYMANAGER_PROPERTY = "javax.xml.registry.queryManagerURL";
044: private static final String LIFECYCLEMANAGER_PROPERTY = "javax.xml.registry.lifeCycleManagerURL";
045: private static final String SEMANTICEQUIVALENCES_PROPERTY = "javax.xml.registry.semanticEquivalences";
046: private static final String POSTALADDRESSSCHEME_PROPERTY = "javax.xml.registry.postalAddressScheme";
047: private static final String AUTHENTICATIONMETHOD_PROPERTY = "javax.xml.registry.security.authenticationMethod";
048: private static final String MAXROWS_PROPERTY = "javax.xml.registry.uddi.maxRows";
049:
050: private String queryManagerURL;
051: private String lifeCycleManagerURL;
052: private String transportClass;
053: private String semanticEquivalences;
054: private String authenticationMethod;
055: private Integer maxRows;
056: private String postalAddressScheme;
057:
058: /**
059: * Public no-arg constructor so that this ConnectionFactory can be
060: * instantiated by the JAXR ConnectionFactory;
061: */
062: public ConnectionFactoryImpl() {
063: }
064:
065: public Connection createConnection() throws JAXRException {
066: if (queryManagerURL == null) {
067: throw new InvalidRequestException("queryManager is not set");
068: }
069: URI queryManager;
070: URI lifeCycleManager;
071: try {
072: queryManager = new URI(queryManagerURL);
073: } catch (URISyntaxException e) {
074: throw new InvalidRequestException(
075: "Invalid queryManagerURL: " + queryManagerURL, e);
076: }
077: try {
078: lifeCycleManager = lifeCycleManagerURL == null ? queryManager
079: : new URI(lifeCycleManagerURL);
080: } catch (URISyntaxException e) {
081: throw new InvalidRequestException(
082: "Invalid lifeCycleManagerURL: "
083: + lifeCycleManagerURL, e);
084: }
085: return new ConnectionImpl(queryManager, lifeCycleManager,
086: transportClass, null, maxRows == null ? -1 : maxRows
087: .intValue());
088: }
089:
090: public FederatedConnection createFederatedConnection(
091: Collection collection) throws JAXRException {
092: throw new UnsupportedCapabilityException(
093: "FederatedConnections are not supported in this release");
094: }
095:
096: /**
097: * Returns a value copy of the properties that will be used to create
098: * a Connections. Operations on this Properties objects will not affect
099: * this ConnectionFactory; use setProperties(Properties) to save changes.
100: *
101: * @return a Properties object containing the properies that will be used to create Connection
102: */
103: public Properties getProperties() {
104: Properties props = new Properties();
105: if (queryManagerURL != null) {
106: props.put(QUERYMANAGER_PROPERTY, queryManagerURL);
107: }
108: if (lifeCycleManagerURL != null) {
109: props.put(LIFECYCLEMANAGER_PROPERTY, lifeCycleManagerURL);
110: }
111: if (semanticEquivalences != null) {
112: props.put(SEMANTICEQUIVALENCES_PROPERTY,
113: semanticEquivalences);
114: }
115: if (postalAddressScheme != null) {
116: props
117: .put(POSTALADDRESSSCHEME_PROPERTY,
118: postalAddressScheme);
119: }
120: if (authenticationMethod != null) {
121: props.put(AUTHENTICATIONMETHOD_PROPERTY,
122: authenticationMethod);
123: }
124: if (maxRows != null) {
125: props.put(MAXROWS_PROPERTY, maxRows.toString());
126: }
127: return props;
128: }
129:
130: /**
131: * Update the properties used by this ConnectionFactory to obtain a connection.
132: *
133: * @param properties the new properties for this ConnectionFactory
134: */
135: public void setProperties(Properties properties) {
136: queryManagerURL = properties.getProperty(QUERYMANAGER_PROPERTY);
137: lifeCycleManagerURL = properties
138: .getProperty(LIFECYCLEMANAGER_PROPERTY);
139: transportClass = properties
140: .getProperty(RegistryImpl.TRANSPORT_CLASS_PROPERTY_NAME);
141: semanticEquivalences = properties
142: .getProperty(SEMANTICEQUIVALENCES_PROPERTY);
143: authenticationMethod = properties
144: .getProperty(AUTHENTICATIONMETHOD_PROPERTY);
145: postalAddressScheme = properties
146: .getProperty(POSTALADDRESSSCHEME_PROPERTY);
147: String val = properties.getProperty(MAXROWS_PROPERTY);
148: maxRows = (val == null) ? null : Integer.valueOf(val);
149: }
150:
151: public static ConnectionFactory newInstance() {
152: return new ConnectionFactoryImpl();
153: }
154:
155: public String getAuthenticationMethod() {
156: return authenticationMethod;
157: }
158:
159: public void setAuthenticationMethod(String authenticationMethod) {
160: this .authenticationMethod = authenticationMethod;
161: }
162:
163: public String getLifeCycleManagerURL() {
164: return lifeCycleManagerURL;
165: }
166:
167: public void setLifeCycleManagerURL(String lifeCycleManagerURL) {
168: this .lifeCycleManagerURL = lifeCycleManagerURL;
169: }
170:
171: public Integer getMaxRows() {
172: return maxRows;
173: }
174:
175: public void setMaxRows(Integer maxRows) {
176: this .maxRows = maxRows;
177: }
178:
179: public String getPostalAddressScheme() {
180: return postalAddressScheme;
181: }
182:
183: public void setPostalAddressScheme(String postalAddressScheme) {
184: this .postalAddressScheme = postalAddressScheme;
185: }
186:
187: public String getQueryManagerURL() {
188: return queryManagerURL;
189: }
190:
191: public void setQueryManagerURL(String queryManagerURL) {
192: this .queryManagerURL = queryManagerURL;
193: }
194:
195: public String getSemanticEquivalences() {
196: return semanticEquivalences;
197: }
198:
199: public void setSemanticEquivalences(String semanticEquivalences) {
200: this .semanticEquivalences = semanticEquivalences;
201: }
202:
203: public String getTransportClass() {
204: return transportClass;
205: }
206:
207: public void setTransportClass(String transportClass) {
208: this.transportClass = transportClass;
209: }
210: }
|