1 2 5 14 package org.jacorb.trading.constraint; 15 16 import java.io.*; 17 18 19 20 public class PropertyNode extends ExprNode 21 { 22 private String m_name; 23 24 25 private PropertyNode() 26 { 27 } 28 29 30 public PropertyNode(String name, ValueType type) 31 { 32 m_name = name; 33 setType(type); 34 } 35 36 37 public void print(PrintStream ps) 38 { 39 ps.println("PropertyNode: name = " + m_name + " type = " + getType()); 40 } 41 42 43 public Value evaluate(PropertySource source) 44 throws MissingPropertyException 45 { 46 Value result; 47 48 result = source.getValue(m_name); 49 if (result == null) 50 throw new MissingPropertyException(m_name); 51 52 return result; 53 } 54 55 56 public boolean exists(PropertySource source) 57 { 58 boolean result = (source.exists(m_name) && source.getValue(m_name) != null); 62 return result; 63 } 64 65 66 public boolean inSequence(Value value, PropertySource source) 67 { 68 boolean result = false; 69 70 int id = ValueType.promote(getType().getId(), value.getTypeId()); 71 72 Value v = value.convert(id); 73 74 Value[] seq = source.getSequenceValues(m_name); 75 for (int i = 0; i < seq.length; i++) { 76 Value nv = seq[i].convert(id); 77 if (v.equals(nv)) { 78 result = true; 79 break; 80 } 81 } 82 83 return result; 84 } 85 } 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | Popular Tags |