1 package org.weda.model.impl;
2
3 import org.weda.property.ConstraintException;
4 import org.weda.property.PropertyDescriptor;
5 import org.weda.model.EditorModel;
6 import org.weda.model.EditorModelException;
7 import org.weda.model.EditorModelGroupException;
8 import org.weda.store.impl.ObjectSet;
9 import org.weda.store.impl.ObjectSetException;
10 import org.weda.property.impl.PropertyDescriptorImpl;
11
12 /**
13 *
14 * @author Mikhail Titov
15 */
16 public class ObjectSetEditorModel<T extends ObjectSetEditorModelGroup>
17 extends AbstractEditorModel<T>
18 {
19 private String propertyPath;
20
21 public ObjectSetEditorModel(){
22 setNeedConversion(true);
23 }
24
25 public ObjectSet getObjectSet() throws EditorModelGroupException {
26 return getModelGroup().getObjectSet();
27 }
28
29 public String getPropertyPath(){
30 return propertyPath == null ? getName() : propertyPath;
31 }
32
33 public void setPropertyPath(String propertyPath) {
34 this.propertyPath=propertyPath;
35 }
36
37 public void setValue(Object value) throws Exception {
38 getPropertyDescriptor().check(value);
39 try{
40 activateDetailConstraints(value);
41 getObjectSet().setValue(getPropertyPath(), value);
42 }catch(Exception e){
43 throw new EditorModelException (
44 String.format(
45 "Can't set value for editor model (%s) in editor group (%s)"
46 , getName(), getModelGroup().getName())
47 , e);
48 }
49 }
50
51 public Object getValue() throws EditorModelException {
52 try{
53 Object value = getObjectSet().getValue(getPropertyPath());
54 activateDetailConstraints(value);
55 return value;
56 }catch(Exception e){
57 throw new EditorModelException (
58 String.format(
59 "Can't get value from editor model (%s) in editor " +
60 "group (%s)"
61 , getName(), getModelGroup().getName())
62 , e);
63 }
64 }
65
66 public PropertyDescriptor getPropertyDescriptor()
67 throws EditorModelException
68 {
69 try{
70 PropertyDescriptor desc =
71 getModelGroup().getPropertyDescriptor(getPropertyPath());
72 if (getPattern()!=null){
73 PropertyDescriptorImpl childDesc =
74 new PropertyDescriptorImpl();
75 childDesc.setPattern(getPattern());
76 childDesc.setParent(desc);
77 desc=childDesc;
78 }
79 return desc;
80 }catch(EditorModelGroupException e){
81 throw new EditorModelException(
82 String.format(
83 "Can't get property descriptor for property (%s)"
84 , getPropertyPath())
85 , e);
86 }
87 }
88
89 }