1 16 package org.apache.juddi.registry; 17 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.util.Properties ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.juddi.AbstractRegistry; 25 import org.apache.juddi.datatype.RegistryObject; 26 import org.apache.juddi.datatype.request.AuthInfo; 27 import org.apache.juddi.datatype.response.AuthToken; 28 import org.apache.juddi.error.RegistryException; 29 import org.apache.juddi.error.UnsupportedException; 30 import org.apache.juddi.function.FunctionMaker; 31 import org.apache.juddi.function.IFunction; 32 import org.apache.juddi.util.Config; 33 import org.apache.juddi.util.Loader; 34 35 38 public class RegistryEngine extends AbstractRegistry 39 { 40 private static final String PROPFILE_NAME = "juddi.properties"; 42 43 public static final String PROPNAME_OPERATOR_NAME = "juddi.operatorName"; 46 47 public static final String PROPNAME_I18N_LANGUAGE_CODE = "juddi.i18n.languageCode"; 48 public static final String PROPNAME_I18N_COUNTRY_CODE = "juddi.i18n.countryCode"; 49 50 public static final String PROPNAME_DISCOVERY_URL = "juddi.discoveryURL"; 51 public static final String PROPNAME_ADMIN_EMAIL_ADDRESS = "juddi.adminEmailAddress"; public static final String PROPNAME_DATASOURCE_NAME = "juddi.dataSource"; 53 54 public static final String PROPNAME_AUTH_CLASS_NAME = "juddi.auth"; 55 public static final String PROPNAME_DATASTORE_CLASS_NAME = "juddi.dataStore"; 56 public static final String PROPNAME_CRYPTOR_CLASS_NAME = "juddi.cryptor"; 57 public static final String PROPNAME_UUIDGEN_CLASS_NAME = "juddi.uuidgen"; 58 public static final String PROPNAME_VALIDATOR_CLASS_NAME = "juddi.validator"; 59 60 public static final String PROPNAME_MAX_NAME_ELEMENTS = "juddi.maxNameElementsAllowed"; 61 public static final String PROPNAME_MAX_NAME_LENGTH = "juddi.maxNameLengthAllowed"; 62 public static final String PROPNAME_MAX_MESSAGE_SIZE = "juddi.maxMessageSize"; public static final String PROPNAME_MAX_BUSINESS_ENTITIES_PER_USER = "juddi.maxBusinessEntitiesPerUser"; public static final String PROPNAME_MAX_BUSINESS_SERVICES_PER_BUSINESS = "juddi.maxBusinessServicesPerBusiness"; public static final String PROPNAME_MAX_BINDING_TEMPLATES_PER_SERVICE = "juddi.maxBindingTemplatesPerService"; public static final String PROPNAME_MAX_TMODELS_PER_USER = "juddi.maxTModelsPerUser"; public static final String PROPNAME_MAX_ROWS_LIMIT = "juddi.maxRowsLimit"; 69 public static final String DEFAULT_OPERATOR_NAME = "Apache.org"; 72 73 public static final String DEFAULT_I18N_LANGUAGE_CODE = "en"; 74 public static final String DEFAULT_I18N_COUNTRY_CODE = "US"; 75 76 public static final String DEFAULT_DISCOVERY_URL = "http://localhost:8080/juddi/uddiget.jsp?"; 77 public static final String DEFAULT_ADMIN_EMAIL_ADDRESS = "nobody@apache.org"; public static final String DEFAULT_DATASOURCE_NAME = "java:comp/env/jdbc/juddiDB"; 79 80 public static final String DEFAULT_AUTH_CLASS_NAME = "org.apache.juddi.auth.DefaultAuthenticator"; 81 public static final String DEFAULT_DATASTORE_CLASS_NAME = "org.apache.juddi.datastore.JDBCDataStore"; 82 public static final String DEFAULT_CRYPTOR_CLASS_NAME = "org.apache.juddi.cryptor.DefaultCryptor"; 83 public static final String DEFAULT_UUIDGEN_CLASS_NAME = "org.apache.juddi.uuidgen.DefaultUUIDGen"; 84 public static final String DEFAULT_VALIDATOR_CLASS_NAME = "org.apache.juddi.validator.DefaultValidator"; 85 86 public static final int DEFAULT_MAX_NAME_ELEMENTS = 5; 87 public static final int DEFAULT_MAX_NAME_LENGTH = 255; 88 public static final int DEFAULT_MAX_MESSAGE_SIZE = 2097152; public static final int DEFAULT_MAX_BUSINESS_ENTITIES_PER_USER = 25; public static final int DEFAULT_MAX_BUSINESS_SERVICES_PER_BUSINESS = 20; public static final int DEFAULT_MAX_BINDING_TEMPLATES_PER_SERVICE = 10; public static final int DEFAULT_MAX_TMODELS_PER_USER = 100; public static final int DEFAULT_MAX_ROWS_LIMIT = 10; 95 private static Log log = LogFactory.getLog(RegistryEngine.class); 97 98 private FunctionMaker maker = null; 100 101 private boolean isAvailable = false; 103 104 111 public RegistryEngine() 112 { 113 super(); 114 115 try { 119 InputStream stream = Loader.getResourceAsStream(PROPFILE_NAME); 120 if (stream != null) 121 { 122 Properties props = new Properties (); 123 props.load(stream); 124 Config.addProperties(props); 125 } 126 } 127 catch (IOException ioex) { 128 log.error("An error occured while loading properties from: "+PROPFILE_NAME,ioex); 129 } 130 } 131 132 139 public RegistryEngine(Properties props) 140 { 141 super(); 142 143 if (props != null) 144 Config.addProperties(props); 145 } 146 147 150 public void init() 151 { 152 isAvailable = false; 154 155 this.maker = new FunctionMaker(this); 158 159 isAvailable = true; 161 } 162 163 167 public void dispose() 168 { 169 isAvailable = false; 171 } 172 173 177 public boolean isAvailable() 178 { 179 return this.isAvailable; 180 } 181 182 185 public RegistryObject execute(RegistryObject request) 186 throws RegistryException 187 { 188 String className = request.getClass().getName(); 189 190 IFunction function = (IFunction)maker.lookup(className); 191 if (function == null) 192 throw new UnsupportedException(className); 193 194 RegistryObject response = function.execute(request); 195 196 return response; 197 } 198 199 200 201 202 203 204 205 public static void main(String [] args) 206 throws Exception 207 { 208 211 Properties props = new Properties (); 213 props.setProperty(RegistryEngine.PROPNAME_OPERATOR_NAME,"jUDDI.org"); 214 props.setProperty(RegistryEngine.PROPNAME_MAX_NAME_ELEMENTS,"5"); 215 props.setProperty(RegistryEngine.PROPNAME_MAX_NAME_LENGTH,"255"); 216 props.setProperty(RegistryEngine.PROPNAME_DISCOVERY_URL,"http://localhost/juddi"); 217 props.setProperty(RegistryEngine.PROPNAME_ADMIN_EMAIL_ADDRESS,"admin@juddi.org"); 218 props.setProperty(RegistryEngine.PROPNAME_MAX_MESSAGE_SIZE,"2097152"); 219 props.setProperty(RegistryEngine.PROPNAME_AUTH_CLASS_NAME,"org.apache.juddi.auth.DefaultAuthenticator"); 220 props.setProperty(RegistryEngine.PROPNAME_CRYPTOR_CLASS_NAME,"org.apache.juddi.cryptor.DefaultCryptor"); 221 props.setProperty(RegistryEngine.PROPNAME_UUIDGEN_CLASS_NAME,"org.apache.juddi.uuidgen.DefaultUUIDGen"); 222 223 props.setProperty("juddi.useConnectionPool","true"); 224 props.setProperty("juddi.jdbcDriver","com.mysql.jdbc.Driver"); 225 props.setProperty("juddi.jdbcURL","jdbc:mysql://localhost/juddi"); 226 props.setProperty("juddi.jdbcUser","juddi"); 227 props.setProperty("juddi.jdbcPassword","juddi"); 228 props.setProperty("juddi.jdbcMaxActive","10"); 229 props.setProperty("juddi.jdbcMaxIdle","10"); 230 231 RegistryEngine registry = new RegistryEngine(props); 232 233 registry.init(); 235 236 System.out.println(Config.getProperties()); 238 239 AuthToken authToken = registry.getAuthToken("sviens","password"); 240 AuthInfo authInfo = authToken.getAuthInfo(); 241 242 System.out.println("AuthToken: "+authInfo.getValue()); 243 244 registry.dispose(); 246 } 247 } | Popular Tags |