1 23 24 package org.apache.slide.projector.descriptor; 25 26 import org.apache.slide.projector.Context; 27 import org.apache.slide.projector.value.ArrayValue; 28 import org.apache.slide.projector.value.Value; 29 30 34 public class TreeValueDescriptor implements ValueDescriptor { 35 private ValueDescriptor entryValueDescriptor; 36 private ValueDescriptor arrayValueDescriptor; 37 38 public TreeValueDescriptor() { 39 this.entryValueDescriptor = null; 40 arrayValueDescriptor = new ArrayValueDescriptor(this); 41 } 42 43 public TreeValueDescriptor(ValueDescriptor entryValueDescriptor) { 44 this.entryValueDescriptor = entryValueDescriptor; 45 arrayValueDescriptor = new ArrayValueDescriptor(this); 46 } 47 48 public Value valueOf(Object value, Context context) throws ValueCastException { 49 try { 50 return arrayValueDescriptor.valueOf(value, context); 51 } catch ( ValueCastException exception ) { 52 return entryValueDescriptor.valueOf(value, context); 53 } 54 } 55 56 public void validate(Value value, Context context) throws ValidationException { 57 if ( value instanceof ArrayValue ) { 58 arrayValueDescriptor.validate(value, context); 59 } else { 60 entryValueDescriptor.validate(value, context); 61 } 62 } 63 } | Popular Tags |