Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

EnumType.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * EnumType.java
  3. * $Id$
  4. *
  5. * Created: Tue Nov 20 22:18:11 2001
  6. *
  7. *
  8. * Copyright 1999-2003 The Apache Software Foundation.
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. *
  22. *
  23. */
  24. package org.apache.fop.datatypes;
  25. import org.apache.fop.fo.PropNames;
  26. import org.apache.fop.fo.expr.PropertyException;
  27. import org.apache.fop.fo.properties.Property;
  28. /**
  29. * Base class for representing enumerated values. The value is maintained as
  30. * an <tt>int</tt> constant value.
  31. * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
  32. * @version $Revision$ $Name$
  33. */
  34. public class EnumType extends AbstractPropertyValue {
  35. private static final String tag = "$Name$";
  36. private static final String revision = "$Revision$";
  37. /**
  38. * An integer enumeration value.
  39. */
  40. protected int enumValue;
  41. /**
  42. * @param property the <tt>int</tt> index of the property on which
  43. * this value is being defined.
  44. * @param enumText the <tt>String</tt> containing the enumeration text.
  45. * An <i>NCName</i>.
  46. * @exception PropertyException
  47. */
  48. public EnumType(int property, String enumText)
  49. throws PropertyException
  50. {
  51. this(property, enumText, PropertyValue.ENUM);
  52. }
  53. /**
  54. * @param property the <tt>int</tt> index of the property on which
  55. * this value is being defined.
  56. * @param enum the <tt>int</tt> enumeration constant.
  57. * @exception PropertyException
  58. */
  59. public EnumType(int property, int enum)
  60. throws PropertyException
  61. {
  62. this(property, enum, PropertyValue.ENUM);
  63. }
  64. /**
  65. * @param propertyName the <tt>String</tt> name of the property on which
  66. * this value is being defined.
  67. * @param enumText the <tt>String</tt> containing the enumeration text.
  68. * An <i>NCName</i>.
  69. * @exception PropertyException
  70. */
  71. public EnumType(String propertyName, String enumText)
  72. throws PropertyException
  73. {
  74. this(PropNames.getPropertyIndex(propertyName),
  75. enumText, PropertyValue.ENUM);
  76. }
  77. /**
  78. * @param propertyName the <tt>String</tt> name of the property on which
  79. * this value is being defined.
  80. * @param enum the <tt>int</tt> enumeration constant.
  81. * @exception PropertyException
  82. */
  83. public EnumType(String propertyName, int enum)
  84. throws PropertyException
  85. {
  86. this(PropNames.getPropertyIndex(propertyName),
  87. enum, PropertyValue.ENUM);
  88. }
  89. /**
  90. * @param property the <tt>int</tt> index of the property on which
  91. * this value is being defined.
  92. * @param enumText the <tt>String</tt> containing the enumeration text.
  93. * An <i>NCName</i>.
  94. * @param type of this value
  95. * @exception PropertyException
  96. */
  97. public EnumType(int property, String enumText, int type)
  98. throws PropertyException
  99. {
  100. super(property, type);
  101. // Get the enum integer or mapped enum integer
  102. enumValue = propertyConsts.getEnumIndex(property, enumText);
  103. }
  104. /**
  105. * @param property the <tt>int</tt> index of the property on which
  106. * this value is being defined.
  107. * @param enum the <tt>int</tt> enumeration constant.
  108. * @param type of this value
  109. * @exception PropertyException
  110. */
  111. public EnumType(int property, int enum, int type)
  112. throws PropertyException
  113. {
  114. super(property, type);
  115. enumValue = enum;
  116. // Validate the text; getEnumText will throw a PropertyException
  117. // if the enum integer is invalid
  118. String enumText = propertyConsts.getEnumText(property, enum);
  119. }
  120. /**
  121. * @param propertyName the <tt>String</tt> name of the property on which
  122. * this value is being defined.
  123. * @param enumText the <tt>String</tt> containing the enumeration text.
  124. * An <i>NCName</i>.
  125. * @param type of this value
  126. * @exception PropertyException
  127. */
  128. public EnumType(String propertyName, String enumText, int type)
  129. throws PropertyException
  130. {
  131. this(PropNames.getPropertyIndex(propertyName), enumText, type);
  132. }
  133. /**
  134. * @param propertyName the <tt>String</tt> name of the property on which
  135. * this value is being defined.
  136. * @param enum the <tt>int</tt> enumeration constant.
  137. * @param type of this value
  138. * @exception PropertyException
  139. */
  140. public EnumType(String propertyName, int enum, int type)
  141. throws PropertyException
  142. {
  143. this(PropNames.getPropertyIndex(propertyName), enum, type);
  144. }
  145. /**
  146. * @return the <tt>int</tt> ENUM value.
  147. */
  148. public int getEnumValue() {
  149. return enumValue;
  150. }
  151. /**
  152. * @return the <tt>String</tt> enumeration token.
  153. */
  154. public String getEnumToken() throws PropertyException {
  155. return propertyConsts.getEnumText(property, enumValue);
  156. }
  157. /**
  158. * validate the <i>EnumType</i> against the associated property.
  159. */
  160. public void validate() throws PropertyException {
  161. super.validate(Property.ENUM);
  162. }
  163. public String toString() {
  164. String enumText;
  165. try {
  166. enumText = propertyConsts.getEnumText(property, enumValue);
  167. } catch (PropertyException e) {
  168. throw new RuntimeException(e.getMessage());
  169. }
  170. return enumText + " " + enumValue + "\n" + super.toString();
  171. }
  172. }