001: /* Binary.java
002:
003: {{IS_NOTE
004:
005: Purpose:
006: Description:
007: History:
008: 2001/10/21 21:32:27, Create, Tom M. Yeh.
009: }}IS_NOTE
010:
011: Copyright (C) 2001 Potix Corporation. All Rights Reserved.
012:
013: {{IS_RIGHT
014: This program is distributed under GPL Version 2.0 in the hope that
015: it will be useful, but WITHOUT ANY WARRANTY.
016: }}IS_RIGHT
017: */
018: package org.zkoss.idom;
019:
020: import org.zkoss.lang.Objects;
021: import org.zkoss.idom.impl.*;
022:
023: /**
024: * The binary item. It is iDOM's extension to W3C/DOM, which allows
025: * only String-type value. However, XML files doesn't convey the type
026: * information, so, when loading back an XML file, Binary vertices
027: * become CData vertices.
028: *
029: * <p>To be compatible with W3C/DOM utility, it fakes as Text.
030: * Thus, getNodeName returns "#text", rather than getName ("#binary").
031: *
032: * @author tomyeh
033: * @see CData
034: */
035: public class Binary extends AbstractTextual implements
036: org.w3c.dom.Text, Binable {
037: /** The value. */
038: Object _value;
039:
040: /** Constructor.
041: */
042: public Binary(String value) {
043: setValue(value);
044: }
045:
046: /** Constructor.
047: */
048: public Binary(Object value) {
049: setValue(value);
050: }
051:
052: /** Constructor.
053: */
054: public Binary() {
055: }
056:
057: //-- AbstractTextual extras --//
058: protected void checkText(String text) {
059: }
060:
061: //-- Binable --//
062: public final Object getValue() {
063: return _value;
064: }
065:
066: public final void setValue(Object o) {
067: checkWritable();
068: if (!Objects.equals(_value, o)) {
069: _value = o;
070: setModified();
071: }
072: }
073:
074: //-- Item --//
075: /**
076: * Gets the text representation of the value. Never null.
077: */
078: public final String getText() {
079: String s = _value != null ? _value.toString() : null;
080: return s != null ? s : "";
081: }
082:
083: public final void setText(String text) {
084: setValue(text);
085: }
086:
087: public final String getName() {
088: return "#binary";
089: }
090:
091: //-- Node --//
092: public final String getNodeName() {
093: return "#text"; //fake as TEXT_NODE
094: }
095:
096: public final short getNodeType() {
097: return TEXT_NODE; //fake as TEXT_NODE
098: }
099:
100: //-- Object --//
101: /**
102: * Gets the textual representation for debug.
103: */
104: public String toString() {
105: String s = super .toString();
106: if (_value == null)
107: return s;
108:
109: int len = s.length();
110: char cc = s.charAt(len - 1);
111: return s.substring(0, len - 1) + ' '
112: + _value.getClass().getName() + cc;
113: }
114: }
|