1 package org.weda.property.impl;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.Collections;
6 import java.util.HashMap;
7 import java.util.LinkedList;
8 import java.util.List;
9 import java.util.Map;
10 import org.weda.enhance.InjectInplaceMessage;
11 import org.weda.message.Messages;
12 import org.weda.message.impl.InplaceMessage;
13 import org.weda.property.PosibleValue;
14 import org.weda.property.PropertyDescriptor;
15 import org.weda.property.PropertyDescriptorException;
16 import org.weda.property.ConstraintException;
17 import org.weda.property.Constraint;
18
19 /**Цель: хранение информации о свойстве
20 *
21 * @author tim
22 */
23 public class PropertyDescriptorImpl
24 implements PropertyDescriptor, Serializable
25 {
26 @InjectInplaceMessage private String displayName;
27 @InjectInplaceMessage private String pattern;
28
29 private Class objectClass;
30 private String name;
31 private Class propertyClass;
32 private PropertyDescriptor parent;
33 private String mimeType;
34 private List<Constraint> constraints;
35
36 public void init() throws PropertyDescriptorException {
37 }
38
39 public void check(Object value) throws ConstraintException {
40 List<Constraint> list = getConstraints();
41 if (list!=null)
42 for (Constraint constraint: list)
43 constraint.check(value, null);
44 }
45
46 public String getDisplayName() {
47 String res =
48 displayName==null && parent!=null ?
49 parent.getDisplayName() : displayName;
50 if (res==null)
51 res=getName();
52 return res;
53 }
54
55 public void setDisplayName(String displayName) {
56 this.displayName = displayName;
57 }
58
59 public String getName() {
60 return name==null && parent!=null ? parent.getName() : name;
61 }
62
63 public void setName(String name) {
64 this.name = name;
65 }
66
67 public Class getPropertyClass() {
68 return propertyClass==null && parent!=null
69 ? parent.getPropertyClass() : propertyClass;
70 }
71
72 public void setPropertyClass(Class propertyClass) {
73 this.propertyClass = propertyClass;
74 }
75
76 public PropertyDescriptor getParent() {
77 return parent;
78 }
79
80 public void setParent(PropertyDescriptor parent) {
81 this.parent = parent;
82 }
83
84 public boolean equals(Object val){
85 if (!(val instanceof PropertyDescriptor))
86 return false;
87 PropertyDescriptor desc = (PropertyDescriptor)val;
88 while (desc.getParent()!=null)
89 desc=desc.getParent();
90 PropertyDescriptor thisRoot=this;
91 while (thisRoot.getParent()!=null)
92 thisRoot=thisRoot.getParent();
93 if (desc==thisRoot)
94 return true;
95 return false;
96 }
97
98 public boolean hasDisplayName() {
99 return displayName!=null || (parent!=null && parent.hasDisplayName());
100 }
101
102 public String getPattern() {
103 return pattern == null && parent !=null?
104 parent.getPattern() : pattern;
105 }
106
107 public void setPattern(String pattern) {
108 this.pattern = pattern;
109 }
110
111 public String getMimeType() {
112 String res =
113 mimeType==null && parent!=null ? parent.getMimeType() : mimeType;
114 return res==null ? OBJECT_PROPERTY_MIME_TYPE : res;
115 }
116
117 public void setMimeType(String mimeType) {
118 this.mimeType = mimeType;
119 }
120
121 public Class getObjectClass() {
122 return objectClass==null && parent!=null
123 ? parent.getObjectClass() : objectClass;
124 }
125
126 public void setObjectClass(Class objectClass) {
127 this.objectClass = objectClass;
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158 public List<Constraint> getConstraints() {
159 return constraints == null &&
160 parent != null ? parent.getConstraints() : constraints;
161 }
162
163
164
165
166
167 public void addConstraint(Constraint constraint){
168 if (constraints == null)
169 constraints = new ArrayList(3);
170 constraints.add(constraint);
171 }
172 }