1 17 18 19 20 package org.apache.fop.fo.properties; 21 22 import org.apache.fop.fo.FObj; 23 import org.apache.fop.fo.PropertyList; 24 import org.apache.fop.fo.expr.PropertyException; 25 26 import java.util.Map ; 27 import java.util.WeakHashMap ; 28 29 32 public class EnumProperty extends Property { 33 34 37 public static class Maker extends PropertyMaker { 38 39 42 public Maker(int propId) { 43 super(propId); 44 } 45 46 51 public Property checkEnumValues(String value) { 52 return super.checkEnumValues(value); 55 } 56 57 public Property convertProperty(Property p, 58 PropertyList propertyList, 59 FObj fo) throws PropertyException { 60 if (p instanceof EnumProperty) { 61 return p; 62 } else { 63 return super.convertProperty(p, propertyList, fo); 64 } 65 } 66 } 67 68 private static final Map propertyCache = new WeakHashMap (); 69 70 private final int value; 71 private final String text; 72 73 77 private EnumProperty(int explicitValue, String text) { 78 this.value = explicitValue; 79 this.text = text; 80 } 81 82 public static EnumProperty getInstance(int explicitValue, String text) { 83 EnumProperty ep = new EnumProperty(explicitValue, text); 84 EnumProperty cacheEntry = (EnumProperty)propertyCache.get(ep); 85 if (cacheEntry == null) { 86 propertyCache.put(ep, ep); 87 return ep; 88 } else { 89 return cacheEntry; 90 } 91 } 92 93 96 public int getEnum() { 97 return this.value; 98 } 99 100 103 public Object getObject() { 104 return text; 105 } 106 107 public boolean equals(Object obj) { 108 if (obj instanceof EnumProperty) { 109 EnumProperty ep = (EnumProperty)obj; 110 return ep.value == this.value && 111 ((ep.text == null && this.text == null) 112 || ep.text.equals(this.text)); 113 } else { 114 return false; 115 } 116 } 117 118 public int hashCode() { 119 return value + text.hashCode(); 120 } 121 } 122 123 | Popular Tags |