Wiki source code of JBND Client-Side _Entity.java Template
Last modified by Florijan Stamenkovic on 2009/03/27 13:30
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | This template requires the [[JBND>>url:http://web.mac.com/flor385/JBND||shape="rect"]] library or source code be included on the Client-Side of the application. NSArray is not parameterized so if you want to use it with 5.4, slight modifications might be beneficial. | ||
2 | |||
3 | {{code}} | ||
4 | |||
5 | // <$GEN_PREFIX$><$classNameWithoutPackage$>.java | ||
6 | // | ||
7 | // Created by eogenerator | ||
8 | // | ||
9 | // DO NOT EDIT. Make changes to <$classNameWithoutPackage$>.java instead. | ||
10 | // | ||
11 | // This EO was generated to perform standard JBND behaviors | ||
12 | // 1. All setter methods will not set new values if they are identical to old values. | ||
13 | // 2. All setter methods invoke EOFDataObject.fireDataObjectEvent(String key, Object oldValue). | ||
14 | // 3. All attribute and relationship keys are stored as static final Strings. | ||
15 | // 4. A default constructor is provided to automatically call the superclass constructor | ||
16 | // that accepts an EOClassDescription argument, used to avoid bugs in the client side EOF. | ||
17 | |||
18 | #if ($entity.superclassPackageName) | ||
19 | package $entity.superclassPackageName; | ||
20 | #end | ||
21 | |||
22 | import com.webobjects.foundation.*; | ||
23 | import com.webobjects.eocontrol.*; | ||
24 | import java.math.BigDecimal; | ||
25 | import java.util.*; | ||
26 | import org.jbnd.support.JBNDUtil; | ||
27 | import org.jbnd.eof.EOFDataObject; | ||
28 | import org.jbnd.event.DataObjectEvent; | ||
29 | import org.jbnd.event.DataObjectEvent.Type; | ||
30 | |||
31 | /** | ||
32 | * DO NOT EDIT! | ||
33 | */ | ||
34 | @SuppressWarnings("all") | ||
35 | public abstract class ${entity.prefixClassNameWithoutPackage} extends #if ($entity.parentSet)${entity.parent.classNameWithDefault}#elseif ($EOGenericRecord)${EOGenericRecord}#else EOFDataObject#end { | ||
36 | |||
37 | /** Entity name */ | ||
38 | public static final String ENTITY_NAME = "$entity.name"; | ||
39 | |||
40 | /** Attribute keys */ | ||
41 | #foreach ($attribute in $entity.sortedClientClassAttributes) | ||
42 | public static final String ${attribute.uppercaseUnderscoreName}_KEY = "$attribute.name"; | ||
43 | #end | ||
44 | |||
45 | /** Relationship keys */ | ||
46 | #foreach ($relationship in $entity.sortedClientClassRelationships) | ||
47 | public static final String ${relationship.uppercaseUnderscoreName}_KEY = "$relationship.name"; | ||
48 | #end | ||
49 | |||
50 | /** | ||
51 | * Constructor. Creates an EO with the <tt>EOClassDescription</tt> of the | ||
52 | * relevant entity, to ensure a proper client side behavior. | ||
53 | */ | ||
54 | public ${entity.prefixClassNameWithoutPackage}() { | ||
55 | super(EOClassDescription.classDescriptionForEntityName("$entity.name")); | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * Constructor used in inheritance situations, when this entity is the parent. | ||
60 | * | ||
61 | * @param cd The class description of the sub-entity. | ||
62 | */ | ||
63 | protected ${entity.prefixClassNameWithoutPackage}(EOClassDescription cd) { | ||
64 | super(cd); | ||
65 | } | ||
66 | |||
67 | #foreach ($attribute in $entity.sortedClientClassAttributes) | ||
68 | #if (!$attribute.inherited) | ||
69 | public $attribute.javaClassName ${attribute.name}() { | ||
70 | return ($attribute.javaClassName)storedValueForKey(${attribute.uppercaseUnderscoreName}_KEY); | ||
71 | } | ||
72 | |||
73 | public void set${attribute.capitalizedName}($attribute.javaClassName aValue) { | ||
74 | // extract old value | ||
75 | $attribute.javaClassName oldValue = ${attribute.name}(); | ||
76 | |||
77 | // do not perform EOF work unless values are different | ||
78 | if(JBNDUtil.equals(oldValue, aValue)) return; | ||
79 | |||
80 | takeStoredValueForKey(aValue, ${attribute.uppercaseUnderscoreName}_KEY); | ||
81 | fireDataObjectEvent(${attribute.uppercaseUnderscoreName}_KEY, oldValue, DataObjectEvent.Type.ATTRIBUTE_CHANGE); | ||
82 | } | ||
83 | #end | ||
84 | #end | ||
85 | |||
86 | #foreach ($relationship in $entity.sortedClientClassToOneRelationships) | ||
87 | #if (!$relationship.inherited) | ||
88 | public $relationship.actualDestination.classNameWithDefault ${relationship.name}() { | ||
89 | return ($relationship.actualDestination.classNameWithDefault)storedValueForKey(${relationship.uppercaseUnderscoreName}_KEY); | ||
90 | } | ||
91 | |||
92 | public void set${relationship.capitalizedName}($relationship.actualDestination.classNameWithDefault aValue) { | ||
93 | // get old value | ||
94 | $relationship.actualDestination.classNameWithDefault oldValue = ${relationship.name}(); | ||
95 | |||
96 | // do not perform EOF work unless values are different | ||
97 | if(JBNDUtil.equals(oldValue, aValue)) return; | ||
98 | |||
99 | takeStoredValueForKey(aValue, ${relationship.uppercaseUnderscoreName}_KEY); | ||
100 | fireDataObjectEvent(${relationship.uppercaseUnderscoreName}_KEY, oldValue, DataObjectEvent.Type.TO_ONE_CHANGE); | ||
101 | } | ||
102 | #end | ||
103 | #end | ||
104 | |||
105 | #foreach ($relationship in $entity.sortedClientClassToManyRelationships) | ||
106 | #if (!$relationship.inherited) | ||
107 | public NSArray<${relationship.actualDestination.classNameWithDefault}> ${relationship.name}() { | ||
108 | return (NSArray<${relationship.actualDestination.classNameWithDefault}>)storedValueForKey(${relationship.uppercaseUnderscoreName}_KEY); | ||
109 | } | ||
110 | |||
111 | public void set${relationship.capitalizedName}(NSArray<${relationship.actualDestination.classNameWithDefault}> aValue) { | ||
112 | Object oldValue = ${relationship.name}().clone(); | ||
113 | takeStoredValueForKey(aValue, ${relationship.uppercaseUnderscoreName}_KEY); | ||
114 | fireDataObjectEvent(${relationship.uppercaseUnderscoreName}_KEY, oldValue, DataObjectEvent.Type.TO_MANY_CHANGE); | ||
115 | } | ||
116 | |||
117 | public void addTo${relationship.capitalizedName}(${relationship.actualDestination.classNameWithDefault} object) { | ||
118 | if(${relationship.name}().contains(object)) return; | ||
119 | includeObjectIntoPropertyWithKey(object, ${relationship.uppercaseUnderscoreName}_KEY); | ||
120 | fireDataObjectEvent(${relationship.uppercaseUnderscoreName}_KEY, object, DataObjectEvent.Type.TO_MANY_ADD); | ||
121 | } | ||
122 | |||
123 | public void removeFrom${relationship.capitalizedName}(${relationship.actualDestination.classNameWithDefault} object) { | ||
124 | if(!${relationship.name}().contains(object)) return; | ||
125 | excludeObjectFromPropertyWithKey(object, ${relationship.uppercaseUnderscoreName}_KEY); | ||
126 | fireDataObjectEvent(${relationship.uppercaseUnderscoreName}_KEY, object, DataObjectEvent.Type.TO_MANY_REMOVE); | ||
127 | } | ||
128 | #end | ||
129 | #end | ||
130 | } | ||
131 | |||
132 | {{/code}} |