⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ozoneelementimpl.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: OzoneElementImpl.java,v 1.2 2003/11/20 23:18:41 per_nyfelt Exp $package org.ozoneDB.xml.dom4j.o3impl;import org.dom4j.*;import org.ozoneDB.OzoneCompatible;import org.ozoneDB.OzoneInterface;import org.ozoneDB.OzoneRemote;import org.ozoneDB.OzoneRemoteException;import org.ozoneDB.xml.dom4j.OzoneBranch;import org.ozoneDB.xml.dom4j.OzoneDocumentFactory;import org.ozoneDB.xml.dom4j.OzoneElement;import java.util.Iterator;import java.util.List;/** * * @author Per Nyfelt */public class OzoneElementImpl extends DefaultElement implements OzoneElement, OzoneCompatible {    final static long serialVersionUID = 1L;    private void init() {    }    public OzoneElementImpl(String name) {        super(name);        init();    }    public static OzoneElement create(OzoneInterface db, String name) {        System.out.println("[OzoneElementImpl] Creating new object");        return (OzoneElement) db.createObject(OzoneElementImpl.class,                new Class[] {String.class},                new Object[]{name});    }    public OzoneElementImpl(QName qname) {        super(qname);        init();    }    public static OzoneElement create(OzoneInterface db, QName qname) {        return (OzoneElement) db.createObject(OzoneElementImpl.class,                new Class[] {QName.class},                new Object[]{qname});    }    public OzoneElementImpl(QName qname, int attributeCount) {        super(qname, attributeCount);        init();    }    public static OzoneElement create(OzoneInterface db, QName qname, int attributeCount) {        final Class[] signature = new Class[] {QName.class, int.class};        return (OzoneElement) db.createObject(OzoneElementImpl.class,                signature,                new Object[]{qname, new Integer(attributeCount)});    }    public OzoneElementImpl(String name, Namespace namespace) {        super(name, namespace);        init();    }    public static OzoneElement create(OzoneInterface db, String name, Namespace namespace) {        final Class[] signature = new Class[] {String.class, Namespace.class};        return (OzoneElement) db.createObject(OzoneElementImpl.class,                signature,                new Object[]{name, namespace});    }    public DocumentFactory getDocumentFactory() {        throw new OzoneRemoteException("getDocumentFactory will not work in Ozone");    }    protected NodeFactory getNodeFactory() {        try {            // todo: might be faster to return super.getNodeFactory() if it is instanceof OzoneCompatible first            // before falling back to object for name look-up            return (NodeFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME);        } catch (Exception e) {            throw new OzoneRemoteException("NodeFctory not registered" + e.toString());        }    }    protected XPathFactory getXPathFactory() {        try {            // todo: might be faster to return super.getXPathFactory() if it is instanceof OzoneCompatible first            // before falling back to object for name look-up            return (XPathFactory) database().objectForName(OzoneDocumentFactory.OBJECT_NAME);        } catch (Exception e) {            throw new OzoneRemoteException("XPathFactory not registered" + e.toString());        }    }    public Element addAttribute(String name, String value) {        // adding a null value is equivalent to removing the attribute        Attribute attribute = attribute(name);        //System.out.println("[" + this.getClass().getName() + "] addAttribute(" + name + ", " + value + ") , attribute = " + attribute);        if (value != null) {            if (attribute == null) {                //System.out.println("creating and adding attribute");                //Attribute att = getDocumentFactory().createAttribute(this, name, value);                Attribute att = getNodeFactory().createAttribute(null, name, value);                System.out.println("Attribute created: " + att + ", parent=" + att.getParent());                add(att);            } else if (attribute.isReadOnly()) {                System.out.println("removing attribute");                remove(attribute);                //System.out.println("creating and adding attribute");                //add(getDocumentFactory().createAttribute(this, name, value));                add(getDocumentFactory().createAttribute(null, name, value));            } else {                System.out.println("Setting attribute value");                attribute.setValue(value);            }        } else if (attribute != null) {            remove(attribute);        }        return this;    }    public Element addAttribute(QName qName, String value) {        // adding a null value is equivalent to removing the attribute        Attribute attribute = attribute(qName);        if (value != null) {            if (attribute == null) {                //add(getDocumentFactory().createAttribute(this, qName, value));                add(getNodeFactory().createAttribute(null, qName, value));            } else if (attribute.isReadOnly()) {                remove(attribute);                //add(getDocumentFactory().createAttribute(this, qName, value));                add(getNodeFactory().createAttribute(null, qName, value));            } else {                attribute.setValue(value);            }        } else if (attribute != null) {            remove(attribute);        }        return this;    }    public List attributes() {        return new O3ContentListFacade((OzoneBranch) self(), attributeList());    }    public List content() {        List backingList = contentList();        return new O3ContentListFacade((OzoneBranch) self(), backingList);    }    /** Called when an invalid node has been added.     * Throws an {@link org.dom4j.IllegalAddException}.     */    public void invalidNodeTypeAddException(Node node) {        super.invalidNodeTypeAddException(node);    }    /** Called when the given List content has been removed so     * each node should have its parent and document relationships     * cleared     */    public void contentRemoved() {        super.contentRemoved();    }    /** @return the text value of the given content object     * as text which returns the text value of CDATA, Entity or Text nodes     */    public String getContentAsText(Object content) {        return super.getContentAsText(content);    }    /** @return the XPath defined string-value of the given content object     */    public String getContentAsStringValue(Object content) {        return super.getContentAsStringValue(content);    }    /** @return the ID of the given <code>Element</code>     */    public String elementID(Element element) {        return super.elementID(element);    }    /** A Factory Method pattern which creates     * a List implementation used to store content     */    public List createContentList() {        return super.createContentList();    }    /** A Factory Method pattern which creates     * a List implementation used to store content     */    public List createContentList(int size) {        return super.createContentList(size);    }    /** A Factory Method pattern which creates     * a BackedList implementation used to store results of     * a filtered content query.     */    public BackedList createResultList() {        return super.createResultList();    }    /** A Factory Method pattern which creates     * a BackedList implementation which contains a single result     */    public List createSingleResultList(Object result) {        return super.createSingleResultList(result);    }    /** A Factory Method pattern which creates an empty     * a BackedList implementation     */    public List createEmptyList() {        return super.createEmptyList();    }    public void childRemoved(Node node) {        super.childRemoved(node);    }    public void childAdded(Node node) {        super.childAdded(node);    }    public boolean removeNode(Node node) {        return super.removeNode(node);    }    public void addNode(Node node) {        super.addNode(node);    }    public List contentList() {        return super.contentList();    }    public void addNode(int index, Node node) {        super.addNode(index, node);    }    /**     * An element clone is identitical to its original except for two things     * 1. it has no document     * 2. it has no parent     * @return a clone of the Element as its own unique persiatant object     */    public Object clone() {        try {            Element answer = (Element) database().copyObject(self());            answer.setDocument(null);            answer.setParent(null);            // now we need to continue to clone our way down, otherwise the content            // of the clone will refer to the same as the original            answer.setContent(null);            answer.setAttributes(null);            answer.appendAttributes((Element) self());            answer.appendContent((Element) self());            return answer;        } catch (Exception e) {            e.printStackTrace();            return null;        }    }    public void onCreate() {    }    public void onActivate() {    }    public void onPassivate() {    }    public void onDelete() {        OzoneInterface db = database();//        QName qname = getQName();//        if (qname != null && qname instanceof OzoneRemote) {//            db.deleteObject((OzoneRemote)qname);//        }        List contentList = content();        OzoneRemote content;        for (Iterator it = contentList.iterator(); it.hasNext();) {            Object obj = it.next();            System.out.println("deleting " + obj.getClass());            content = (OzoneRemote) obj;            db.deleteObject(content);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -