KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > svg > AbstractSVGItem


1 /*
2
3    Copyright 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.dom.svg;
19
20 /**
21  * Adapter for the SVGItem interface.
22  *
23  * @author <a HREF="mailto:nicolas.socheleau@bitflash.com">Nicolas Socheleau</a>
24  * @version $Id: AbstractSVGItem.java,v 1.3 2004/08/18 07:13:13 vhardy Exp $
25  */

26 public abstract class AbstractSVGItem
27     implements SVGItem {
28
29     /**
30      * List the item belongs to.
31      */

32     protected AbstractSVGList parent;
33
34     /**
35      * String representation of the item.
36      *
37      * This is a cached representation of the
38      * item while it is not changed.
39      */

40     protected String JavaDoc itemStringValue;
41
42     /**
43      * Return the string representation of the item.
44      */

45     protected abstract String JavaDoc getStringValue();
46
47     /// Default Constructor.
48
protected AbstractSVGItem(){
49     }
50
51     /**
52      * Assign a parent list to this item.
53      *
54      * @param list : list the item belongs.
55      */

56     public void setParent(AbstractSVGList list){
57         parent = list;
58     }
59
60     /**
61      * Return the parent list of the item.
62      *
63      * @return list the item belongs.
64      */

65     public AbstractSVGList getParent(){
66         return parent;
67     }
68
69     /**
70      * Notifies the parent list that
71      * the item has changed.
72      *
73      * Discard the cached representation
74      * of the item.
75      */

76     protected void resetAttribute(){
77         if ( parent != null ){
78             itemStringValue = null;
79             parent.itemChanged();
80         }
81     }
82
83     /**
84      * Return the cached representation
85      * of the item if valid otherwise
86      * re-computes the String representation
87      * of the item.
88      */

89     public String JavaDoc getValueAsString(){
90         if ( itemStringValue == null ){
91             itemStringValue = getStringValue();
92         }
93         return itemStringValue;
94     }
95 }
96
Popular Tags