1 package org.apache.ojb.broker.metadata.fieldaccess; 2 3 17 18 import org.apache.commons.beanutils.DynaBean; 19 import org.apache.ojb.broker.PersistenceBrokerException; 20 import org.apache.ojb.broker.util.logging.Logger; 21 import org.apache.ojb.broker.util.logging.LoggerFactory; 22 23 33 public class PersistentFieldDynaBeanAccessImpl extends AbstractPersistentField 34 { 35 private static final long serialVersionUID = 4728858060905429509L; 36 public PersistentFieldDynaBeanAccessImpl() 37 { 38 super(); 39 } 40 41 public PersistentFieldDynaBeanAccessImpl(Class aPropertyType, String aPropertyName) 42 { 43 super(aPropertyType, aPropertyName); 44 } 45 46 49 public void doSet(Object anObject, Object aValue) throws PersistenceBrokerException 50 { 51 if (anObject instanceof DynaBean) 52 { 53 DynaBean dynaBean = (DynaBean) anObject; 54 try 55 { 56 dynaBean.set(getName(), aValue); 57 } 58 catch (Throwable t) 59 { 60 String msg = dynaBean.getClass().getName(); 61 logSetProblem(anObject, aValue, msg); 62 throw new PersistenceBrokerException(t); 63 } 64 } 65 else 66 { 67 String msg = "the object is not a DynaBean"; 68 logSetProblem(anObject, aValue, msg); 69 throw new PersistenceBrokerException(msg); 70 } 71 } 72 73 76 public Object doGet(Object anObject) throws PersistenceBrokerException 77 { 78 if (anObject instanceof DynaBean) 79 { 80 DynaBean dynaBean = (DynaBean) anObject; 81 try 82 { 83 return dynaBean.get(getName()); 84 } 85 catch (Throwable t) 86 { 87 String msg = dynaBean.getClass().getName(); 88 logGetProblem(anObject, msg); 89 throw new PersistenceBrokerException(t); 90 } 91 } 92 else 93 { 94 String msg = "the object is not a DynaBean"; 95 logGetProblem(anObject, msg); 96 throw new PersistenceBrokerException(msg); 97 } 98 } 99 100 104 public String getName() 105 { 106 return this.fieldName; 107 } 108 public Class getType() 109 { 110 return this.rootObjectType; 111 } 112 public Class getDeclaringClass() 113 { 114 return DynaBean.class; 115 } 116 117 public boolean makeAccessible() 118 { 119 return false; 120 } 121 122 public boolean usesAccessorsAndMutators() 123 { 124 return false; 125 } 126 127 public String toString() 128 { 129 return "DynaBean." + getName() + ": " + super.toString(); 130 } 131 132 135 protected void logSetProblem(Object anObject, Object aValue, String msg) 136 { 137 Logger logger = LoggerFactory.getDefaultLogger(); 138 logger.error("Error in operation [set] of object [" + this.getClass().getName() + "], " + msg); 139 logger.error("Property Name [" + getName() + "]"); 140 if (anObject instanceof DynaBean) 141 { 142 DynaBean dynaBean = (DynaBean) anObject; 143 logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() + "]"); 144 } 145 else if (anObject != null) 146 { 147 logger.error("anObject was class [" + anObject.getClass().getName() + "]"); 148 } 149 else 150 { 151 logger.error("anObject was null"); 152 } 153 if (aValue != null) 154 logger.error("aValue was class [" + aValue.getClass().getName() + "]"); 155 else 156 logger.error("aValue was null"); 157 } 158 159 162 protected void logGetProblem(Object anObject, String msg) 163 { 164 Logger logger = LoggerFactory.getDefaultLogger(); 165 logger.error("Error in operation [get of object [" + this.getClass().getName() + "], " + msg); 166 logger.error("Property Name [" + getName() + "]"); 167 if (anObject instanceof DynaBean) 168 { 169 DynaBean dynaBean = (DynaBean) anObject; 170 logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() + "]"); 171 } 172 else if (anObject != null) 173 { 174 logger.error("anObject was class [" + anObject.getClass().getName() + "]"); 175 } 176 else 177 { 178 logger.error("anObject was null"); 179 } 180 } 181 } 182 | Popular Tags |