| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package net.wotonomy.access; |
| 19 |
|
|
| 20 |
|
import net.wotonomy.foundation.NSDictionary; |
| 21 |
|
import net.wotonomy.foundation.NSMutableDictionary; |
| 22 |
|
import net.wotonomy.foundation.NSSelector; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
public class EOAttribute extends EOProperty implements EOPropertyListEncoding { |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
public static final int Void = 0; |
| 38 |
|
public static final int InParameter = 1; |
| 39 |
|
public static final int OutParameter = 2; |
| 40 |
|
public static final int InOutParameter = 3; |
| 41 |
|
|
| 42 |
|
protected EOEntity _entity; |
| 43 |
|
protected String _name; |
| 44 |
|
protected String _columnName; |
| 45 |
|
protected String _definition; |
| 46 |
|
protected String _className; |
| 47 |
|
protected String _externalType; |
| 48 |
|
protected Class _valueClass; |
| 49 |
|
protected String _valueClassName; |
| 50 |
|
protected String _valueType; |
| 51 |
|
protected String _valueFactoryMethodName; |
| 52 |
|
protected String _readFormat; |
| 53 |
|
protected String _writeFormat; |
| 54 |
|
protected String _prototypeName; |
| 55 |
|
protected EOAttribute _prototype; |
| 56 |
|
protected NSSelector _valueFactoryMethod; |
| 57 |
|
protected boolean _allowsNull; |
| 58 |
|
protected boolean _readOnly; |
| 59 |
|
protected boolean _isFlattened; |
| 60 |
|
protected boolean _knowsIfFlattened; |
| 61 |
|
protected int _precision; |
| 62 |
|
protected int _scale; |
| 63 |
|
protected int _width; |
| 64 |
|
protected int _parameterDirection; |
| 65 |
|
protected NSDictionary _internalInfo; |
| 66 |
|
protected NSDictionary _userInfo; |
| 67 |
|
|
| 68 |
|
protected boolean _has_allowsNull; |
| 69 |
|
|
| 70 |
|
public EOAttribute() { |
| 71 |
0 |
super(); |
| 72 |
0 |
_allowsNull = true; |
| 73 |
0 |
} |
| 74 |
|
|
| 75 |
|
public EOAttribute(NSDictionary dict, Object obj) { |
| 76 |
0 |
super(); |
| 77 |
0 |
if (obj instanceof EOEntity) |
| 78 |
0 |
_entity = (EOEntity)obj; |
| 79 |
0 |
setName((String)dict.objectForKey("name")); |
| 80 |
0 |
if (dict.objectForKey("columnName") != null) |
| 81 |
0 |
setColumnName((String)dict.objectForKey("columnName")); |
| 82 |
0 |
if (dict.objectForKey("definition") != null) |
| 83 |
0 |
setDefinition((String)dict.objectForKey("definition")); |
| 84 |
0 |
_prototypeName = (String)dict.objectForKey("prototypeName"); |
| 85 |
0 |
setExternalType((String)dict.objectForKey("externalType")); |
| 86 |
0 |
setClassName((String)dict.objectForKey("valueClassName")); |
| 87 |
0 |
setValueType((String)dict.objectForKey("valueType")); |
| 88 |
0 |
_writeFormat = (String)dict.objectForKey("writeFormat"); |
| 89 |
0 |
_readFormat = (String)dict.objectForKey("readFormat"); |
| 90 |
0 |
if (dict.objectForKey("precision") != null) |
| 91 |
0 |
setPrecision(Integer.parseInt((String)dict.objectForKey("precision"))); |
| 92 |
0 |
if (dict.objectForKey("scale") != null) |
| 93 |
0 |
setScale(Integer.parseInt((String)dict.objectForKey("scale"))); |
| 94 |
0 |
if (dict.objectForKey("width") != null) |
| 95 |
0 |
setWidth(Integer.parseInt((String)dict.objectForKey("width"))); |
| 96 |
0 |
if (dict.objectForKey("parameterDirection") != null) |
| 97 |
0 |
setParameterDirection(Integer.parseInt((String)dict.objectForKey("parameterDirection"))); |
| 98 |
0 |
setAllowsNull("Y".equals(dict.objectForKey("allowsNull"))); |
| 99 |
0 |
} |
| 100 |
|
|
| 101 |
|
void setEntity(EOEntity value) { |
| 102 |
0 |
_entity = value; |
| 103 |
0 |
} |
| 104 |
|
|
| 105 |
|
public void setName(String name) { |
| 106 |
0 |
_name = name; |
| 107 |
0 |
} |
| 108 |
|
public String name() { |
| 109 |
0 |
return _name; |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
public void setColumnName(String name) { |
| 113 |
0 |
_columnName = name; |
| 114 |
0 |
} |
| 115 |
|
public String columnName() { |
| 116 |
0 |
if (_columnName != null) |
| 117 |
0 |
return _columnName; |
| 118 |
0 |
if (prototype() != null) |
| 119 |
0 |
if (_prototype.columnName() != null) |
| 120 |
0 |
return _prototype.columnName(); |
| 121 |
0 |
return null; |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
public void setClassName(String name) { |
| 125 |
0 |
_className = name; |
| 126 |
0 |
} |
| 127 |
|
public String className() { |
| 128 |
0 |
if (_className != null) |
| 129 |
0 |
return _className; |
| 130 |
0 |
if (prototype() != null) |
| 131 |
0 |
if (_prototype.className() != null) |
| 132 |
0 |
return _prototype.className(); |
| 133 |
0 |
return null; |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
public void setDefinition(String def) { |
| 137 |
0 |
_definition = def; |
| 138 |
0 |
_columnName = null; |
| 139 |
0 |
} |
| 140 |
|
public String definition() { |
| 141 |
0 |
if (_definition != null) |
| 142 |
0 |
return _definition; |
| 143 |
0 |
if (prototype() != null) |
| 144 |
0 |
if (_prototype.definition() != null) |
| 145 |
0 |
return _prototype.definition(); |
| 146 |
0 |
return null; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
public void setExternalType(String type) { |
| 150 |
0 |
_externalType = type; |
| 151 |
0 |
} |
| 152 |
|
public String externalType() { |
| 153 |
0 |
if (_externalType != null) |
| 154 |
0 |
return _externalType; |
| 155 |
0 |
if (prototype() != null) |
| 156 |
0 |
if (_prototype.externalType() != null) |
| 157 |
0 |
return _prototype.externalType(); |
| 158 |
0 |
return null; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
public void setAllowsNull(boolean flag) { |
| 162 |
0 |
_allowsNull = flag; |
| 163 |
0 |
_has_allowsNull = true; |
| 164 |
0 |
} |
| 165 |
|
public boolean allowsNull() { |
| 166 |
0 |
if (_has_allowsNull) |
| 167 |
0 |
return _allowsNull; |
| 168 |
0 |
if (prototype() != null) |
| 169 |
0 |
return _prototype.allowsNull(); |
| 170 |
0 |
return _allowsNull; |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
public void setReadOnly(boolean flag) { |
| 174 |
0 |
_readOnly = flag; |
| 175 |
0 |
} |
| 176 |
|
public boolean readOnly() { |
| 177 |
0 |
return _readOnly; |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
public void setPrototype(EOAttribute proto) { |
| 181 |
0 |
_prototype = proto; |
| 182 |
0 |
if (proto != null) |
| 183 |
0 |
_prototypeName = proto.name(); |
| 184 |
|
else |
| 185 |
0 |
_prototypeName = null; |
| 186 |
0 |
} |
| 187 |
|
public EOAttribute prototype() { |
| 188 |
0 |
if (_prototypeName != null && _prototype == null) { |
| 189 |
|
try { |
| 190 |
0 |
EOModel m = _entity.model(); |
| 191 |
0 |
EOModelGroup g = m.modelGroup(); |
| 192 |
0 |
EOEntity protos = g.entityNamed("EO" + m.adaptorName() + "Prototypes"); |
| 193 |
0 |
if (protos == null) |
| 194 |
0 |
protos = g.entityNamed("EOPrototypes"); |
| 195 |
0 |
_prototype = protos.attributeNamed(_prototypeName); |
| 196 |
0 |
} catch (NullPointerException e) { |
| 197 |
0 |
} |
| 198 |
|
} |
| 199 |
0 |
return _prototype; |
| 200 |
|
} |
| 201 |
|
|
| 202 |
|
public void setPrecision(int value) { |
| 203 |
0 |
_precision = value; |
| 204 |
0 |
} |
| 205 |
|
public int precision() { |
| 206 |
0 |
if (_precision > 0) |
| 207 |
0 |
return _precision; |
| 208 |
0 |
if (prototype() != null) |
| 209 |
0 |
return _prototype.precision(); |
| 210 |
0 |
return _precision; |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
public void setScale(int value) { |
| 214 |
0 |
_scale = value; |
| 215 |
0 |
} |
| 216 |
|
public int scale() { |
| 217 |
0 |
if (_scale > 0) |
| 218 |
0 |
return _scale; |
| 219 |
0 |
if (prototype() != null) |
| 220 |
0 |
return _prototype.scale(); |
| 221 |
0 |
return _scale; |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
public void setWidth(int value) { |
| 225 |
0 |
_width = value; |
| 226 |
0 |
} |
| 227 |
|
public int width() { |
| 228 |
0 |
if (_width > 0) |
| 229 |
0 |
return _width; |
| 230 |
0 |
if (prototype() != null) |
| 231 |
0 |
return _prototype.width(); |
| 232 |
0 |
return _width; |
| 233 |
|
} |
| 234 |
|
|
| 235 |
|
|
| 236 |
|
public void setValueClassName(String name) { |
| 237 |
0 |
setClassName(name); |
| 238 |
0 |
} |
| 239 |
|
|
| 240 |
|
public String valueClassName() { |
| 241 |
0 |
return className(); |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
public void setValueType(String type) { |
| 245 |
0 |
_valueType = type; |
| 246 |
0 |
} |
| 247 |
|
public String valueType() { |
| 248 |
0 |
if (_valueType != null) |
| 249 |
0 |
return _valueType; |
| 250 |
0 |
if (prototype() != null) |
| 251 |
0 |
return _prototype.valueType(); |
| 252 |
0 |
return null; |
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
public void setReadFormat(String value) { |
| 256 |
0 |
_readFormat = value; |
| 257 |
0 |
} |
| 258 |
|
public String readFormat() { |
| 259 |
0 |
return _readFormat; |
| 260 |
|
} |
| 261 |
|
|
| 262 |
|
public void setWriteFormat(String value) { |
| 263 |
0 |
_writeFormat = value; |
| 264 |
0 |
} |
| 265 |
|
public String writeFormat() { |
| 266 |
0 |
return _writeFormat; |
| 267 |
|
} |
| 268 |
|
|
| 269 |
|
public boolean isDerived() { |
| 270 |
0 |
return (definition() != null); |
| 271 |
|
} |
| 272 |
|
|
| 273 |
|
|
| 274 |
|
|
| 275 |
|
|
| 276 |
|
|
| 277 |
|
|
| 278 |
|
public boolean isFlattened() { |
| 279 |
0 |
if (_knowsIfFlattened) |
| 280 |
0 |
return _isFlattened; |
| 281 |
0 |
_knowsIfFlattened = true; |
| 282 |
0 |
if (definition() == null) |
| 283 |
0 |
return false; |
| 284 |
0 |
_isFlattened = (entity()._attributeForPath(definition()) != null); |
| 285 |
0 |
return _isFlattened; |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
public EOEntity entity() { |
| 289 |
0 |
return _entity; |
| 290 |
|
} |
| 291 |
|
|
| 292 |
|
public void setParameterDirection(int dir) { |
| 293 |
0 |
_parameterDirection = dir; |
| 294 |
0 |
} |
| 295 |
|
public int parameterDirection() { |
| 296 |
0 |
return _parameterDirection; |
| 297 |
|
} |
| 298 |
|
|
| 299 |
|
public String relationshipPath() { |
| 300 |
0 |
if (isFlattened()) |
| 301 |
0 |
return definition(); |
| 302 |
0 |
return null; |
| 303 |
|
} |
| 304 |
|
|
| 305 |
|
public void setUserInfo(NSDictionary value) { |
| 306 |
0 |
_userInfo = value; |
| 307 |
0 |
} |
| 308 |
|
public NSDictionary userInfo() { |
| 309 |
0 |
return _userInfo; |
| 310 |
|
} |
| 311 |
|
|
| 312 |
|
public void awakeWithPropertyList(NSDictionary plist) { |
| 313 |
0 |
} |
| 314 |
|
|
| 315 |
|
public void encodeIntoPropertyList(NSMutableDictionary dict) { |
| 316 |
0 |
dict.setObjectForKey(name(), "name"); |
| 317 |
0 |
if (_prototypeName != null) |
| 318 |
0 |
dict.setObjectForKey(_prototypeName, "prototypeName"); |
| 319 |
0 |
if (_columnName != null) |
| 320 |
0 |
dict.setObjectForKey(_columnName, "columnName"); |
| 321 |
0 |
if (_definition != null) |
| 322 |
0 |
dict.setObjectForKey(_definition, "definition"); |
| 323 |
0 |
if (_className != null) |
| 324 |
0 |
dict.setObjectForKey(_className, "valueClassName"); |
| 325 |
0 |
if (_valueType != null) |
| 326 |
0 |
dict.setObjectForKey(_valueType, "valueType"); |
| 327 |
0 |
if (_precision > 0) |
| 328 |
0 |
dict.setObjectForKey(new Integer(_precision), "precision"); |
| 329 |
0 |
if (_scale > 0) |
| 330 |
0 |
dict.setObjectForKey(new Integer(_scale), "scale"); |
| 331 |
0 |
if (_width > 0) |
| 332 |
0 |
dict.setObjectForKey(new Integer(_width), "width"); |
| 333 |
0 |
if (_externalType != null) |
| 334 |
0 |
dict.setObjectForKey(_externalType, "externalType"); |
| 335 |
0 |
if (_readFormat != null) |
| 336 |
0 |
dict.setObjectForKey(_readFormat, "readFormat"); |
| 337 |
0 |
if (_writeFormat != null) |
| 338 |
0 |
dict.setObjectForKey(_writeFormat, "writeFormat"); |
| 339 |
0 |
if (_allowsNull) |
| 340 |
0 |
dict.setObjectForKey("Y", "allowsNull"); |
| 341 |
0 |
if (_entity == null) |
| 342 |
0 |
dict.setObjectForKey(new Integer(parameterDirection()), "parameterDirection"); |
| 343 |
0 |
if (userInfo() != null && userInfo().count() > 0) |
| 344 |
0 |
dict.setObjectForKey(userInfo(), "userInfo"); |
| 345 |
0 |
if (_internalInfo != null && _internalInfo.count() > 0) |
| 346 |
0 |
dict.setObjectForKey(_internalInfo, "internalInfo"); |
| 347 |
0 |
} |
| 348 |
|
|
| 349 |
|
} |
| 350 |
|
|
| 351 |
|
|
| 352 |
|
|
| 353 |
|
|
| 354 |
|
|
| 355 |
|
|
| 356 |
|
|
| 357 |
|
|
| 358 |
|
|
| 359 |
|
|
| 360 |
|
|
| 361 |
|
|
| 362 |
|
|
| 363 |
|
|
| 364 |
|
|
| 365 |
|
|
| 366 |
|
|
| 367 |
|
|
| 368 |
|
|
| 369 |
|
|
| 370 |
|
|
| 371 |
|
|
| 372 |
|
|
| 373 |
|
|
| 374 |
|
|
| 375 |
|
|
| 376 |
|
|
| 377 |
|
|
| 378 |
|
|
| 379 |
|
|
| 380 |
|
|
| 381 |
|
|