1 19 20 package org.netbeans.upgrade.systemoptions; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 26 abstract class PropertyProcessor { 27 private String className; 28 private static Map <String , String > results; 29 private static Map <String , PropertyProcessor> clsname2Delegate = new HashMap <String , PropertyProcessor>(); 30 31 static { 32 registerPropertyProcessor(new TaskTagsProcessor()); 34 registerPropertyProcessor(new HostPropertyProcessor()); 35 registerPropertyProcessor(new FileProcessor()); registerPropertyProcessor(new NbClassPathProcessor()); registerPropertyProcessor(new HashMapProcessor()); registerPropertyProcessor(new IntrospectedInfoProcessor()); registerPropertyProcessor(new ListProcessor()); registerPropertyProcessor(new URLProcessor()); registerPropertyProcessor(new ColorProcessor()); registerPropertyProcessor(new StringPropertyProcessor()); } 44 45 46 private static void registerPropertyProcessor(PropertyProcessor instance) { 47 if (clsname2Delegate.put(instance.className, instance) != null) { 48 throw new IllegalArgumentException (); 49 } 50 } 51 52 private static PropertyProcessor DEFAULT = new PropertyProcessor(false) { 53 void processPropertyImpl(final String propertyName, final Object value) { 54 String stringvalue = null; 55 stringvalue = Utils.valueFromObjectWrapper(value); 56 addProperty(propertyName, stringvalue); 57 } 58 }; 59 60 private static PropertyProcessor TYPES = new PropertyProcessor(true) { 61 void processPropertyImpl(final String propertyName, final Object value) { 62 addProperty(propertyName, Utils.getClassNameFromObject(value)); 63 } 64 }; 65 66 private boolean types; 67 68 69 private PropertyProcessor(boolean types) { 70 this.types = types; 71 } 72 73 protected PropertyProcessor(String className) { 74 this(false); 75 this.className = className; 76 } 77 78 static Map <String , String > processProperty(String propertyName, Object value, boolean types) { 79 results = new HashMap <String , String >(); 80 PropertyProcessor p = (types) ? TYPES : findDelegate(value); 81 if (p == null) { 82 p = DEFAULT; 83 } 84 assert p != null; 85 p.processPropertyImpl(propertyName, value); 86 return results; 87 } 88 89 abstract void processPropertyImpl(String propertyName, Object value); 90 91 protected final void addProperty(String propertyName, String value) { 92 if (results.put(propertyName, value) != null) { 93 throw new IllegalArgumentException (propertyName); 94 } 95 } 96 97 private static PropertyProcessor findDelegate(final Object value) { 98 String clsName = Utils.getClassNameFromObject(value); 99 return (PropertyProcessor)clsname2Delegate.get(clsName); 100 } 101 } | Popular Tags |