001: /**
002: * org/ozone-db/xml/XMLElement.java
003: *
004: * The contents of this file are subject to the OpenXML Public
005: * License Version 1.0; you may not use this file except in compliance
006: * with the License. You may obtain a copy of the License at
007: * http://www.openxml.org/license.html
008: *
009: * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
010: * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
011: * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
012: * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
013: * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
014: * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
015: *
016: * The Initial Developer of this code under the License is Assaf Arkin.
017: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
018: * All Rights Reserved.
019: */
020:
021: /**
022: * Changes for Persistent DOM running with ozone are
023: * Copyright 1999 by SMB GmbH. All rights reserved.
024: */package org.ozoneDB.xml;
025:
026: import org.w3c.dom.*;
027: import org.ozoneDB.xml.dom.*;
028:
029: /**
030: * Base class for user XML elements. {@link XMLDocument} is designed to create
031: * elements of classes derived from {@link XMLElement}. In addition to several
032: * API extensions, user XML elements can be used to map XML documents directly
033: * into application data structures.
034: * <P>
035: * {@link XMLElement} extends the DOM {@link Element} with the following methods:
036: * <UL>
037: * <LI>{@link #setReadOnly} renders an element read-only preventing any changes
038: * to it's attribute or content
039: * <LI>{@link #setUserObject} and {@link #getUserObject} may be used to associate
040: * a user object with an element
041: * </UL>
042: * <P>
043: * In order to support user elements, a document class must extend {@link
044: * XMLDocument}. It then registers tag name to element class associations using
045: * {@link XMLDocument#registerElement}, or uses an external element factory
046: * with {@link XMLDocument#useElementFactory}.
047: * <P>
048: * The user elements will be returns whenever {@link XMLDocument#createElement}
049: * is called on the document, or when a document of this type is parsed.
050: * <P>
051: * A user element derived from {@link XMLElement} must pass the owner document
052: * and tag name to its constructor. The class and its constructor must be
053: * declared public and the constructor must have the same signature as the
054: * {@link XMLElement} constructor. The last three requirements may be relaxed
055: * if an external element factory is used.
056: *
057: *
058: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
059: * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
060: * @see org.w3c.dom.Element
061: * @see XMLDocument#registerElement
062: * @see XMLElementFactory
063: * @deprecated Alternative API will be introduced in OpenXML 1.1
064: */
065: public class XMLElement extends ElementImpl implements XMLElementProxy {
066:
067: /**
068: * Constructor requires owner document and element tag name. This will be
069: * provided when an element of this or a derived class is being constructed
070: * by an {@link XMLDocument}. The arguments must pass to this constructor
071: * unaffected. Derived classes must implement at least one constructor with
072: * the exact same signature to support element class registration; this
073: * requirement is relaxed if an external element factory is used.
074: *
075: * @param owner The owner document
076: * @param tagName The element's tag name
077: */
078: public XMLElement(Document owner, String tagName) {
079: super ((DocumentImpl) owner, tagName);
080: }
081:
082: public XMLElement() {
083: super ();
084: }
085:
086: /**
087: * Associates this element with a user object. There is no limit on what
088: * the user object may hold.
089: *
090: * @param userObject The user object
091: */
092: public void setUserObject(Object userObject) {
093: _userObject = userObject;
094: }
095:
096: /**
097: * Returns the user object associated with this element. There is no limit
098: * on what the user object may hold.
099: *
100: * @return The user object
101: */
102: public Object getUserObject() {
103: return _userObject;
104: }
105:
106: /**
107: * Returns the identifier of this element. Unless specifies otherwise in
108: * the DTD, this would be the value of the <TT>id</TT> attribute. It may
109: * be a textual value or null.
110: *
111: * @return The identifier of this element
112: */
113: public String getID() {
114: return getAttribute("id");
115: }
116:
117: /**
118: * Holds a user object. Any object can be associated with this element
119: * using the appropriate set/get methods.
120: */
121: protected Object _userObject;
122:
123: }
|