1 package org.apache.ojb.broker.metadata.fieldaccess; 2 3 17 18 import org.apache.ojb.broker.core.PersistenceBrokerConfiguration; 19 import org.apache.ojb.broker.metadata.MetadataException; 20 import org.apache.ojb.broker.util.ClassHelper; 21 import org.apache.ojb.broker.util.configuration.ConfigurationException; 22 import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator; 23 import org.apache.ojb.broker.util.logging.Logger; 24 import org.apache.ojb.broker.util.logging.LoggerFactory; 25 26 30 31 public class PersistentFieldFactory 32 { 33 private static Logger log = LoggerFactory.getLogger(PersistentFieldFactory.class); 34 private static final Class DEFAULT_PERSISTENT_FIELD_IMPL = PersistentFieldDirectImpl.class; 35 private static final Class [] METHOD_PARAMETER_TYPES = {Class .class, String .class}; 36 37 40 43 public static PersistentField createPersistentField(Class attributeType, String attributeName) 44 { 45 return createPersistentField(null,attributeType,attributeName); 46 } 47 48 public static PersistentField createPersistentField(String persistentFieldClassName, Class attributeType, String attributeName) 49 { 50 try 51 { 52 if (persistentFieldClassName == null) 53 { 54 synchronized (PersistentFieldFactory.class) 55 { 56 persistentFieldClassName = getDefaultPersistentFieldClassName(); 57 } 58 } 59 Object [] args = {attributeType, attributeName}; 60 return (PersistentField) ClassHelper.newInstance(persistentFieldClassName, METHOD_PARAMETER_TYPES, args); 61 62 } 63 catch (Exception ex) 64 { 65 throw new MetadataException("Error creating PersistentField: " + 66 attributeType.getName() + ", " + attributeName, ex); 67 } 68 } 69 70 97 private static String getDefaultPersistentFieldClassName() 98 { 99 try 100 { 101 PersistenceBrokerConfiguration config = 102 (PersistenceBrokerConfiguration) OjbConfigurator.getInstance().getConfigurationFor( 103 null); 104 105 Class clazz = config.getPersistentFieldClass(); 106 return clazz.getName(); 107 } 108 catch (ConfigurationException e) 109 { 110 log.error("Cannot look-up PersistentField class, use default implementation instead", e); 111 return DEFAULT_PERSISTENT_FIELD_IMPL.getName(); 112 } 113 } 114 115 } 116 | Popular Tags |