1 29 30 package com.caucho.ejb.cfg; 31 32 import com.caucho.amber.field.AmberField; 33 import com.caucho.amber.type.EntityType; 34 import com.caucho.bytecode.JClass; 35 import com.caucho.bytecode.JMethod; 36 import com.caucho.config.ConfigException; 37 import com.caucho.ejb.gen.EntityBean; 38 import com.caucho.java.JavaWriter; 39 import com.caucho.util.L10N; 40 41 import javax.ejb.EJBLocalObject ; 42 import java.io.IOException ; 43 import java.util.Collection ; 44 import java.util.Map ; 45 46 49 public class CmrRelation extends CmpProperty { 50 private static final L10N L = new L10N(CmrRelation.class); 51 52 private String _relationName; 53 54 private String _fieldName; 55 private boolean _hasGetter; 56 57 private CmrRelation _targetRelation; 58 59 62 public CmrRelation(EjbEntityBean entityBean) 63 throws ConfigException 64 { 65 super(entityBean); 66 } 67 68 71 public CmrRelation(EjbEntityBean entityBean, String fieldName) 72 throws ConfigException 73 { 74 super(entityBean); 75 76 setFieldName(fieldName); 77 78 JMethod getter = getGetter(); 79 80 if (! getter.isAbstract() && ! entityBean.isAllowPOJO()) 81 throw new ConfigException(L.l("{0}: '{1}' must have an abstract getter method. cmr-relations must have abstract getter methods returning a local interface.", 82 entityBean.getEJBClass().getName(), 83 getter.getFullName())); 84 85 JClass retType = getter.getReturnType(); 86 87 if (! retType.isAssignableTo(EJBLocalObject .class) && 88 ! retType.isAssignableTo(Collection .class) && 89 ! retType.isAssignableTo(Map .class)) { 90 throw new ConfigException(L.l("{0}: '{1}' must return an EJBLocalObject or a Collection. cmr-relations must have abstract getter methods returning a local interface.", 91 entityBean.getEJBClass().getName(), 92 getter.getFullName())); 93 } 94 95 JMethod setter = getSetter(); 96 97 if (setter == null) 98 return; 99 100 JClass []paramTypes = setter.getParameterTypes(); 101 102 if (! retType.equals(paramTypes[0])) 103 throw new ConfigException(L.l("{0}: '{1}' must return an '{2}'. Persistent setters must match the getter types .", 104 entityBean.getEJBClass().getName(), 105 setter.getFullName(), 106 retType.getName())); 107 } 108 109 112 public String getRelationName() 113 { 114 return _relationName; 115 } 116 117 120 public void setRelationName(String name) 121 { 122 _relationName = name; 123 } 124 125 128 public EjbEntityBean getTargetBean() 129 { 130 return null; 131 } 132 133 136 public JClass getTargetType() 137 { 138 throw new UnsupportedOperationException (getClass().getName()); 139 } 140 141 144 public void setTarget(CmrRelation target) 145 { 146 throw new UnsupportedOperationException (getClass().getName()); 147 } 148 149 152 public boolean isCollection() 153 { 154 return false; 155 } 156 157 160 public void setTargetRelation(CmrRelation target) 161 { 162 _targetRelation = target; 163 } 164 165 168 public CmrRelation getTargetRelation() 169 { 170 return _targetRelation; 171 } 172 173 176 public void linkAmber() 177 throws ConfigException 178 { 179 } 180 181 184 public void assemble(EntityBean bean) 185 { 186 187 } 188 189 192 public void setHasGetter(boolean hasGetter) 193 { 194 _hasGetter = true; 195 } 196 197 200 public boolean getHasGetter() 201 { 202 return _hasGetter; 203 } 204 205 208 public EjbMethod createGetter(EjbView view, 209 JMethod apiMethod, 210 JMethod implMethod) 211 throws ConfigException 212 { 213 return new CmpGetter(view, apiMethod, implMethod); 214 } 215 216 219 public AmberField assembleAmber(EntityType type) 220 throws ConfigException 221 { 222 throw new UnsupportedOperationException (getClass().getName()); 223 } 224 225 228 public void generateAfterCommit(JavaWriter out) 229 throws IOException 230 { 231 } 232 233 236 public void generateDestroy(JavaWriter out) 237 throws IOException 238 { 239 } 240 241 public String toString() 242 { 243 return "CmrRelation[" + getName() + "]"; 244 } 245 } 246 | Popular Tags |