KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > extension > PrefixableStylableExtensionElement


1 /*
2
3    Copyright 2001,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.extension;
19
20 import org.apache.batik.dom.AbstractDocument;
21 import org.apache.batik.dom.util.DOMUtilities;
22 import org.w3c.dom.DOMException JavaDoc;
23
24 /**
25  * This class implements a simple method for handling the node 'prefix'.
26  *
27  * @author <a HREF="mailto:thomas.deweese@kodak.com">Thomas Deweese</a>
28  * @version $Id: PrefixableStylableExtensionElement.java,v 1.4 2004/08/18 07:14:19 vhardy Exp $
29  */

30 public abstract class PrefixableStylableExtensionElement
31     extends StylableExtensionElement {
32
33     /**
34      * The element prefix.
35      */

36     protected String JavaDoc prefix = null;
37
38     /**
39      * Creates a new BatikStarElement object.
40      */

41     protected PrefixableStylableExtensionElement() {
42     }
43
44     /**
45      * Creates a new BatikStarElement object.
46      * @param prefix The namespace prefix.
47      * @param owner The owner document.
48      */

49     public PrefixableStylableExtensionElement(String JavaDoc prefix,
50                                               AbstractDocument owner) {
51         super(prefix, owner);
52         setPrefix(prefix);
53     }
54
55     /**
56      * <b>DOM</b>: Implements {@link org.w3c.dom.Node#getNodeName()}.
57      */

58     public String JavaDoc getNodeName() {
59         return (prefix == null || prefix.equals(""))
60             ? getLocalName() : prefix + ":" + getLocalName();
61     }
62
63     /**
64      * <b>DOM</b>: Implements {@link org.w3c.dom.Node#setPrefix(String)}.
65      */

66     public void setPrefix(String JavaDoc prefix) throws DOMException JavaDoc {
67         if (isReadonly()) {
68             throw createDOMException
69                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.node",
70                  new Object JavaDoc[] { new Integer JavaDoc(getNodeType()), getNodeName() });
71         }
72
73         if (prefix != null &&
74             !prefix.equals("") &&
75             !DOMUtilities.isValidName(prefix)) {
76             throw createDOMException
77                 (DOMException.INVALID_CHARACTER_ERR, "prefix",
78                  new Object JavaDoc[] { new Integer JavaDoc(getNodeType()),
79                                 getNodeName(),
80                                 prefix });
81         }
82
83         this.prefix = prefix;
84     }
85 }
86
Popular Tags