1 19 20 package org.netbeans.upgrade.systemoptions; 21 22 import java.util.HashMap ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 import java.util.logging.Level ; 26 import java.util.logging.Logger ; 27 28 class ContentProcessor { 29 private static Map <String , ContentProcessor> clsname2Delegate = new HashMap <String , ContentProcessor>(); 30 protected String systemOptionInstanceName; 31 32 static { 33 registerContentProcessor(new JUnitContentProcessor("org.netbeans.modules.junit.JUnitSettings")); } 35 36 private static void registerContentProcessor(ContentProcessor instance) { 37 if (clsname2Delegate.put(instance.systemOptionInstanceName, instance) != null) { 38 throw new IllegalArgumentException (); 39 } 40 } 41 42 43 protected ContentProcessor(String systemOptionInstanceName) { 44 this.systemOptionInstanceName = systemOptionInstanceName; 45 } 46 47 protected Result parseContent(final Iterator <Object > it, boolean types) { 48 Map <String , String > m; 49 Result result = null; 50 try { 51 Map <String , Object > props = parseProperties(it); 52 assert props != null; 53 m = processProperties(props, types); 55 result = new DefaultResult(systemOptionInstanceName, m); 57 } catch (IllegalStateException isx) { 58 Logger.getLogger(ContentProcessor.class.getName()).log(Level.WARNING, systemOptionInstanceName + " not parsed", isx); 59 } 60 return result; 61 } 62 63 static Result parseContent(String systemOptionInstanceName, boolean types, final Iterator <Object > it) { 64 ContentProcessor cp = clsname2Delegate.get(systemOptionInstanceName); 65 if (cp == null) { 66 cp = new ContentProcessor(systemOptionInstanceName); 67 } 68 return cp.parseContent(it, types); 69 } 70 71 private final Map <String , String > processProperties(final Map <String , Object > properties, boolean types) { 72 Map <String , String > allProps = new HashMap <String , String >(); 73 for (Iterator <Map.Entry <String , Object >> it = properties.entrySet().iterator(); it.hasNext();) { 74 Map.Entry <String , Object > entry = it.next(); 75 String name = entry.getKey(); 76 Object value = entry.getValue(); 77 allProps.putAll(PropertyProcessor.processProperty(name, value, types)); 78 } 79 return allProps; 80 } 81 82 private final Map <String , Object > parseProperties(final Iterator <Object > it) { Map <String , Object > properties = new HashMap <String , Object >(); 84 for (; it.hasNext();) { 85 Object name = it.next(); 86 if ("null".equals(name) || name == null) { 87 return properties; 89 } else if (!(name instanceof String )) { 90 throw new IllegalStateException (name.getClass().getName()); 91 } else { 92 if (!it.hasNext()) { 93 throw new IllegalStateException (name.toString()); 94 } 95 Object value = it.next(); 96 properties.put((String )name, value); 97 Object propertyRead = it.next(); 98 if (!(propertyRead instanceof SerParser.ObjectWrapper )) { 99 throw new IllegalStateException (propertyRead.getClass().getName()); 100 } else { 101 SerParser.ObjectWrapper ow = (SerParser.ObjectWrapper)propertyRead; 102 if (!ow.classdesc.name.endsWith("java.lang.Boolean;")) { throw new IllegalStateException (ow.classdesc.name); 104 } 105 } 106 } 107 } 108 throw new IllegalStateException ("Unexpected end"); } 110 } 111 | Popular Tags |