KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > StaticPropertyList


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 package org.apache.fop.fo;
18
19 import org.apache.fop.fo.expr.PropertyException;
20 import org.apache.fop.fo.properties.Property;
21
22 /**
23  * A very fast implementation of PropertyList that uses arrays to store
24  * the explicit set properties and another array to store cached values.
25  */

26 public class StaticPropertyList extends PropertyList {
27     private Property[] explicit;
28     private Property[] values;
29     
30     /**
31      * Construct a StaticPropertyList.
32      * @param fObjToAttach The FObj object.
33      * @param parentPropertyList The parent property list.
34      */

35     public StaticPropertyList(FObj fObjToAttach, PropertyList parentPropertyList) {
36         super(fObjToAttach, parentPropertyList);
37         explicit = new Property[Constants.PROPERTY_COUNT + 1];
38         values = new Property[Constants.PROPERTY_COUNT + 1];
39     }
40
41     /**
42      * Return the value explicitly specified on this FO.
43      * @param propId The ID of the property whose value is desired.
44      * @return The value if the property is explicitly set, otherwise null.
45      */

46     public Property getExplicit(int propId) {
47         return explicit[propId];
48     }
49
50     /**
51      * Set an value defined explicitly on this FO.
52      * @param propId The ID of the property whose value is desired.
53      * @param value The value of the property to set.
54      */

55     public void putExplicit(int propId, Property value) {
56         explicit[propId] = value;
57         if (values[propId] != null) { // if the cached value is set overwrite it
58
values[propId] = value;
59         }
60     }
61
62     /**
63      * Override PropertyList.get() and provides fast caching of previously
64      * retrieved property values.
65      * @param propId The property ID
66      */

67     public Property get(int propId, boolean bTryInherit, boolean bTryDefault)
68         throws PropertyException
69     {
70         Property p = values[propId];
71         if (p == null) {
72             p = values[propId] = super.get(propId, bTryInherit, bTryDefault);
73         }
74         return p;
75     }
76 }
77
Popular Tags