KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > util > AbstractFieldValue


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10
11 package org.mmbase.bridge.util;
12 import org.mmbase.bridge.*;
13 import org.mmbase.util.Casting;
14 import org.w3c.dom.Document JavaDoc;
15 import org.w3c.dom.Element JavaDoc;
16 import java.util.*;
17
18 /**
19  * This implementation of the Field Value interface is used by getFunctionValue of Node. This
20  * represents the result of a `function' on a node and it (therefore) is an unmodifiable.
21  *
22  * @author Michiel Meeuwissen
23  * @version $Id: AbstractFieldValue.java,v 1.2 2006/02/10 18:00:47 michiel Exp $
24  * @since MMBase-1.8
25  */

26 public abstract class AbstractFieldValue implements FieldValue {
27
28     static protected BridgeException CANNOTCHANGE = new BridgeException("Cannot change function value");
29
30     protected final Node node;
31     protected final Cloud cloud;
32
33     protected AbstractFieldValue(Node n, Cloud c) {
34         node = n;
35         cloud = c != null ? c : (n != null ? n.getCloud() : null);
36     }
37
38     /**
39      * Function values cannot be changed
40      * @return false
41      */

42     public boolean canModify() {
43         return false;
44     }
45
46     public boolean isNull() {
47         return get() == null;
48     }
49
50     public abstract Object JavaDoc get();
51
52     public Object JavaDoc getField() {
53         return null;
54     }
55
56     public Node getNode() {
57         return node;
58     }
59
60     public boolean toBoolean() {
61         return Casting.toBoolean(get());
62     }
63
64     public byte[] toByte() {
65         return Casting.toByte(get());
66     }
67
68     public float toFloat() {
69         return Casting.toFloat(get());
70     }
71
72     public double toDouble() {
73         return Casting.toDouble(get());
74     }
75
76     public long toLong() {
77         return Casting.toLong(get());
78     }
79
80     public int toInt() {
81         return Casting.toInt(get());
82     }
83
84     public Node toNode() {
85         return Casting.toNode(get(), cloud);
86     }
87
88     public String JavaDoc toString() {
89         return Casting.toString(get());
90     }
91
92     public Document JavaDoc toXML() throws IllegalArgumentException JavaDoc {
93         return Casting.toXML(get());
94     }
95
96     public final Element JavaDoc toXML(Document JavaDoc tree) throws IllegalArgumentException JavaDoc {
97         Document JavaDoc doc = toXML();
98         if(doc == null) return null;
99         return (Element JavaDoc) tree.importNode(doc.getDocumentElement(), true);
100     }
101
102     /**
103      * @since MMBase-1.8
104      */

105     public Date toDate() {
106         return Casting.toDate(get());
107     }
108
109
110     /**
111      * Function values cannot be changed, and all set-functions throw an exception.
112      * @param value set value
113      * @throws BridgeException
114      */

115     public void set(Object JavaDoc value) {
116         throw CANNOTCHANGE;
117     }
118
119
120     public void setObject(Object JavaDoc value) {
121         throw CANNOTCHANGE;
122     }
123
124     /**
125      * Function values cannot be changed, and all set-functions throw an exception.
126      * @param value set value
127      * @throws BridgeException
128      */

129     public void setBoolean(boolean value) {
130         throw CANNOTCHANGE;
131     }
132
133     /**
134      * Function values cannot be changed, and all set-functions throw an exception.
135      * @param value set value
136      * @throws BridgeException
137      */

138     public void setFLoat(float value) {
139         throw CANNOTCHANGE;
140     }
141
142     /**
143      * Function values cannot be changed, and all set-functions throw an exception.
144      * @param value set value
145      * @throws BridgeException
146      */

147     public void setDouble(double value) {
148         throw CANNOTCHANGE;
149     }
150
151     /**
152      * Function values cannot be changed, and all set-functions throw an exception.
153      * @param value set value
154      * @throws BridgeException
155      */

156     public void setLong(long value) {
157         throw CANNOTCHANGE;
158     }
159
160     /**
161      * Function values cannot be changed, and all set-functions throw an exception.
162      * @param value set value
163      * @throws BridgeException
164      */

165     public void setInt(int value) {
166         throw CANNOTCHANGE;
167     }
168
169     /**
170      * Function values cannot be changed, and all set-functions throw an exception.
171      * @param value set value
172      * @throws BridgeException
173      */

174     public void setByte(byte[] value) {
175         throw CANNOTCHANGE;
176     }
177
178     /**
179      * Function values cannot be changed, and all set-functions throw an exception.
180      * @param value set value
181      * @throws BridgeException
182      */

183     public void setString(String JavaDoc value) {
184         throw CANNOTCHANGE;
185     }
186
187     /**
188      * Function values cannot be changed, and all set-functions throw an exception.
189      * @param value set value
190      * @throws BridgeException
191      */

192     public void setNode(Node value) {
193         throw CANNOTCHANGE;
194     }
195
196     /**
197      * Function values cannot be changed, and all set-functions throw an exception.
198      * @param value set value
199      * @throws BridgeException
200      */

201     public void setXML(Document JavaDoc value) {
202         throw CANNOTCHANGE;
203     }
204
205     /**
206      * Function values cannot be changed, and all set-functions throw an exception.
207      * @throws BridgeException
208      * @since MMBase-1.8
209      */

210     public void setDate(Date value) {
211         throw CANNOTCHANGE;
212     }
213
214 }
215
Popular Tags