You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StaticPropertyList.java 2.7KB

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