001: /*
002: * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong, Adam Megacz
028: */
029:
030: package com.caucho.jaxb.property;
031:
032: import com.caucho.jaxb.BinderImpl;
033: import com.caucho.jaxb.JAXBUtil;
034: import com.caucho.jaxb.NodeIterator;
035: import com.caucho.jaxb.mapping.Namer;
036: import com.caucho.jaxb.skeleton.ClassSkeleton;
037: import com.caucho.util.L10N;
038:
039: import javax.xml.bind.JAXBException;
040: import javax.xml.bind.Marshaller;
041: import javax.xml.bind.Unmarshaller;
042: import javax.xml.namespace.QName;
043: import javax.xml.stream.XMLStreamException;
044: import javax.xml.stream.XMLStreamReader;
045: import javax.xml.stream.XMLStreamWriter;
046: import java.io.IOException;
047:
048: import org.w3c.dom.Node;
049:
050: /**
051: * a property referencing some other Skeleton
052: */
053: public class SkeletonProperty extends Property {
054: private static final L10N L = new L10N(SkeletonProperty.class);
055:
056: private ClassSkeleton _skeleton;
057:
058: public SkeletonProperty(ClassSkeleton skeleton) {
059: _skeleton = skeleton;
060:
061: if (_skeleton == null)
062: throw new NullPointerException();
063: }
064:
065: public Object read(Unmarshaller u, XMLStreamReader in,
066: Object previous) throws IOException, XMLStreamException,
067: JAXBException {
068: return _skeleton.read(u, in);
069: }
070:
071: public Object bindFrom(BinderImpl binder, NodeIterator node,
072: Object previous) throws IOException, JAXBException {
073: Node root = node.getNode();
074:
075: Object old = binder.getJAXBNode(root);
076:
077: Object ret = _skeleton.bindFrom(binder, old, node);
078:
079: binder.bind(ret, root);
080:
081: return ret;
082: }
083:
084: public void write(Marshaller m, XMLStreamWriter out, Object obj,
085: Namer namer) throws IOException, XMLStreamException,
086: JAXBException {
087: _skeleton.write(m, out, obj, namer, null);
088: }
089:
090: public Node bindTo(BinderImpl binder, Node node, Object obj,
091: Namer namer) throws IOException, JAXBException {
092: return _skeleton.bindTo(binder, node, obj, namer, null);
093: }
094:
095: public QName getSchemaType() {
096: return _skeleton.getTypeName();
097: }
098:
099: public boolean isXmlPrimitiveType() {
100: return false;
101: }
102:
103: public String toString() {
104: return "SkeletonProperty[" + _skeleton + "]";
105: }
106: }
|