1 19 20 39 40 package org.netbeans.modules.j2ee.sun.validation.data; 41 42 import org.w3c.dom.*; 43 import org.netbeans.modules.schema2beans.*; 44 import java.beans.*; 45 import java.util.*; 46 import java.io.*; 47 48 50 public class Validation extends org.netbeans.modules.schema2beans.BaseBean 51 { 52 53 static Vector comparators = new Vector(); 54 55 static public final String VALIDATE = "Validate"; static public final String ELEMENT = "Element"; 58 public Validation() throws org.netbeans.modules.schema2beans.Schema2BeansException { 59 this(null, Common.USE_DEFAULT_VALUES); 60 } 61 62 public Validation(org.w3c.dom.Node doc, int options) throws org.netbeans.modules.schema2beans.Schema2BeansException { 63 this(Common.NO_DEFAULT_VALUES); 64 initFromNode(doc, options); 65 } 66 protected void initFromNode(org.w3c.dom.Node doc, int options) throws Schema2BeansException 67 { 68 if (doc == null) 69 { 70 doc = GraphManager.createRootElementNode("validation"); if (doc == null) 72 throw new Schema2BeansException(Common.getMessage( 73 "CantCreateDOMRoot_msg", "validation")); 74 } 75 Node n = GraphManager.getElementNode("validation", doc); if (n == null) 77 throw new Schema2BeansException(Common.getMessage( 78 "DocRootNotInDOMGraph_msg", "validation", doc.getFirstChild().getNodeName())); 79 80 this.graphManager.setXmlDocument(doc); 81 82 this.createBean(n, this.graphManager()); 84 this.initialize(options); 85 } 86 public Validation(int options) 87 { 88 super(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 89 initOptions(options); 90 } 91 protected void initOptions(int options) 92 { 93 this.graphManager = new GraphManager(this); 95 this.createRoot("validation", "Validation", Common.TYPE_1 | Common.TYPE_BEAN, Validation.class); 97 98 this.createProperty("element", ELEMENT, 101 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 102 Element.class); 103 this.createAttribute("validate", "Validate", 104 AttrProp.ENUM, 105 new String [] { 106 "true", 107 "false" 108 }, "true"); 109 this.initialize(options); 110 } 111 112 void initialize(int options) 114 { 115 116 } 117 118 public void setValidate(java.lang.String value) { 120 setAttributeValue(VALIDATE, value); 121 } 122 123 public java.lang.String getValidate() { 125 return getAttributeValue(VALIDATE); 126 } 127 128 public void setElement(int index, Element value) { 130 this.setValue(ELEMENT, index, value); 131 } 132 133 public Element getElement(int index) { 135 return (Element)this.getValue(ELEMENT, index); 136 } 137 138 public void setElement(Element[] value) { 140 this.setValue(ELEMENT, value); 141 } 142 143 public Element[] getElement() { 145 return (Element[])this.getValues(ELEMENT); 146 } 147 148 public int sizeElement() { 150 return this.size(ELEMENT); 151 } 152 153 public int addElement(org.netbeans.modules.j2ee.sun.validation.data.Element value) { 155 return this.addValue(ELEMENT, value); 156 } 157 158 public int removeElement(org.netbeans.modules.j2ee.sun.validation.data.Element value) { 163 return this.removeValue(ELEMENT, value); 164 } 165 166 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 168 comparators.add(c); 169 } 170 171 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 173 comparators.remove(c); 174 } 175 public static Validation createGraph(org.w3c.dom.Node doc) throws org.netbeans.modules.schema2beans.Schema2BeansException { 180 return new Validation(doc, Common.NO_DEFAULT_VALUES); 181 } 182 183 public static Validation createGraph(java.io.InputStream in) throws org.netbeans.modules.schema2beans.Schema2BeansException { 184 return createGraph(in, false); 185 } 186 187 public static Validation createGraph(java.io.InputStream in, boolean validate) throws org.netbeans.modules.schema2beans.Schema2BeansException { 188 Document doc = GraphManager.createXmlDocument(in, validate); 189 return createGraph(doc); 190 } 191 192 public static Validation createGraph() { 196 try { 197 return new Validation(); 198 } 199 catch (Schema2BeansException e) { 200 throw new RuntimeException (e.getMessage()); 201 } 202 } 203 204 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 205 boolean restrictionFailure = false; 206 if (getValidate() == null) { 208 throw new org.netbeans.modules.schema2beans.ValidateException("getValidate() == null", "validate", this); } 210 for (int _index = 0; _index < sizeElement(); ++_index) { 212 org.netbeans.modules.j2ee.sun.validation.data.Element element = getElement(_index); 213 if (element != null) { 214 element.validate(); 215 } 216 } 217 } 218 219 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 221 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 222 write(baos); 223 String str = baos.toString();; 224 out.writeUTF(str); 226 } 227 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 229 try{ 230 init(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 231 String strDocument = in.readUTF(); 232 ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes()); 234 Document doc = GraphManager.createXmlDocument(bais, false); 235 initOptions(Common.NO_DEFAULT_VALUES); 236 initFromNode(doc, Common.NO_DEFAULT_VALUES); 237 } 238 catch (Schema2BeansException e) { 239 e.printStackTrace(); 240 throw new RuntimeException (e.getMessage()); 241 } 242 } 243 244 public void dump(StringBuffer str, String indent){ 246 String s; 247 Object o; 248 org.netbeans.modules.schema2beans.BaseBean n; 249 str.append(indent); 250 str.append("Element["+this.sizeElement()+"]"); for(int i=0; i<this.sizeElement(); i++) 252 { 253 str.append(indent+"\t"); 254 str.append("#"+i+":"); 255 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElement(i); 256 if (n != null) 257 n.dump(str, indent + "\t"); else 259 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT, i, str, indent); 261 } 262 263 } 264 public String dumpBeanNode(){ 265 StringBuffer str = new StringBuffer (); 266 str.append("Validation\n"); this.dump(str, "\n "); return str.toString(); 269 }} 270 271 273 274 351 | Popular Tags |