1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.caleigo.core.meta;
19
20 import org.caleigo.core.*;
21 import org.caleigo.toolkit.log.*;
22
23
24 /*** MetaEntityRelationEntiy is the entity class for MetaEntityRelation objects.
25 *
26 * @author dennis
27 * @version 1.0.0
28 *//*
29 * WHEN WHO WHY & WHAT
30 * ------------------------------------------------------------------------------
31 * 030627 dennis Creation
32 */
33 public class MetaEntityRelationEntity extends AbstractMetaEntity
34 {
35
36
37 /*** Default constructor for MetaEntityRelationEntity.
38 */
39 public MetaEntityRelationEntity()
40 {
41 }
42
43 /*** Copy constructor for MetaEntityRelationEntity.
44 */
45 public MetaEntityRelationEntity(MetaEntityRelationEntity entity)
46 {
47 this.copyData(entity);
48 this.clearAllDirtyFlags();
49 }
50
51 /*** This constructor creates a new MetaEntityRelationEntity and loads
52 * it with data from the data source using the entity's identity data.
53 */
54 public MetaEntityRelationEntity(String aSourceName)
55 {
56 super(Qualifier.create(MetaEntityRelation.SourceName, new String(aSourceName)));
57 }
58
59
60 /*** This constructor creates a new MetaEntityRelationEntity and loads
61 * it with data from the data source using the provided identity qualifier.
62 */
63 public MetaEntityRelationEntity(Qualifier identityQualifier)
64 {
65 super(identityQualifier);
66 }
67
68
69 public IEntityDescriptor getEntityDescriptor()
70 {
71 return MetaEntityRelation.instance;
72 }
73
74 protected void doOnDataChange(IFieldDescriptor fieldDescriptor, Object oldValue, Object newValue)
75 {
76
77 if(fieldDescriptor==MetaEntityRelation.ReferenceEntity && oldValue==null && this.isDataNull(MetaEntityRelation.ReverseName))
78 {
79 MetaEntityDescriptorEntity entity = MetaEntityDescriptor.load(newValue.toString());
80 if(entity!=null)
81 this.setData(MetaEntityRelation.ReverseName, entity.getDisplayName());
82 }
83 if(fieldDescriptor==MetaEntityRelation.TargetEntity && oldValue==null && this.isDataNull(MetaEntityRelation.ForwardName))
84 {
85 MetaEntityDescriptorEntity entity = MetaEntityDescriptor.load(newValue.toString());
86 if(entity!=null)
87 this.setData(MetaEntityRelation.ForwardName, entity.getDisplayName());
88 }
89
90
91 if(fieldDescriptor==MetaEntityRelation.ReferenceEntity && oldValue==null && !this.isDataNull(MetaEntityRelation.TargetEntity)
92 || fieldDescriptor==MetaEntityRelation.TargetEntity && oldValue==null && !this.isDataNull(MetaEntityRelation.ReferenceEntity))
93 {
94 try
95 {
96 IEntity refEntity = MetaEntityDescriptor.load((String)this.getData(MetaEntityRelation.ReferenceEntity));
97 IEntity tgtEntity = MetaEntityDescriptor.load((String)this.getData(MetaEntityRelation.TargetEntity));
98 String compositeName = (String)refEntity.getData(MetaEntityDescriptor.CodeName)+(String)tgtEntity.getData(MetaEntityDescriptor.CodeName);
99
100 if(this.isDataNull(MetaEntityRelation.CodeName))
101 this.setData(MetaEntityRelation.CodeName, compositeName);
102 if(this.isDataNull(MetaEntityRelation.SourceName))
103 this.setData(MetaEntityRelation.SourceName, compositeName);
104 }
105 catch(Exception e)
106 {
107 Log.printWarning(this, "Failed to calculate entity relation code and source name: "+e.getClass().getName());
108 }
109 }
110 }
111
112
113 public String getSourceName() {return (String)this.getData(MetaEntityRelation.SourceName);}
114 public String getCodeName() {return (String)this.getData(MetaEntityRelation.CodeName);}
115 public String getForwardName() {return (String)this.getData(MetaEntityRelation.ForwardName);}
116 public String getReverseName() {return (String)this.getData(MetaEntityRelation.ReverseName);}
117 public String getReferenceEntity() {return (String)this.getData(MetaEntityRelation.ReferenceEntity);}
118 public String getTargetEntity() {return (String)this.getData(MetaEntityRelation.TargetEntity);}
119
120 public void setSourceName(String value) {this.setData(MetaEntityRelation.SourceName, value);}
121 public void setCodeName(String value) {this.setData(MetaEntityRelation.CodeName, value);}
122 public void setForwardName(String value) {this.setData(MetaEntityRelation.ForwardName, value);}
123 public void setReverseName(String value) {this.setData(MetaEntityRelation.ReverseName, value);}
124 public void setReferenceEntity(String value) {this.setData(MetaEntityRelation.ReferenceEntity, value);}
125 public void setTargetEntity(String value) {this.setData(MetaEntityRelation.TargetEntity, value);}
126
127 public Object getSourceNameData() {return this.getData(MetaEntityRelation.SourceName);}
128 public Object getCodeNameData() {return this.getData(MetaEntityRelation.CodeName);}
129 public Object getForwardNameData() {return this.getData(MetaEntityRelation.ForwardName);}
130 public Object getReverseNameData() {return this.getData(MetaEntityRelation.ReverseName);}
131 public Object getReferenceEntityData() {return this.getData(MetaEntityRelation.ReferenceEntity);}
132 public Object getTargetEntityData() {return this.getData(MetaEntityRelation.TargetEntity);}
133
134 public void setSourceNameData(Object value) {this.setData(MetaEntityRelation.SourceName, value);}
135 public void setCodeNameData(Object value) {this.setData(MetaEntityRelation.CodeName, value);}
136 public void setForwardNameData(Object value) {this.setData(MetaEntityRelation.ForwardName, value);}
137 public void setReverseNameData(Object value) {this.setData(MetaEntityRelation.ReverseName, value);}
138 public void setReferenceEntityData(Object value) {this.setData(MetaEntityRelation.ReferenceEntity, value);}
139 public void setTargetEntityData(Object value) {this.setData(MetaEntityRelation.TargetEntity, value);}
140 }