1 19 20 37 38 package org.netbeans.modules.j2ee.sun.validation.constraints.data; 39 40 import org.w3c.dom.*; 41 import org.netbeans.modules.schema2beans.*; 42 import java.beans.*; 43 import java.util.*; 44 import java.io.*; 45 46 48 public class Constraints extends org.netbeans.modules.schema2beans.BaseBean 49 { 50 51 static Vector comparators = new Vector(); 52 53 static public final String CHECK_INFO = "CheckInfo"; 55 public Constraints() throws org.netbeans.modules.schema2beans.Schema2BeansException { 56 this(null, Common.USE_DEFAULT_VALUES); 57 } 58 59 public Constraints(org.w3c.dom.Node doc, int options) throws org.netbeans.modules.schema2beans.Schema2BeansException { 60 this(Common.NO_DEFAULT_VALUES); 61 initFromNode(doc, options); 62 } 63 protected void initFromNode(org.w3c.dom.Node doc, int options) throws Schema2BeansException 64 { 65 if (doc == null) 66 { 67 doc = GraphManager.createRootElementNode("constraints"); if (doc == null) 69 throw new Schema2BeansException(Common.getMessage( 70 "CantCreateDOMRoot_msg", "constraints")); 71 } 72 Node n = GraphManager.getElementNode("constraints", doc); if (n == null) 74 throw new Schema2BeansException(Common.getMessage( 75 "DocRootNotInDOMGraph_msg", "constraints", doc.getFirstChild().getNodeName())); 76 77 this.graphManager.setXmlDocument(doc); 78 79 this.createBean(n, this.graphManager()); 81 this.initialize(options); 82 } 83 public Constraints(int options) 84 { 85 super(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 86 initOptions(options); 87 } 88 protected void initOptions(int options) 89 { 90 this.graphManager = new GraphManager(this); 92 this.createRoot("constraints", "Constraints", Common.TYPE_1 | Common.TYPE_BEAN, Constraints.class); 94 95 this.createProperty("check-info", CHECK_INFO, 98 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 99 CheckInfo.class); 100 this.initialize(options); 101 } 102 103 void initialize(int options) 105 { 106 107 } 108 109 public void setCheckInfo(int index, CheckInfo value) { 111 this.setValue(CHECK_INFO, index, value); 112 } 113 114 public CheckInfo getCheckInfo(int index) { 116 return (CheckInfo)this.getValue(CHECK_INFO, index); 117 } 118 119 public void setCheckInfo(CheckInfo[] value) { 121 this.setValue(CHECK_INFO, value); 122 } 123 124 public CheckInfo[] getCheckInfo() { 126 return (CheckInfo[])this.getValues(CHECK_INFO); 127 } 128 129 public int sizeCheckInfo() { 131 return this.size(CHECK_INFO); 132 } 133 134 public int addCheckInfo(org.netbeans.modules.j2ee.sun.validation.constraints.data.CheckInfo value) { 136 return this.addValue(CHECK_INFO, value); 137 } 138 139 public int removeCheckInfo(org.netbeans.modules.j2ee.sun.validation.constraints.data.CheckInfo value) { 144 return this.removeValue(CHECK_INFO, value); 145 } 146 147 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 149 comparators.add(c); 150 } 151 152 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 154 comparators.remove(c); 155 } 156 public static Constraints createGraph(org.w3c.dom.Node doc) throws org.netbeans.modules.schema2beans.Schema2BeansException { 161 return new Constraints(doc, Common.NO_DEFAULT_VALUES); 162 } 163 164 public static Constraints createGraph(java.io.InputStream in) throws org.netbeans.modules.schema2beans.Schema2BeansException { 165 return createGraph(in, false); 166 } 167 168 public static Constraints createGraph(java.io.InputStream in, boolean validate) throws org.netbeans.modules.schema2beans.Schema2BeansException { 169 Document doc = GraphManager.createXmlDocument(in, validate); 170 return createGraph(doc); 171 } 172 173 public static Constraints createGraph() { 177 try { 178 return new Constraints(); 179 } 180 catch (Schema2BeansException e) { 181 throw new RuntimeException (e.getMessage()); 182 } 183 } 184 185 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 186 boolean restrictionFailure = false; 187 for (int _index = 0; _index < sizeCheckInfo(); ++_index) { 189 org.netbeans.modules.j2ee.sun.validation.constraints.data.CheckInfo element = getCheckInfo(_index); 190 if (element != null) { 191 element.validate(); 192 } 193 } 194 } 195 196 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 198 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 199 write(baos); 200 String str = baos.toString();; 201 out.writeUTF(str); 203 } 204 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 206 try{ 207 init(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 208 String strDocument = in.readUTF(); 209 ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes()); 211 Document doc = GraphManager.createXmlDocument(bais, false); 212 initOptions(Common.NO_DEFAULT_VALUES); 213 initFromNode(doc, Common.NO_DEFAULT_VALUES); 214 } 215 catch (Schema2BeansException e) { 216 e.printStackTrace(); 217 throw new RuntimeException (e.getMessage()); 218 } 219 } 220 221 public void dump(StringBuffer str, String indent){ 223 String s; 224 Object o; 225 org.netbeans.modules.schema2beans.BaseBean n; 226 str.append(indent); 227 str.append("CheckInfo["+this.sizeCheckInfo()+"]"); for(int i=0; i<this.sizeCheckInfo(); i++) 229 { 230 str.append(indent+"\t"); 231 str.append("#"+i+":"); 232 n = (org.netbeans.modules.schema2beans.BaseBean) this.getCheckInfo(i); 233 if (n != null) 234 n.dump(str, indent + "\t"); else 236 str.append(indent+"\tnull"); this.dumpAttributes(CHECK_INFO, i, str, indent); 238 } 239 240 } 241 public String dumpBeanNode(){ 242 StringBuffer str = new StringBuffer (); 243 str.append("Constraints\n"); this.dump(str, "\n "); return str.toString(); 246 }} 247 248 250 251 327 | Popular Tags |