KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.net.URL JavaDoc;
21
22 import org.apache.batik.util.ParsedURL;
23 import org.w3c.dom.DOMException JavaDoc;
24
25 /**
26  * This class provides a base implementation for the value factories.
27  *
28  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
29  * @version $Id: AbstractValueFactory.java,v 1.5 2004/08/18 07:12:53 vhardy Exp $
30  */

31 public abstract class AbstractValueFactory {
32     
33     /**
34      * Returns the name of the property handled.
35      */

36     public abstract String JavaDoc getPropertyName();
37     
38     /**
39      * Resolves an URI.
40      */

41     protected static String JavaDoc resolveURI(URL JavaDoc base, String JavaDoc value) {
42         return new ParsedURL(base, value).toString();
43     }
44
45     /**
46      * Creates a DOM exception, given an invalid identifier.
47      */

48     protected DOMException JavaDoc createInvalidIdentifierDOMException(String JavaDoc ident) {
49         Object JavaDoc[] p = new Object JavaDoc[] { getPropertyName(), ident };
50         String JavaDoc s = Messages.formatMessage("invalid.identifier", p);
51         return new DOMException JavaDoc(DOMException.SYNTAX_ERR, s);
52     }
53
54     /**
55      * Creates a DOM exception, given an invalid lexical unit type.
56      */

57     protected DOMException JavaDoc createInvalidLexicalUnitDOMException(short type) {
58         Object JavaDoc[] p = new Object JavaDoc[] { getPropertyName(),
59                                     new Integer JavaDoc(type) };
60         String JavaDoc s = Messages.formatMessage("invalid.lexical.unit", p);
61         return new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, s);
62     }
63
64     /**
65      * Creates a DOM exception, given an invalid float type.
66      */

67     protected DOMException JavaDoc createInvalidFloatTypeDOMException(short t) {
68         Object JavaDoc[] p = new Object JavaDoc[] { getPropertyName(), new Integer JavaDoc(t) };
69         String JavaDoc s = Messages.formatMessage("invalid.float.type", p);
70         return new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, s);
71     }
72
73     /**
74      * Creates a DOM exception, given an invalid float value.
75      */

76     protected DOMException JavaDoc createInvalidFloatValueDOMException(float f) {
77         Object JavaDoc[] p = new Object JavaDoc[] { getPropertyName(), new Float JavaDoc(f) };
78         String JavaDoc s = Messages.formatMessage("invalid.float.value", p);
79         return new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, s);
80     }
81
82     /**
83      * Creates a DOM exception, given an invalid string type.
84      */

85     protected DOMException JavaDoc createInvalidStringTypeDOMException(short t) {
86         Object JavaDoc[] p = new Object JavaDoc[] { getPropertyName(), new Integer JavaDoc(t) };
87         String JavaDoc s = Messages.formatMessage("invalid.string.type", p);
88         return new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, s);
89     }
90
91     protected DOMException JavaDoc createMalformedLexicalUnitDOMException() {
92         Object JavaDoc[] p = new Object JavaDoc[] { getPropertyName() };
93         String JavaDoc s = Messages.formatMessage("malformed.lexical.unit", p);
94         return new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, s);
95     }
96
97     protected DOMException JavaDoc createDOMException() {
98         Object JavaDoc[] p = new Object JavaDoc[] { getPropertyName() };
99         String JavaDoc s = Messages.formatMessage("invalid.access", p);
100         return new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, s);
101     }
102 }
103
Popular Tags