1 19 44 45 package org.netbeans.modules.j2ee.sun.sunresources.beans; 46 47 import org.w3c.dom.*; 48 import org.netbeans.modules.schema2beans.*; 49 import java.beans.*; 50 import java.util.*; 51 import java.io.*; 52 53 55 public class Wizard extends org.netbeans.modules.schema2beans.BaseBean 56 { 57 58 static Vector comparators = new Vector(); 59 60 static public final String NAME = "Name"; static public final String FIELD_GROUP = "FieldGroup"; 63 public Wizard() throws org.netbeans.modules.schema2beans.Schema2BeansException { 64 this(null, Common.USE_DEFAULT_VALUES); 65 } 66 67 public Wizard(org.w3c.dom.Node doc, int options) throws org.netbeans.modules.schema2beans.Schema2BeansException { 68 this(Common.NO_DEFAULT_VALUES); 69 initFromNode(doc, options); 70 } 71 protected void initFromNode(org.w3c.dom.Node doc, int options) throws Schema2BeansException 72 { 73 if (doc == null) 74 { 75 doc = GraphManager.createRootElementNode("wizard"); if (doc == null){ 77 throw new Schema2BeansException(Common.getMessage( 78 "CantCreateDOMRoot_msg", "wizard")); 79 } 80 } 81 Node n = GraphManager.getElementNode("wizard", doc); if (n == null){ 83 throw new Schema2BeansException(Common.getMessage( 84 "DocRootNotInDOMGraph_msg", "wizard", doc.getFirstChild().getNodeName())); 85 } 86 87 this.graphManager.setXmlDocument(doc); 88 89 this.createBean(n, this.graphManager()); 91 this.initialize(options); 92 } 93 public Wizard(int options) 94 { 95 super(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 96 initOptions(options); 97 } 98 protected void initOptions(int options) 99 { 100 this.graphManager = new GraphManager(this); 102 this.createRoot("wizard", "Wizard", Common.TYPE_1 | Common.TYPE_BEAN, Wizard.class); 104 105 this.createProperty("name", NAME, 108 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY, 109 String .class); 110 this.createProperty("field-group", FIELD_GROUP, 112 Common.TYPE_1_N | Common.TYPE_BEAN | Common.TYPE_KEY, 113 FieldGroup.class); 114 this.initialize(options); 115 } 116 117 void initialize(int options) 119 { 120 121 } 122 123 public void setName(String value) { 125 this.setValue(NAME, value); 126 } 127 128 public String getName() { 130 return (String )this.getValue(NAME); 131 } 132 133 public void setFieldGroup(int index, FieldGroup value) { 135 this.setValue(FIELD_GROUP, index, value); 136 } 137 138 public FieldGroup getFieldGroup(int index) { 140 return (FieldGroup)this.getValue(FIELD_GROUP, index); 141 } 142 143 public void setFieldGroup(FieldGroup[] value) { 145 this.setValue(FIELD_GROUP, value); 146 } 147 148 public FieldGroup[] getFieldGroup() { 150 return (FieldGroup[])this.getValues(FIELD_GROUP); 151 } 152 153 public int sizeFieldGroup() { 155 return this.size(FIELD_GROUP); 156 } 157 158 public int addFieldGroup(org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup value) { 160 return this.addValue(FIELD_GROUP, value); 161 } 162 163 public int removeFieldGroup(org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup value) { 168 return this.removeValue(FIELD_GROUP, value); 169 } 170 171 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 173 comparators.add(c); 174 } 175 176 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 178 comparators.remove(c); 179 } 180 public static Wizard createGraph(org.w3c.dom.Node doc) throws org.netbeans.modules.schema2beans.Schema2BeansException { 185 return new Wizard(doc, Common.NO_DEFAULT_VALUES); 186 } 187 188 public static Wizard createGraph(java.io.InputStream in) throws org.netbeans.modules.schema2beans.Schema2BeansException { 189 return createGraph(in, false); 190 } 191 192 public static Wizard createGraph(java.io.InputStream in, boolean validate) throws org.netbeans.modules.schema2beans.Schema2BeansException { 193 Document doc = GraphManager.createXmlDocument(in, validate); 194 return createGraph(doc); 195 } 196 197 public static Wizard createGraph() { 201 try { 202 return new Wizard(); 203 } 204 catch (Schema2BeansException e) { 205 throw new RuntimeException (e.getMessage()); 206 } 207 } 208 209 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 210 if (getName() == null) { 212 throw new org.netbeans.modules.schema2beans.ValidateException("getName() == null", "name", this); } 214 if (sizeFieldGroup() == 0) { 216 throw new org.netbeans.modules.schema2beans.ValidateException("sizeFieldGroup() == 0", "fieldGroup", this); } 218 for (int _index = 0; _index < sizeFieldGroup(); ++_index) { 219 org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup element = getFieldGroup(_index); 220 if (element != null) { 221 element.validate(); 222 } 223 } 224 } 225 226 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 228 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 229 write(baos); 230 String str = baos.toString();; 231 out.writeUTF(str); 233 } 234 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 236 try{ 237 init(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 238 String strDocument = in.readUTF(); 239 ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes()); 241 Document doc = GraphManager.createXmlDocument(bais, false); 242 initOptions(Common.NO_DEFAULT_VALUES); 243 initFromNode(doc, Common.NO_DEFAULT_VALUES); 244 } 245 catch (Schema2BeansException e) { 246 e.printStackTrace(); 247 throw new RuntimeException (e.getMessage()); 248 } 249 } 250 251 public void dump(StringBuffer str, String indent){ 253 String s; 254 org.netbeans.modules.schema2beans.BaseBean n; 255 str.append(indent); 256 str.append("Name"); str.append(indent+"\t"); str.append("<"); s = this.getName(); 260 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(NAME, 0, str, indent); 263 264 str.append(indent); 265 str.append("FieldGroup["+this.sizeFieldGroup()+"]"); for(int i=0; i<this.sizeFieldGroup(); i++) 267 { 268 str.append(indent+"\t"); 269 str.append("#"+i+":"); 270 n = (org.netbeans.modules.schema2beans.BaseBean) this.getFieldGroup(i); 271 if (n != null) 272 n.dump(str, indent + "\t"); else 274 str.append(indent+"\tnull"); this.dumpAttributes(FIELD_GROUP, i, str, indent); 276 } 277 278 } 279 public String dumpBeanNode(){ 280 StringBuffer str = new StringBuffer (); 281 str.append("Wizard\n"); this.dump(str, "\n "); return str.toString(); 284 }} 285 286 288 289 309 | Popular Tags |