This project has retired. For details please refer to its Attic page.
Coverage Report
Coverage Report - org.apache.ws.scout.registry.ConnectionImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ConnectionImpl
50%
25/50
33%
6/18
2.333
 
 1  
 /*
 2  
  * Copyright 2001-2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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.UDDIClient;
 32  
 
 33  
 /**
 34  
  * Apache Scout Implementation of a JAXR Connection.
 35  
  * For futher details, look into the JAXR API Javadoc.
 36  
  *
 37  
  * @author Anil Saldhana  <anil@apache.org>
 38  
  * @author Tom Cunningham <tcunning@apache.org>
 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  2
         private static Log log = LogFactory.getLog(ConnectionImpl.class);
 48  116
         private boolean closed = false;
 49  116
     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  116
     UDDIClient manager = null;
 56  
 
 57  
     public ConnectionImpl(Properties properties) throws InvalidRequestException
 58  116
     {
 59  116
         postalScheme = properties.getProperty(ConnectionFactoryImpl.POSTALADDRESSSCHEME_PROPERTY);
 60  116
         String val = properties.getProperty(ConnectionFactoryImpl.MAXROWS_PROPERTY);
 61  116
         maxRows = (val == null) ? -1 : Integer.valueOf(val);
 62  116
         uddiVersion = properties.getProperty(ConnectionFactoryImpl.UDDI_VERSION_PROPERTY, DEFAULT_UDDI_VERSION);
 63  
         //The TCK does not set the UDDI_VERSION, so if the lifecycle URL contains 'v3' we 
 64  
         //automagically set the version to be "3.0"
 65  116
         if (!properties.contains(ConnectionFactoryImpl.UDDI_VERSION_PROPERTY) 
 66  116
                 && (properties.contains(ConnectionFactoryImpl.LIFECYCLEMANAGER_PROPERTY)) 
 67  0
                 && properties.getProperty(ConnectionFactoryImpl.LIFECYCLEMANAGER_PROPERTY).contains("v3") ) {
 68  0
             properties.setProperty(ConnectionFactoryImpl.UDDI_VERSION_PROPERTY, "3.0");
 69  0
             uddiVersion = "3.0";
 70  0
             String securityManager = properties.getProperty(ConnectionFactoryImpl.LIFECYCLEMANAGER_PROPERTY).replace("publish", "security");
 71  0
             properties.setProperty(ConnectionFactoryImpl.SECURITYMANAGER_PROPERTY, securityManager);
 72  
         }
 73  
      
 74  116
         String uddiConfigFile      = properties.getProperty(JUDDI_CLIENT_CONFIG_FILE);// DEFAULT_JUDDI_CLIENT_CONFIG_FILE);
 75  116
         if (isUDDIv3(uddiVersion)) {
 76  0
             String nodeName = null;
 77  0
             String managerName = null;
 78  0
             if (manager==null && uddiConfigFile!=null) {
 79  
                 try {
 80  0
                     manager = new UDDIClient(uddiConfigFile, properties);
 81  0
                     manager.start();
 82  0
                 } catch (ConfigurationException e) {
 83  0
                     log.error(e.getMessage(),e);
 84  0
                 }
 85  
             }
 86  0
             if (manager !=null) {
 87  
                 try {
 88  0
                     managerName = manager.getName();
 89  0
                     nodeName = manager.getClientConfig().getHomeNode().getName();
 90  0
                 } catch (ConfigurationException e) {
 91  0
                     log.error(e.getMessage(),e);
 92  0
                 }
 93  
             }
 94  0
             registry = new RegistryV3Impl(properties, nodeName, managerName);
 95  0
         } else {
 96  116
             registry = new RegistryImpl(properties);                   
 97  
         }
 98  
 
 99  
         //this.postalScheme = postalScheme;
 100  
         //this.maxRows = maxRows;
 101  
 
 102  116
     }
 103  
     
 104  
     private boolean isUDDIv3(String version) {
 105  116
         if (version.startsWith("3")) return true;
 106  116
         return false;
 107  
     }
 108  
 
 109  
     public RegistryService getRegistryService() throws JAXRException
 110  
     {
 111  136
         RegistryServiceImpl reg = new RegistryServiceImpl(registry, postalScheme, maxRows, uddiVersion);
 112  136
         reg.setConnection(this);
 113  136
         return reg;
 114  
     }
 115  
 
 116  
     public void close()
 117  
     {
 118  62
         closed = true;
 119  62
     }
 120  
 
 121  
     public boolean isClosed()
 122  
     {
 123  0
         return closed;
 124  
     }
 125  
 
 126  
     public Set getCredentials()
 127  
     {
 128  202
         return credentials;
 129  
     }
 130  
 
 131  
     public void setCredentials(Set credentials)
 132  
     {
 133  118
         this.credentials = credentials;
 134  118
     }
 135  
 
 136  
     public boolean isSynchronous()
 137  
     {
 138  0
         return synchronous;
 139  
     }
 140  
 
 141  
     public void setSynchronous(boolean synchronous)
 142  
     {
 143  0
         this.synchronous = synchronous;
 144  0
     }
 145  
 }