KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > constraint > PropertyNode


1
2 // Copyright (C) 1998-1999
3
// Object Oriented Concepts, Inc.
4

5 // **********************************************************************
6
//
7
// Copyright (c) 1997
8
// Mark Spruiell (mark@intellisoft.com)
9
//
10
// See the COPYING file for more information
11
//
12
// **********************************************************************
13

14 package org.jacorb.trading.constraint;
15
16 import java.io.*;
17
18
19 /** Represents a property */
20 public class PropertyNode extends ExprNode
21 {
22   private String JavaDoc m_name;
23
24
25   private PropertyNode()
26   {
27   }
28
29
30   public PropertyNode(String JavaDoc 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       // the mere presence of the property is not enough; we also need
59
// to make sure the property's value is obtainable; this may force
60
// the evaluation of a dynamic property
61
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