1 23 24 package org.enhydra.kelp.forte; 25 26 import org.enhydra.kelp.common.node.PropertyKeys; 27 import org.enhydra.kelp.common.PropUtil; 28 29 import org.enhydra.kelp.forte.node.ForteProject; 30 31 import org.openide.options.SystemOption; 32 import org.openide.util.HelpCtx; 33 import org.openide.util.NbBundle; 34 35 import java.io.*; 36 import java.util.Hashtable ; 37 38 42 public class XMLCSettings extends SystemOption implements PropertyKeys 43 { 44 static final long serialVersionUID = -1412625156769505620L; 45 46 protected Hashtable nodeProps = null; 47 48 public void writeExternal (ObjectOutput out) throws IOException { 49 out.writeObject(propertyValue(XMLC_DOC_TYPES)); 50 out.writeObject(propertyValue(XMLC_BUILD)); 51 out.writeObject(propertyValue(XMLC_PRINT_DOM)); 52 out.writeObject(propertyValue(XMLC_PRINT_PARSE)); 53 out.writeObject(propertyValue(XMLC_PRINT_DOC)); 54 out.writeObject(propertyValue(XMLC_VERBOSE)); 55 out.writeObject(propertyValue(XMLC_PRINT_ACCESSOR)); 56 out.writeObject(propertyValue(XMLC_OUTPUT_FILENAME)); 57 out.writeObject(propertyValue(XMLC_MAP_PACKAGE_FROM)); 58 out.writeObject(propertyValue(XMLC_MAP_PACKAGE_TO)); 59 out.writeObject(propertyValue(XMLC_MAP_PACKAGE_LENGTH)); 60 out.writeObject(propertyValue(XMLC_MAP_SCOPE)); 61 out.writeObject(propertyValue(NAME_XMLC_OPTION_FILEPATH)); 62 out.writeObject(propertyValue(NAME_XMLC_PARAMETERS)); 63 out.writeObject(propertyValue(PROP_PROJECT_ROOT)); 64 out.writeObject(propertyValue(PROP_SRC_DIR)); 65 out.writeObject(nodeProps); 66 } 67 68 public void readExternal (ObjectInput in) throws IOException, ClassNotFoundException { 69 setProperty(XMLC_DOC_TYPES, (String )in.readObject()); 70 setProperty(XMLC_BUILD, (String )in.readObject()); 71 setProperty(XMLC_PRINT_DOM, (String )in.readObject()); 72 setProperty(XMLC_PRINT_PARSE, (String )in.readObject()); 73 setProperty(XMLC_PRINT_DOC, (String )in.readObject()); 74 setProperty(XMLC_VERBOSE, (String )in.readObject()); 75 setProperty(XMLC_PRINT_ACCESSOR, (String )in.readObject()); 76 setProperty(XMLC_OUTPUT_FILENAME, (String )in.readObject()); 77 setProperty(XMLC_MAP_PACKAGE_FROM, (String )in.readObject()); 78 setProperty(XMLC_MAP_PACKAGE_TO, (String )in.readObject()); 79 setProperty(XMLC_MAP_PACKAGE_LENGTH, (String )in.readObject()); 80 setProperty(XMLC_MAP_SCOPE, (String )in.readObject()); 81 setProperty(NAME_XMLC_OPTION_FILEPATH, (String )in.readObject()); 82 setProperty(NAME_XMLC_PARAMETERS, (String )in.readObject()); 83 setProperty(PROP_PROJECT_ROOT, (String )in.readObject()); 84 setProperty(PROP_SRC_DIR, (String )in.readObject()); 85 86 try { 87 nodeProps = (Hashtable )in.readObject(); 88 } catch (OptionalDataException e) { 89 if (nodeProps == null) 90 nodeProps = new Hashtable (); 91 } 92 } 93 94 95 public String displayName () { 96 return NbBundle.getMessage (XMLCSettings.class, "LBL_xmlc_settings"); 97 } 98 99 public HelpCtx getHelpCtx () { 100 return HelpCtx.DEFAULT_HELP; 101 } 104 105 106 public static XMLCSettings getDefault () 107 { 108 return (XMLCSettings) findObject (XMLCSettings.class, true); 109 } 110 111 public void setProperty(String key, String value) 112 { 113 putProperty(key, value, true); 114 } 115 116 public String propertyValue(String key) 117 { 118 return (String )getProperty(key); 119 } 120 121 public void setNodeProperty(String key, String prop) 122 { 123 if (nodeProps == null) 124 nodeProps = new Hashtable (); 125 126 if (prop != null) 127 try { 128 nodeProps.put(key, prop); 129 }catch (NullPointerException e) { 130 System.err.println(e); 131 } 132 else 133 nodeProps.remove(key); 134 } 135 136 public String getNodeProperty(String key) 137 { 138 if (nodeProps != null) 139 { 140 String res = (String )nodeProps.get(key); 141 return res; 142 } 143 144 return null; 145 } 146 147 public boolean isGlobal(){ 148 return false; 149 } 150 public String getRoot() 152 { 153 ForteProject proj = new ForteProject(); 154 String cur = propertyValue(PROP_PROJECT_ROOT); 155 if ((cur == null) || (cur.length() <= 0)) 156 { 157 cur = proj.getDefaultRoot(); 158 if (cur != null) 159 setRoot(cur); 160 } 161 if (! proj.inProject(cur)) 162 { 163 cur = proj.getDefaultRoot(); 164 if (cur != null) 165 setRoot(cur); 166 } 167 168 return cur; 169 } 170 171 public void setRoot(String root) 172 { 173 setProperty(PROP_PROJECT_ROOT, root); 174 } 175 public String getSource() 177 { 178 String res = propertyValue(PROP_SRC_DIR); 179 if ((res == null) || (res.length() <= 0)) 180 { 181 res = "src"; 182 setSource(res); 183 } 184 return res; 185 } 186 187 public void setSource(String src) 188 { 189 setProperty(PROP_SRC_DIR, src); 190 } 191 192 206 207 } 208 | Popular Tags |