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.

EnumNumber.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.properties;
  19. import org.apache.fop.datatypes.Numeric;
  20. import org.apache.fop.datatypes.PercentBaseContext;
  21. import org.apache.fop.fo.expr.PropertyException;
  22. /**
  23. * A number quantity in XSL which is specified as an enum, such as "no-limit".
  24. */
  25. public final class EnumNumber extends Property implements Numeric {
  26. /** cache holding all canonical EnumNumber instances */
  27. private static final PropertyCache cache = new PropertyCache();
  28. private final EnumProperty enumProperty;
  29. /**
  30. * Constructor
  31. * @param enumProperty the base EnumProperty
  32. */
  33. private EnumNumber(Property enumProperty) {
  34. this.enumProperty = (EnumProperty) enumProperty;
  35. }
  36. /**
  37. * Returns the canonical EnumNumber instance corresponding
  38. * to the given Property
  39. *
  40. * @param enumProperty the base EnumProperty
  41. * @return the canonical instance
  42. */
  43. public static EnumNumber getInstance(Property enumProperty) {
  44. return (EnumNumber)cache.fetch(
  45. new EnumNumber((EnumProperty) enumProperty));
  46. }
  47. /** {@inheritDoc} */
  48. public int getEnum() {
  49. return enumProperty.getEnum();
  50. }
  51. /** {@inheritDoc} */
  52. public String getString() {
  53. return enumProperty.toString();
  54. }
  55. /** {@inheritDoc} */
  56. public Object getObject() {
  57. return enumProperty.getObject();
  58. }
  59. /** {@inheritDoc} */
  60. public boolean equals(Object obj) {
  61. if (obj instanceof EnumNumber) {
  62. return (((EnumNumber)obj).enumProperty == this.enumProperty);
  63. } else {
  64. return false;
  65. }
  66. }
  67. /** {@inheritDoc} */
  68. public int hashCode() {
  69. return enumProperty.hashCode();
  70. }
  71. /** {@inheritDoc} */
  72. public int getDimension() {
  73. return 0;
  74. }
  75. /**
  76. * {@inheritDoc}
  77. * Always <code>true</code> for instances of this type
  78. */
  79. public boolean isAbsolute() {
  80. return true;
  81. }
  82. /**
  83. * {@inheritDoc}
  84. * logs an error, because it's not supposed to be called
  85. */
  86. public double getNumericValue(PercentBaseContext context) throws PropertyException {
  87. log.error("getNumericValue() called on " + enumProperty + " number");
  88. return 0;
  89. }
  90. /**
  91. * {@inheritDoc}
  92. * logs an error, because it's not supposed to be called
  93. */
  94. public int getValue(PercentBaseContext context) {
  95. log.error("getValue() called on " + enumProperty + " number");
  96. return 0;
  97. }
  98. /**
  99. * {@inheritDoc}
  100. * logs an error, because it's not supposed to be called
  101. */
  102. public int getValue() {
  103. log.error("getValue() called on " + enumProperty + " number");
  104. return 0;
  105. }
  106. /**
  107. * {@inheritDoc}
  108. * logs an error, because it's not supposed to be called
  109. */
  110. public double getNumericValue() {
  111. log.error("getNumericValue() called on " + enumProperty + " number");
  112. return 0;
  113. }
  114. /**
  115. * {@inheritDoc}
  116. */
  117. public Numeric getNumeric() {
  118. return this;
  119. }
  120. }