選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FromNearestSpecified.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * $Id$
  3. *
  4. *
  5. * Copyright 1999-2003 The Apache Software Foundation.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. *
  20. */
  21. package org.apache.fop.datatypes.indirect;
  22. import org.apache.fop.datatypes.PropertyValue;
  23. import org.apache.fop.fo.FONode;
  24. import org.apache.fop.fo.expr.PropertyException;
  25. import org.apache.fop.fo.properties.Property;
  26. /**
  27. * A pseudo-class to represent a call to the core function
  28. * from-nearest-specified-value().
  29. * Used <i>only</i> in the cases where the property
  30. * assigned to is identical to the <tt>NCName</tt> argument, and this is a
  31. * shorthand.
  32. * <p>Further, the function call must be the only component of the expression
  33. * in which it occurs. (See Rec. Section 5.10.4 Property Value Functions.)
  34. * In these circumstances, the function call resolves to a
  35. * from-nearest-specified-value() function call on each of the properties to
  36. * which the shorthand resolves.
  37. * <p>The use of the pseudo-type should ensure that the function call is not
  38. * involved in any arithmetic components of a more complex expression. I.e,
  39. * the function evaluator in the parser must check to see whether the
  40. * property for which the from-nearest-specified-value() function is being
  41. * evaluated is a shorthand. If not, the function is normally evaluated.
  42. * If so, the parser must further check that the property assigned to (i.e.
  43. * the property against which this function is being evaluated) is the same
  44. * as the <tt>NCName</tt> argument. If not, it is an error. If so, the
  45. * property evaluates to an instance of this class. The value must itself
  46. * be later resolved before the property value can be utilised in the fo
  47. * node, but, in the meantime, any attempt to involve the function call in
  48. * any more complex expression will throw an exception.
  49. * <p>This mechanism ensures, without greatly complicating the parser,
  50. * that the constraint on the from-nearest-specified-value() function, with
  51. * respect to shorthands, is met.
  52. * <p>This pseudo-datatype is also used as the first stage of shorthand
  53. * expansion. After a shorthand's expression is parsed, the next stage of
  54. * resolution will generate a FromNearestSpecified object for each property
  55. * in the expansion of the shorthand.
  56. * <p>Once created, this class acts as an <tt>IndirectValue</tt> in the
  57. * event that it cannot immediately be resolved. This association exists
  58. * simply to save creating another object.
  59. *
  60. * @see FromParent
  61. * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
  62. * @version $Revision$ $Name$
  63. */
  64. public class FromNearestSpecified extends IndirectValue {
  65. private static final String tag = "$Name$";
  66. private static final String revision = "$Revision$";
  67. /**
  68. * @param property the <tt>int</tt> index of the property on which
  69. * this value is being defined. In this case, a shorthand property.
  70. * @exception PropertyException
  71. */
  72. public FromNearestSpecified(int property)
  73. throws PropertyException
  74. {
  75. super(property, PropertyValue.FROM_NEAREST_SPECIFIED);
  76. }
  77. /**
  78. * @param propertyName the <tt>String</tt> name of the property on which
  79. * this value is being defined. In this case, a shorthand property.
  80. * @exception PropertyException
  81. */
  82. public FromNearestSpecified(String propertyName)
  83. throws PropertyException
  84. {
  85. super(propertyName, PropertyValue.FROM_NEAREST_SPECIFIED);
  86. }
  87. /**
  88. * Attempt to resolve this object into a "real" property value. If the
  89. * object has no <i>inheritedValue</i>, obtain and set one. The
  90. * obtained value is from the nearest ancestor node on which a value
  91. * has been specified.
  92. * Then invoke the superclass' <i>resolve()</i> method.
  93. * @param node - the <tt>FONode</tt> with which this object is associated.
  94. * @return the resulting <tt>PropertyValue</tt>. Either a resolved value
  95. * or <i>this</i>, if bequeathing value has no resolved computed value.
  96. */
  97. public PropertyValue resolve(FONode node) throws PropertyException {
  98. if (inheritedValue == null) {
  99. inheritedValue = node.getNearestSpecifiedValue(sourceProperty);
  100. }
  101. return super.resolve(node);
  102. }
  103. /**
  104. * validate the <i>FromNearestSpecified</i> against the associated
  105. * property.
  106. */
  107. public void validate() throws PropertyException {
  108. super.validate(Property.SHORTHAND);
  109. }
  110. }