1 46 package groovy.model; 47 48 import org.codehaus.groovy.runtime.InvokerHelper; 49 50 56 public class PropertyModel implements ValueModel, NestedValueModel { 57 58 private ValueModel sourceModel; 59 private String property; 60 private Class type; 61 62 public PropertyModel(ValueModel sourceModel, String property) { 63 this(sourceModel, property, Object .class); 64 } 65 66 public PropertyModel(ValueModel sourceModel, String property, Class type) { 67 this.sourceModel = sourceModel; 68 this.property = property; 69 this.type = type; 70 } 71 72 public String getProperty() { 73 return property; 74 } 75 76 public ValueModel getSourceModel() { 77 return sourceModel; 78 } 79 80 public Object getValue() { 81 Object source = sourceModel.getValue(); 82 if (source != null) { 83 return InvokerHelper.getProperty(source, property); 84 } 85 return null; 86 } 87 88 public void setValue(Object value) { 89 Object source = sourceModel.getValue(); 90 if (source != null) { 91 InvokerHelper.setProperty(source, property, value); 92 } 93 } 94 95 public Class getType() { 96 return type; 97 } 98 99 public boolean isEditable() { 100 101 return true; 102 } 103 104 } 105 | Popular Tags |