KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > area > AreaTreeObject


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 /* $Id$ */
19
20 package org.apache.fop.area;
21
22 import java.util.Collections JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.fop.util.QName;
27
28 /**
29  * Abstract base class for all area tree objects.
30  */

31 public abstract class AreaTreeObject {
32
33     /** Foreign attributes */
34     protected Map JavaDoc foreignAttributes = null;
35     
36     /**
37      * Sets a foreign attribute.
38      * @param name the qualified name of the attribute
39      * @param value the attribute value
40      */

41     public void setForeignAttribute(QName name, String JavaDoc value) {
42         if (this.foreignAttributes == null) {
43             this.foreignAttributes = new java.util.HashMap JavaDoc();
44         }
45         this.foreignAttributes.put(name, value);
46     }
47     
48     /**
49      * Set foreign attributes from a Map.
50      * @param atts a Map with attributes (keys: QName, values: String)
51      */

52     public void setForeignAttributes(Map JavaDoc atts) {
53         if (atts.size() == 0) {
54             return;
55         }
56         Iterator JavaDoc iter = atts.keySet().iterator();
57         while (iter.hasNext()) {
58             QName qName = (QName)iter.next();
59             String JavaDoc value = (String JavaDoc)atts.get(qName);
60             //The casting is only to ensure type safety (too bad we can't use generics, yet)
61
setForeignAttribute(qName, value);
62         }
63     }
64     
65     /**
66      * Returns the value of a foreign attribute on the area.
67      * @param name the qualified name of the attribute
68      * @return the attribute value or null if it isn't set
69      */

70     public String JavaDoc getForeignAttributeValue(QName name) {
71         if (this.foreignAttributes != null) {
72             return (String JavaDoc)this.foreignAttributes.get(name);
73         } else {
74             return null;
75         }
76     }
77     
78     /** @return the foreign attributes associated with this area */
79     public Map JavaDoc getForeignAttributes() {
80         if (this.foreignAttributes != null) {
81             return Collections.unmodifiableMap(this.foreignAttributes);
82         } else {
83             return Collections.EMPTY_MAP;
84         }
85     }
86     
87     
88 }
89
Popular Tags