1 package org.ozoneDB.xml.dom4j.o3impl; 9 10 import org.dom4j.*; 11 import org.ozoneDB.OzoneCompatible; 12 import org.ozoneDB.OzoneInterface; 13 import org.ozoneDB.OzoneRemote; 14 import org.ozoneDB.OzoneRemoteException; 15 import org.ozoneDB.xml.dom4j.OzoneBranch; 16 import org.ozoneDB.xml.dom4j.OzoneDocumentFactory; 17 import org.ozoneDB.xml.dom4j.OzoneElement; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 26 27 public class OzoneElementImpl extends DefaultElement implements OzoneElement, OzoneCompatible { 28 29 final static long serialVersionUID = 1L; 30 31 private void init() { 32 } 33 34 public OzoneElementImpl(String name) { 35 super(name); 36 init(); 37 } 38 39 public static OzoneElement create(OzoneInterface db, String name) { 40 System.out.println("[OzoneElementImpl] Creating new object"); 41 return (OzoneElement) db.createObject(OzoneElementImpl.class, 42 new Class [] {String .class}, 43 new Object []{name}); 44 } 45 46 public OzoneElementImpl(QName qname) { 47 super(qname); 48 init(); 49 } 50 51 public static OzoneElement create(OzoneInterface db, QName qname) { 52 return (OzoneElement) db.createObject(OzoneElementImpl.class, 53 new Class [] {QName.class}, 54 new Object []{qname}); 55 } 56 57 public OzoneElementImpl(QName qname, int attributeCount) { 58 super(qname, attributeCount); 59 init(); 60 } 61 62 public static OzoneElement create(OzoneInterface db, QName qname, int attributeCount) { 63 final Class [] signature = new Class [] {QName.class, int.class}; 64 return (OzoneElement) db.createObject(OzoneElementImpl.class, 65 signature, 66 new Object []{qname, new Integer (attributeCount)}); 67 } 68 69 public OzoneElementImpl(String name, Namespace namespace) { 70 super(name, namespace); 71 init(); 72 } 73 74 public static OzoneElement create(OzoneInterface db, String name, Namespace namespace) { 75 final Class [] signature = new Class [] {String .class, Namespace.class}; 76 return (OzoneElement) db.createObject(OzoneElementImpl.class, 77 signature, 78 new Object []{name, namespace}); 79 } 80 81 public DocumentFactory getDocumentFactory() { 82 throw new OzoneRemoteException("getDocumentFactory will not work in Ozone"); 83 } 84 85 protected NodeFactory getNodeFactory() { 86 try { 87 return (NodeFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME); 90 } catch (Exception e) { 91 throw new OzoneRemoteException("NodeFctory not registered" + e.toString()); 92 } 93 } 94 95 protected XPathFactory getXPathFactory() { 96 try { 97 return (XPathFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME); 100 } catch (Exception e) { 101 throw new OzoneRemoteException("XPathFactory not registered" + e.toString()); 102 } 103 } 104 105 public Element addAttribute(String name, String value) { 106 Attribute attribute = attribute(name); 108 if (value != null) { 110 if (attribute == null) { 111 Attribute att = getNodeFactory().createAttribute(null, name, value); 114 System.out.println("Attribute created: " + att + ", parent=" + att.getParent()); 115 add(att); 116 } else if (attribute.isReadOnly()) { 117 System.out.println("removing attribute"); 118 remove(attribute); 119 add(getDocumentFactory().createAttribute(null, name, value)); 122 } else { 123 System.out.println("Setting attribute value"); 124 attribute.setValue(value); 125 } 126 } else if (attribute != null) { 127 remove(attribute); 128 } 129 return this; 130 131 } 132 133 public Element addAttribute(QName qName, String value) { 134 Attribute attribute = attribute(qName); 136 if (value != null) { 137 if (attribute == null) { 138 add(getNodeFactory().createAttribute(null, qName, value)); 140 } else if (attribute.isReadOnly()) { 141 remove(attribute); 142 add(getNodeFactory().createAttribute(null, qName, value)); 144 } else { 145 attribute.setValue(value); 146 } 147 } else if (attribute != null) { 148 remove(attribute); 149 } 150 return this; 151 } 152 153 public List attributes() { 154 return new O3ContentListFacade((OzoneBranch) self(), attributeList()); 155 } 156 157 public List content() { 158 List backingList = contentList(); 159 return new O3ContentListFacade((OzoneBranch) self(), backingList); 160 } 161 162 165 public void invalidNodeTypeAddException(Node node) { 166 super.invalidNodeTypeAddException(node); 167 } 168 169 173 public void contentRemoved() { 174 super.contentRemoved(); 175 } 176 177 180 public String getContentAsText(Object content) { 181 return super.getContentAsText(content); 182 } 183 184 186 public String getContentAsStringValue(Object content) { 187 return super.getContentAsStringValue(content); 188 } 189 190 192 public String elementID(Element element) { 193 return super.elementID(element); 194 } 195 196 199 public List createContentList() { 200 return super.createContentList(); 201 } 202 203 206 public List createContentList(int size) { 207 return super.createContentList(size); 208 } 209 210 213 public BackedList createResultList() { 214 return super.createResultList(); 215 } 216 217 220 public List createSingleResultList(Object result) { 221 return super.createSingleResultList(result); 222 } 223 224 227 public List createEmptyList() { 228 return super.createEmptyList(); 229 } 230 231 public void childRemoved(Node node) { 232 super.childRemoved(node); 233 } 234 235 public void childAdded(Node node) { 236 super.childAdded(node); 237 } 238 239 public boolean removeNode(Node node) { 240 return super.removeNode(node); 241 } 242 243 public void addNode(Node node) { 244 super.addNode(node); 245 } 246 247 public List contentList() { 248 return super.contentList(); 249 } 250 251 public void addNode(int index, Node node) { 252 super.addNode(index, node); 253 } 254 255 256 262 public Object clone() { 263 try { 264 Element answer = (Element) database().copyObject(self()); 265 answer.setDocument(null); 266 answer.setParent(null); 267 answer.setContent(null); 270 answer.setAttributes(null); 271 answer.appendAttributes((Element) self()); 272 answer.appendContent((Element) self()); 273 return answer; 274 } catch (Exception e) { 275 e.printStackTrace(); 276 return null; 277 } 278 } 279 280 public void onCreate() { 281 } 282 283 public void onActivate() { 284 } 285 286 public void onPassivate() { 287 } 288 289 public void onDelete() { 290 OzoneInterface db = database(); 291 List contentList = content(); 296 OzoneRemote content; 297 for (Iterator it = contentList.iterator(); it.hasNext();) { 298 Object obj = it.next(); 299 System.out.println("deleting " + obj.getClass()); 300 content = (OzoneRemote) obj; 301 db.deleteObject(content); 302 } 303 } 304 } 305 | Popular Tags |