1 43 44 package org.jfree.xml.parser.coretypes; 45 46 import java.awt.RenderingHints ; 47 import java.lang.reflect.Field ; 48 import java.lang.reflect.Modifier ; 49 50 import org.jfree.util.Log; 51 import org.jfree.xml.parser.AbstractXmlReadHandler; 52 import org.jfree.xml.parser.XmlReaderException; 53 import org.xml.sax.Attributes ; 54 import org.xml.sax.SAXException ; 55 56 59 public class RenderingHintValueReadHandler extends AbstractXmlReadHandler { 60 61 62 private Object key; 63 64 65 private Object value; 66 67 70 public RenderingHintValueReadHandler() { 71 super(); 72 } 73 74 81 protected void startParsing(final Attributes attrs) throws SAXException { 82 final String keyText = attrs.getValue("key"); 83 final String valueText = attrs.getValue("value"); 84 this.key = stringToHintField(keyText); 85 this.value = stringToHintField(valueText); 86 } 87 88 private Object stringToHintField (final String name) { 89 final Field [] fields = RenderingHints .class.getFields(); 90 for (int i = 0; i < fields.length; i++) { 91 final Field f = fields[i]; 92 if (Modifier.isFinal(f.getModifiers()) 93 && Modifier.isPublic(f.getModifiers()) 94 && Modifier.isStatic(f.getModifiers())) { 95 try { 96 final String fieldName = f.getName(); 97 if (fieldName.equals(name)) { 98 return f.get(null); 99 } 100 } 101 catch (Exception e) { 102 Log.info ("Unable to write RenderingHint", e); 103 } 104 } 105 } 106 throw new IllegalArgumentException ("Invalid value given"); 107 } 108 109 116 public Object getObject() throws XmlReaderException { 117 return new Object [] {this.key, this.value}; 118 } 119 120 125 public Object getKey() { 126 return this.key; 127 } 128 129 134 public Object getValue() { 135 return this.value; 136 } 137 138 } 139 | Popular Tags |