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