View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/ConnectionFactoryImpl.java,v 1.11 2003/09/12 13:43:10 doballve Exp $ 3 * 4 * ==================================================================== 5 * 6 * This code is subject to the freebxml License, Version 1.1 7 * 8 * Copyright (c) 2003 freebxml.org. All rights reserved. 9 * 10 * ==================================================================== 11 */ 12 13 package com.sun.xml.registry.ebxml; 14 15 import java.util.Collection; 16 import java.util.Enumeration; 17 import java.util.Properties; 18 19 import javax.xml.registry.Connection; 20 import javax.xml.registry.ConnectionFactory; 21 import javax.xml.registry.FederatedConnection; 22 import javax.xml.registry.JAXRException; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.commons.logging.impl.LogFactoryImpl; 27 28 import com.sun.xml.registry.ebxml.util.ProviderProperties; 29 import java.util.Locale; 30 31 /*** 32 * Class Declaration for Class1 33 * 34 */ 35 public class ConnectionFactoryImpl extends ConnectionFactory { 36 37 private Log log; 38 private ProviderProperties providerProps = ProviderProperties.getInstance(); 39 40 41 public ConnectionFactoryImpl() throws JAXRException 42 { 43 initLogging(this.providerProps.getProperties()); 44 initLocale(this.providerProps.getProperties()); 45 } 46 47 48 /*** 49 * Sets the Properties used during createConnection 50 * and createFederatedConnection calls. 51 * 52 * <p><DL><DT><B>Capability Level: 0 </B></DL> 53 * 54 * @param properties configuration properties that are either 55 * specified by JAXR or provider specific. 56 */ 57 public void setProperties(Properties properties) throws JAXRException{ 58 this.providerProps.mergeProperties(properties); 59 } 60 61 62 /*** 63 * Gets the Properties used during createConnection 64 * and createFederatedConnection calls. 65 * 66 * <p><DL><DT><B>Capability Level: 0 </B></DL> 67 * 68 */ 69 public Properties getProperties() throws JAXRException{ 70 return this.providerProps.getProperties(); 71 } 72 73 /*** 74 * Create a named connection. Such a connection can be used to 75 * communicate with a JAXR provider. 76 * 77 * <p><DL><DT><B>Capability Level: 0 </B></DL> 78 * 79 * @link dependency 80 * @label creates 81 * @associates <{Connection}> 82 */ 83 public Connection createConnection() throws JAXRException { 84 Connection connection = new ConnectionImpl(this); 85 return connection; 86 } 87 88 /*** 89 * Create a FederatedConnection. 90 * 91 * <p><DL><DT><B>Capability Level: 0 (optional) </B></DL> 92 * 93 * @param connections Is a Collection of Connection objects. Note that 94 * Connection objects may also be FederatedConnection objects. 95 * 96 * @link dependency 97 * @label creates 98 * @associates <{FederatedConnection}> 99 */ 100 public FederatedConnection createFederatedConnection(Collection connections) throws JAXRException{ 101 // Write your code here 102 return null; 103 } 104 105 106 /*** 107 * Init Apache Commons Logging 108 * 109 * Use SimpleLog by default which prints out "info" level messages and 110 * above to stderr. SimpleLog uses System properties starting w/ 111 * "org.apache.commons.logging.simplelog." for configuration. 112 */ 113 private void initLogging(Properties props) 114 throws JAXRException 115 { 116 LogFactory lf = LogFactory.getFactory(); 117 118 // Assume we are using the default LogFactoryImpl 119 120 // We use logClassName to force the SimpleLog logger be the default 121 // instead of other possible loggers returned by the LogFactoryImpl 122 // code. 123 String logClassName = null; 124 try { 125 logClassName = System.getProperty(LogFactoryImpl.LOG_PROPERTY, 126 "org.apache.commons.logging.impl.SimpleLog"); 127 128 // Translate a shortcut prop name to full SimpleLog name 129 String defaultLog = props.getProperty("jaxr.defaultlog"); 130 if (defaultLog != null) { 131 System.setProperty( 132 "org.apache.commons.logging.simplelog.defaultlog", 133 defaultLog); 134 } 135 136 // Set any props that are for Apache commons logging as System 137 // props 138 Enumeration e = props.propertyNames(); 139 while (e.hasMoreElements()) { 140 String propertyName = (String)e.nextElement(); 141 if (propertyName.startsWith("org.apache.commons.logging")) { 142 System.setProperty(propertyName, 143 props.getProperty(propertyName)); 144 } 145 } 146 } catch (SecurityException e) { 147 System.err.println("Warning: cannot initialize logging:" 148 + "unable to access System properties"); 149 // throw new JAXRException("Unable to access System properties"); 150 } 151 lf.setAttribute(LogFactoryImpl.LOG_PROPERTY, logClassName); 152 log = lf.getInstance(ConnectionFactoryImpl.class); 153 log.debug("Logging initialized"); 154 } 155 156 /*** 157 * Internal method to return logger 158 */ 159 public Log getLog() { 160 return log; 161 } 162 163 /*** 164 * Sets initial Locale. 165 * 166 * The Locale is defined by 3 properties: 167 * <ul> 168 * <li>jaxr-ebxml.initial-locale.language</li> 169 * <li>jaxr-ebxml.initial-locale.country</li> 170 * <li>jaxr-ebxml.initial-locale.variant</li> 171 * </ul> 172 * Locale.setDefault will be called with a new Locale created using language, 173 * country and variant (if defined, up to the first missing of the 3 174 * properties). If language property is not defined, Locale WILL NOT be 175 * changed. See http://java.sun.com/j2se/1.4.1/docs/api/java/util/Locale.html 176 * for possible values for language, country and variant. 177 * 178 * @param props The source for the properties. 179 */ 180 private void initLocale(Properties props) { 181 String language = props.getProperty("jaxr-ebxml.initial-locale.language"); 182 String country = props.getProperty("jaxr-ebxml.initial-locale.country"); 183 String variant = props.getProperty("jaxr-ebxml.initial-locale.variant"); 184 if (language == null || language.length() == 0) { 185 return; 186 } else if (country == null || country.length() == 0) { 187 Locale.setDefault(new Locale(language)); 188 } else if (variant == null || variant.length() == 0) { 189 Locale.setDefault(new Locale(language, country)); 190 } else { 191 Locale.setDefault(new Locale(language, country, variant)); 192 } 193 } 194 }

This page was automatically generated by Maven