1 19 41 42 package org.netbeans.modules.j2ee.sun.dd.impl.transform; 43 44 import org.w3c.dom.*; 45 import org.netbeans.modules.schema2beans.*; 46 import java.beans.*; 47 import java.util.*; 48 import java.io.*; 49 50 52 public class Transform extends org.netbeans.modules.schema2beans.BaseBean 53 { 54 55 static Vector comparators = new Vector(); 56 private static final org.netbeans.modules.schema2beans.Version runtimeVersion = new org.netbeans.modules.schema2beans.Version(4, 2, 0); 57 58 static public final String XMLTYPE = "Xmltype"; 60 public Transform() throws org.netbeans.modules.schema2beans.Schema2BeansException { 61 this(null, Common.USE_DEFAULT_VALUES); 62 } 63 64 public Transform(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("transform"); if (doc == null) 74 throw new Schema2BeansException(Common.getMessage( 75 "CantCreateDOMRoot_msg", "transform")); 76 } 77 Node n = GraphManager.getElementNode("transform", doc); if (n == null) 79 throw new Schema2BeansException(Common.getMessage( 80 "DocRootNotInDOMGraph_msg", "transform", doc.getFirstChild().getNodeName())); 81 82 this.graphManager.setXmlDocument(doc); 83 84 this.createBean(n, this.graphManager()); 86 this.initialize(options); 87 } 88 public Transform(int options) 89 { 90 super(comparators, runtimeVersion); 91 initOptions(options); 92 } 93 protected void initOptions(int options) 94 { 95 this.graphManager = new GraphManager(this); 97 this.createRoot("transform", "Transform", Common.TYPE_1 | Common.TYPE_BEAN, Transform.class); 99 100 initPropertyTables(1); 102 this.createProperty("xmltype", XMLTYPE, 104 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 105 Xmltype.class); 106 this.initialize(options); 107 } 108 109 void initialize(int options) { 111 112 } 113 114 public void setXmltype(int index, Xmltype value) { 116 this.setValue(XMLTYPE, index, value); 117 } 118 119 public Xmltype getXmltype(int index) { 121 return (Xmltype)this.getValue(XMLTYPE, index); 122 } 123 124 public int sizeXmltype() { 126 return this.size(XMLTYPE); 127 } 128 129 public void setXmltype(Xmltype[] value) { 131 this.setValue(XMLTYPE, value); 132 } 133 134 public Xmltype[] getXmltype() { 136 return (Xmltype[])this.getValues(XMLTYPE); 137 } 138 139 public int addXmltype(Xmltype value) { 141 int positionOfNewItem = this.addValue(XMLTYPE, value); 142 return positionOfNewItem; 143 } 144 145 public int removeXmltype(Xmltype value) { 150 return this.removeValue(XMLTYPE, value); 151 } 152 153 157 public Xmltype newXmltype() { 158 return new Xmltype(); 159 } 160 161 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 163 comparators.add(c); 164 } 165 166 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 168 comparators.remove(c); 169 } 170 public static Transform createGraph(org.w3c.dom.Node doc) throws org.netbeans.modules.schema2beans.Schema2BeansException { 175 return new Transform(doc, Common.NO_DEFAULT_VALUES); 176 } 177 178 public static Transform createGraph(java.io.File f) throws org.netbeans.modules.schema2beans.Schema2BeansException, java.io.IOException { 179 java.io.InputStream in = new java.io.FileInputStream (f); 180 try { 181 return createGraph(in, false); 182 } finally { 183 in.close(); 184 } 185 } 186 187 public static Transform createGraph(java.io.InputStream in) throws org.netbeans.modules.schema2beans.Schema2BeansException { 188 return createGraph(in, false); 189 } 190 191 public static Transform createGraph(java.io.InputStream in, boolean validate) throws org.netbeans.modules.schema2beans.Schema2BeansException { 192 Document doc = GraphManager.createXmlDocument(in, validate); 193 return createGraph(doc); 194 } 195 196 public static Transform createGraph() { 200 try { 201 return new Transform(); 202 } 203 catch (Schema2BeansException e) { 204 throw new RuntimeException (e); 205 } 206 } 207 208 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 209 boolean restrictionFailure = false; 210 boolean restrictionPassed = false; 211 for (int _index = 0; _index < sizeXmltype(); ++_index) { 213 Xmltype element = getXmltype(_index); 214 if (element != null) { 215 element.validate(); 216 } 217 } 218 } 219 220 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 222 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 223 write(baos); 224 String str = baos.toString();; 225 out.writeUTF(str); 227 } 228 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 230 try{ 231 init(comparators, runtimeVersion); 232 String strDocument = in.readUTF(); 233 ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes()); 235 Document doc = GraphManager.createXmlDocument(bais, false); 236 initOptions(Common.NO_DEFAULT_VALUES); 237 initFromNode(doc, Common.NO_DEFAULT_VALUES); 238 } 239 catch (Schema2BeansException e) { 240 throw new RuntimeException (e); 241 } 242 } 243 244 public void _setSchemaLocation(String location) { 245 if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) { 246 createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA | AttrProp.IMPLIED, null, "http://www.w3.org/2001/XMLSchema-instance"); 247 setAttributeValue("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 248 createAttribute("xsi:schemaLocation", "xsi:schemaLocation", AttrProp.CDATA | AttrProp.IMPLIED, null, location); 249 } 250 setAttributeValue("xsi:schemaLocation", location); 251 } 252 253 public String _getSchemaLocation() { 254 if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) { 255 createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA | AttrProp.IMPLIED, null, "http://www.w3.org/2001/XMLSchema-instance"); 256 setAttributeValue("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 257 createAttribute("xsi:schemaLocation", "xsi:schemaLocation", AttrProp.CDATA | AttrProp.IMPLIED, null, null); 258 } 259 return getAttributeValue("xsi:schemaLocation"); 260 } 261 262 public void dump(StringBuffer str, String indent){ 264 String s; 265 Object o; 266 org.netbeans.modules.schema2beans.BaseBean n; 267 str.append(indent); 268 str.append("Xmltype["+this.sizeXmltype()+"]"); for(int i=0; i<this.sizeXmltype(); i++) 270 { 271 str.append(indent+"\t"); 272 str.append("#"+i+":"); 273 n = (org.netbeans.modules.schema2beans.BaseBean) this.getXmltype(i); 274 if (n != null) 275 n.dump(str, indent + "\t"); else 277 str.append(indent+"\tnull"); this.dumpAttributes(XMLTYPE, i, str, indent); 279 } 280 281 } 282 public String dumpBeanNode(){ 283 StringBuffer str = new StringBuffer (); 284 str.append("Transform\n"); this.dump(str, "\n "); return str.toString(); 287 }} 288 289 291 292 317 | Popular Tags |