1 23 24 44 45 package com.sun.enterprise.tools.common.validation.data; 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 Validation extends org.netbeans.modules.schema2beans.BaseBean 56 { 57 58 static Vector comparators = new Vector(); 59 60 static public final String VALIDATE = "Validate"; static public final String ELEMENT = "Element"; 63 public Validation() throws org.netbeans.modules.schema2beans.Schema2BeansException { 64 this(null, Common.USE_DEFAULT_VALUES); 65 } 66 67 public Validation(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("validation"); if (doc == null) 77 throw new Schema2BeansException(Common.getMessage( 78 "CantCreateDOMRoot_msg", "validation")); 79 } 80 Node n = GraphManager.getElementNode("validation", doc); if (n == null) 82 throw new Schema2BeansException(Common.getMessage( 83 "DocRootNotInDOMGraph_msg", "validation", doc.getFirstChild().getNodeName())); 84 85 this.graphManager.setXmlDocument(doc); 86 87 this.createBean(n, this.graphManager()); 89 this.initialize(options); 90 } 91 public Validation(int options) 92 { 93 super(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 94 initOptions(options); 95 } 96 protected void initOptions(int options) 97 { 98 this.graphManager = new GraphManager(this); 100 this.createRoot("validation", "Validation", Common.TYPE_1 | Common.TYPE_BEAN, Validation.class); 102 103 this.createProperty("element", ELEMENT, 106 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 107 Element.class); 108 this.createAttribute("validate", "Validate", 109 AttrProp.ENUM, 110 new String [] { 111 "true", 112 "false" 113 }, "true"); 114 this.initialize(options); 115 } 116 117 void initialize(int options) 119 { 120 121 } 122 123 public void setValidate(java.lang.String value) { 125 setAttributeValue(VALIDATE, value); 126 } 127 128 public java.lang.String getValidate() { 130 return getAttributeValue(VALIDATE); 131 } 132 133 public void setElement(int index, Element value) { 135 this.setValue(ELEMENT, index, value); 136 } 137 138 public Element getElement(int index) { 140 return (Element)this.getValue(ELEMENT, index); 141 } 142 143 public void setElement(Element[] value) { 145 this.setValue(ELEMENT, value); 146 } 147 148 public Element[] getElement() { 150 return (Element[])this.getValues(ELEMENT); 151 } 152 153 public int sizeElement() { 155 return this.size(ELEMENT); 156 } 157 158 public int addElement(com.sun.enterprise.tools.common.validation.data.Element value) { 160 return this.addValue(ELEMENT, value); 161 } 162 163 public int removeElement(com.sun.enterprise.tools.common.validation.data.Element value) { 168 return this.removeValue(ELEMENT, 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 Validation createGraph(org.w3c.dom.Node doc) throws org.netbeans.modules.schema2beans.Schema2BeansException { 185 return new Validation(doc, Common.NO_DEFAULT_VALUES); 186 } 187 188 public static Validation createGraph(java.io.InputStream in) throws org.netbeans.modules.schema2beans.Schema2BeansException { 189 return createGraph(in, false); 190 } 191 192 public static Validation 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 Validation createGraph() { 201 try { 202 return new Validation(); 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 boolean restrictionFailure = false; 211 if (getValidate() == null) { 213 throw new org.netbeans.modules.schema2beans.ValidateException("getValidate() == null", "validate", this); } 215 for (int _index = 0; _index < sizeElement(); ++_index) { 217 com.sun.enterprise.tools.common.validation.data.Element element = getElement(_index); 218 if (element != null) { 219 element.validate(); 220 } 221 } 222 } 223 224 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 226 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 227 write(baos); 228 String str = baos.toString();; 229 out.writeUTF(str); 231 } 232 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 234 try{ 235 init(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 236 String strDocument = in.readUTF(); 237 ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes()); 239 Document doc = GraphManager.createXmlDocument(bais, false); 240 initOptions(Common.NO_DEFAULT_VALUES); 241 initFromNode(doc, Common.NO_DEFAULT_VALUES); 242 } 243 catch (Schema2BeansException e) { 244 e.printStackTrace(); 245 throw new RuntimeException (e.getMessage()); 246 } 247 } 248 249 public void dump(StringBuffer str, String indent){ 251 String s; 252 Object o; 253 org.netbeans.modules.schema2beans.BaseBean n; 254 str.append(indent); 255 str.append("Element["+this.sizeElement()+"]"); for(int i=0; i<this.sizeElement(); i++) 257 { 258 str.append(indent+"\t"); 259 str.append("#"+i+":"); 260 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElement(i); 261 if (n != null) 262 n.dump(str, indent + "\t"); else 264 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT, i, str, indent); 266 } 267 268 } 269 public String dumpBeanNode(){ 270 StringBuffer str = new StringBuffer (); 271 str.append("Validation\n"); this.dump(str, "\n "); return str.toString(); 274 }} 275 276 278 279 356 | Popular Tags |