View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2001 - 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 package com.sun.ebxml.registry.repository; 11 12 import java.lang.reflect.Constructor; 13 import java.lang.reflect.Method; 14 15 import org.apache.commons.logging.LogFactory; 16 17 import com.sun.ebxml.registry.util.RegistryProperties; 18 19 20 /*** 21 * RepositoryManagerFactory that provides access to concrete 22 * RepositoryManager instance. 23 * 24 * @author Peter Burgess 25 * 26 * @version $Version: $ [$Date: 2003/03/18 07:56:08 $] 27 */ 28 29 public class RepositoryManagerFactory { 30 31 /*** ebxmlrr.properties key for concrete RepositoryManager class */ 32 private static final String REPOSITORY_MANAGER_CLASS_PROPERTY = 33 "ebxmlrr.repository.repositoryManagerClass"; 34 35 /*** 36 * The RepositoryManager implementation that handles querying the registry 37 * e.g. default FileSystemRepositoryManager 38 */ 39 private RepositoryManager repositoryManager = null; 40 41 /*** Factory class instance*/ 42 private static RepositoryManagerFactory instance = null; 43 44 45 private org.apache.commons.logging.Log log = 46 LogFactory.getLog(this.getClass()); 47 48 /*** 49 * Constructor. 50 */ 51 protected RepositoryManagerFactory() { 52 } 53 54 /*** 55 * Factory method that instantiates the Singleton 56 * concrete RepositoryManager instance. 57 */ 58 private RepositoryManager createRepositoryManager() throws Exception 59 { 60 RepositoryManager repMgr = null; 61 62 String repositoryManagerClass = 63 RegistryProperties.getInstance().getProperty(REPOSITORY_MANAGER_CLASS_PROPERTY); 64 65 log.debug("repositoryManagerClass = " + repositoryManagerClass); 66 67 Class theClass = Class.forName(repositoryManagerClass); 68 69 //try to invoke constructor using Reflection, 70 //if this fails then try invoking getInstance() 71 try { 72 Constructor constructor = theClass.getConstructor(null); 73 repMgr = (RepositoryManager)constructor.newInstance(new Object[0]); 74 } catch(Exception e) { 75 log.warn("No accessible constructor. " 76 + "invoking getInstance() instead."); 77 Method factory = theClass.getDeclaredMethod("getInstance", null); 78 repMgr = (RepositoryManager)factory.invoke(null, new Object[0]); 79 } 80 81 return repMgr; 82 } 83 84 /*** 85 * Returns the concrete RepositoryManager Singleton instance. 86 */ 87 public RepositoryManager getRepositoryManager() { 88 if(repositoryManager == null) { 89 synchronized(RepositoryManagerFactory.class) { 90 if(repositoryManager == null) { 91 try { 92 repositoryManager = createRepositoryManager(); 93 } catch(Exception e) { 94 String errmsg = "[RepositoryManagerFactory] Cannot instantiate " + 95 "concrete RepositoryManager. Please check that " + 96 "property '" + REPOSITORY_MANAGER_CLASS_PROPERTY + 97 "' is correctly set in ebxmlrr.properties file."; 98 log.error(errmsg, e); 99 } 100 } 101 } 102 } 103 104 return repositoryManager; 105 } 106 107 /*** 108 * Singleton instance accessor. 109 */ 110 public static RepositoryManagerFactory getInstance() { 111 if(instance == null) { 112 synchronized(RepositoryManagerFactory.class) { 113 if(instance == null) { 114 instance = new RepositoryManagerFactory(); 115 } 116 } 117 } 118 return instance; 119 } 120 121 122 }

This page was automatically generated by Maven