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: StaticPropertyList.java 985537 2010-08-14 17:17:00Z jeremias $ */ 19 20 package org.apache.fop.fo; 21 22 import org.apache.fop.fo.expr.PropertyException; 23 import org.apache.fop.fo.properties.Property; 24 25 /** 26 * A very fast implementation of PropertyList that uses arrays to store 27 * the explicit set properties and another array to store cached values. 28 */ 29 public class StaticPropertyList extends PropertyList { 30 private final Property[] explicit; 31 private final Property[] values; 32 33 /** 34 * Construct a StaticPropertyList. 35 * @param fObjToAttach The FObj object. 36 * @param parentPropertyList The parent property list. 37 */ StaticPropertyList(FObj fObjToAttach, PropertyList parentPropertyList)38 public StaticPropertyList(FObj fObjToAttach, PropertyList parentPropertyList) { 39 super(fObjToAttach, parentPropertyList); 40 explicit = new Property[Constants.PROPERTY_COUNT + 1]; 41 values = new Property[Constants.PROPERTY_COUNT + 1]; 42 } 43 44 /** 45 * Return the value explicitly specified on this FO. 46 * @param propId The ID of the property whose value is desired. 47 * @return The value if the property is explicitly set, otherwise null. 48 */ getExplicit(int propId)49 public Property getExplicit(int propId) { 50 return explicit[propId]; 51 } 52 53 /** 54 * Set an value defined explicitly on this FO. 55 * @param propId The ID of the property whose value is desired. 56 * @param value The value of the property to set. 57 */ putExplicit(int propId, Property value)58 public void putExplicit(int propId, Property value) { 59 explicit[propId] = value; 60 if (values[propId] != null) { // if the cached value is set overwrite it 61 values[propId] = value; 62 } 63 } 64 65 /** 66 * Override PropertyList.get() and provides fast caching of previously 67 * retrieved property values. 68 * {@inheritDoc} 69 */ get(int propId, boolean bTryInherit, boolean bTryDefault)70 public Property get(int propId, boolean bTryInherit, boolean bTryDefault) 71 throws PropertyException { 72 Property p = values[propId]; 73 if (p == null) { 74 p = super.get(propId, bTryInherit, bTryDefault); 75 values[propId] = p; 76 } 77 return p; 78 } 79 } 80