001: /*
002:
003: ============================================================================
004: The Apache Software License, Version 1.1
005: ============================================================================
006:
007: Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
008:
009: Redistribution and use in source and binary forms, with or without modifica-
010: tion, are permitted provided that the following conditions are met:
011:
012: 1. Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014:
015: 2. Redistributions in binary form must reproduce the above copyright notice,
016: this list of conditions and the following disclaimer in the documentation
017: and/or other materials provided with the distribution.
018:
019: 3. The end-user documentation included with the redistribution, if any, must
020: include the following acknowledgment: "This product includes software
021: developed by the Apache Software Foundation (http://www.apache.org/)."
022: Alternately, this acknowledgment may appear in the software itself, if
023: and wherever such third-party acknowledgments normally appear.
024:
025: 4. The names "Batik" and "Apache Software Foundation" must not be
026: used to endorse or promote products derived from this software without
027: prior written permission. For written permission, please contact
028: apache@apache.org.
029:
030: 5. Products derived from this software may not be called "Apache", nor may
031: "Apache" appear in their name, without prior written permission of the
032: Apache Software Foundation.
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
035: INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
036: FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
037: APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
039: DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
040: OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
041: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044:
045: This software consists of voluntary contributions made by many individuals
046: on behalf of the Apache Software Foundation. For more information on the
047: Apache Software Foundation, please see <http://www.apache.org/>.
048:
049: */
050:
051: package org.apache.batik.css.engine.value;
052:
053: import java.lang.ref.WeakReference;
054: import org.w3c.dom.DOMException;
055: import org.w3c.dom.css.CSSValue;
056:
057: /**
058: * This class provides an abstract implementation of the Value interface.
059: *
060: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
061: * @version $Id$
062: */
063: public abstract class AbstractValue implements Value {
064:
065: /**
066: * Implements {@link Value#getCssValueType()}.
067: */
068: public short getCssValueType() {
069: return CSSValue.CSS_PRIMITIVE_VALUE;
070: }
071:
072: /**
073: * Implements {@link Value#getPrimitiveType()}.
074: */
075: public short getPrimitiveType() {
076: throw createDOMException();
077: }
078:
079: /**
080: * Implements {@link Value#getFloatValue()}.
081: */
082: public float getFloatValue() throws DOMException {
083: throw createDOMException();
084: }
085:
086: /**
087: * Implements {@link Value#getStringValue()}.
088: */
089: public String getStringValue() throws DOMException {
090: throw createDOMException();
091: }
092:
093: /**
094: * Implements {@link Value#getRed()}.
095: */
096: public Value getRed() throws DOMException {
097: throw createDOMException();
098: }
099:
100: /**
101: * Implements {@link Value#getGreen()}.
102: */
103: public Value getGreen() throws DOMException {
104: throw createDOMException();
105: }
106:
107: /**
108: * Implements {@link Value#getBlue()}.
109: */
110: public Value getBlue() throws DOMException {
111: throw createDOMException();
112: }
113:
114: /**
115: * Implements {@link Value#getLength()}.
116: */
117: public int getLength() throws DOMException {
118: throw createDOMException();
119: }
120:
121: /**
122: * Implements {@link Value#item(int)}.
123: */
124: public Value item(int index) throws DOMException {
125: throw createDOMException();
126: }
127:
128: /**
129: * Implements {@link Value#getTop()}.
130: */
131: public Value getTop() throws DOMException {
132: throw createDOMException();
133: }
134:
135: /**
136: * Implements {@link Value#getRight()}.
137: */
138: public Value getRight() throws DOMException {
139: throw createDOMException();
140: }
141:
142: /**
143: * Implements {@link Value#getBottom()}.
144: */
145: public Value getBottom() throws DOMException {
146: throw createDOMException();
147: }
148:
149: /**
150: * Implements {@link Value#getLeft()}.
151: */
152: public Value getLeft() throws DOMException {
153: throw createDOMException();
154: }
155:
156: /**
157: * Implements {@link Value#getIdentifier()}.
158: */
159: public String getIdentifier() throws DOMException {
160: throw createDOMException();
161: }
162:
163: /**
164: * Implements {@link Value#getListStyle()}.
165: */
166: public String getListStyle() throws DOMException {
167: throw createDOMException();
168: }
169:
170: /**
171: * Implements {@link Value#getSeparator()}.
172: */
173: public String getSeparator() throws DOMException {
174: throw createDOMException();
175: }
176:
177: /**
178: * Creates an INVALID_ACCESS_ERR exception.
179: */
180: protected DOMException createDOMException() {
181: Object[] p = new Object[] { new Integer(getCssValueType()) };
182: String s = Messages.formatMessage("invalid.value.access", p);
183: // BEGIN RAVE MODIFICATIONS
184: //return new DOMException(DOMException.INVALID_ACCESS_ERR, s);
185: return new DOMException(DOMException.INVALID_ACCESS_ERR, s
186: + ": " + this );
187: // END RAVE MODIFICATIONS
188: }
189:
190: // BEGIN RAVE MODIFICATIONS
191: /**
192: * The (possibly relative) linenumber in the file where this CSS
193: * value is defined.
194: */
195: public int getLineNumber() {
196: return lineno;
197: }
198:
199: /**
200: * The location where this CSS value is defined. This could be a
201: * CSS file but doesn't have to be -- it could point to a markup file
202: * with an inline style attribute. This is an "opaque" value as far
203: * as the value object is concerned; it does not interpret it.
204: * The client such as the CSS engine can use the location attribute
205: * to efficiently store information related to the location here such
206: * that it can later compute the filename.
207: */
208: public Object getLocation() {
209: return locationWRef.get();
210: }
211:
212: /** For library use only. Public to allow subpackage access. */
213: public void setLocation(Object location) {
214: locationWRef = new WeakReference(location);
215: }
216:
217: /** For library use only. Public to allow subpackage access. */
218: public void setLineNumber(int lineno) {
219: this .lineno = lineno;
220: }
221:
222: /** XXX Just a hot fix to have weak ref instead of strong one.
223: Better solution is to rearchitect it the way this value doesn't hold any such objects,
224: but there is a map kept internally wherever such link is needed. */
225: private WeakReference locationWRef = new WeakReference(null);
226: private int lineno;
227: // END RAVE MODIFICATIONS
228:
229: }
|