KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > IdentifierManager


1 /*
2
3    Copyright 2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.css.engine.value;
19
20 import org.apache.batik.css.engine.CSSEngine;
21 import org.w3c.css.sac.LexicalUnit;
22 import org.w3c.dom.DOMException JavaDoc;
23 import org.w3c.dom.css.CSSPrimitiveValue;
24
25 /**
26  * This class provides a manager for the property with support for
27  * identifier values.
28  *
29  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
30  * @version $Id: IdentifierManager.java,v 1.5 2004/12/03 12:20:15 deweese Exp $
31  */

32 public abstract class IdentifierManager extends AbstractValueManager {
33
34     /**
35      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
36      */

37     public Value createValue(LexicalUnit lu, CSSEngine engine)
38         throws DOMException JavaDoc {
39     switch (lu.getLexicalUnitType()) {
40     case LexicalUnit.SAC_INHERIT:
41         return ValueConstants.INHERIT_VALUE;
42
43     case LexicalUnit.SAC_IDENT:
44             String JavaDoc s = lu.getStringValue().toLowerCase().intern();
45         Object JavaDoc v = getIdentifiers().get(s);
46         if (v == null) {
47         throw createInvalidIdentifierDOMException(lu.getStringValue());
48         }
49         return (Value)v;
50
51     default:
52         throw createInvalidLexicalUnitDOMException
53                 (lu.getLexicalUnitType());
54     }
55     }
56
57     /**
58      * Implements {@link
59      * ValueManager#createStringValue(short,String,CSSEngine)}.
60      */

61     public Value createStringValue(short type, String JavaDoc value, CSSEngine engine)
62     throws DOMException JavaDoc {
63     if (type != CSSPrimitiveValue.CSS_IDENT) {
64             throw createInvalidStringTypeDOMException(type);
65     }
66     Object JavaDoc v = getIdentifiers().get(value.toLowerCase().intern());
67     if (v == null) {
68             throw createInvalidIdentifierDOMException(value);
69     }
70     return (Value)v;
71     }
72
73     /**
74      * Returns the map that contains the name/value mappings for each
75      * possible identifiers.
76      */

77     public abstract StringMap getIdentifiers();
78 }
79
Popular Tags