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 Scott Ferguson
028: */
029:
030: package com.caucho.jaxb.property;
031:
032: import java.io.IOException;
033:
034: import java.util.ArrayList;
035:
036: import javax.xml.bind.JAXBException;
037: import javax.xml.bind.Marshaller;
038: import javax.xml.bind.Unmarshaller;
039:
040: import javax.xml.namespace.QName;
041:
042: import javax.xml.stream.XMLStreamException;
043: import javax.xml.stream.XMLStreamReader;
044: import javax.xml.stream.XMLStreamWriter;
045:
046: import org.w3c.dom.Node;
047:
048: import com.caucho.jaxb.BinderImpl;
049: import com.caucho.jaxb.NodeIterator;
050: import com.caucho.jaxb.mapping.Namer;
051: import com.caucho.jaxb.mapping.XmlMapping;
052: import com.caucho.jaxb.skeleton.ClassSkeleton;
053:
054: import com.caucho.util.L10N;
055:
056: /**
057: */
058: public abstract class Property {
059: public static final L10N L = new L10N(Property.class);
060:
061: //
062: // Schema generation methods
063: //
064: public boolean isXmlPrimitiveType() {
065: return true;
066: }
067:
068: public String getMinOccurs() {
069: return "0";
070: }
071:
072: public String getMaxOccurs() {
073: return null;
074: }
075:
076: public boolean isNullable() {
077: return false;
078: }
079:
080: public Object getNilValue() {
081: return null;
082: }
083:
084: public abstract QName getSchemaType();
085:
086: // XXX: This is hideous -- there is way too much overloading going on here
087: // R/W methods
088: //
089:
090: public Object readAttribute(XMLStreamReader in, int i)
091: throws IOException, JAXBException {
092: throw new JAXBException(
093: L
094: .l(
095: "Internal error: Property does not support attributes {0}",
096: this ));
097: }
098:
099: public abstract Object read(Unmarshaller u, XMLStreamReader in,
100: Object previous) throws IOException, XMLStreamException,
101: JAXBException;
102:
103: public Object read(Unmarshaller u, XMLStreamReader in,
104: Object previous, ClassSkeleton attributed, Object parent)
105: throws IOException, XMLStreamException, JAXBException {
106: return read(u, in, previous);
107: }
108:
109: public abstract Object bindFrom(BinderImpl binder,
110: NodeIterator node, Object previous) throws IOException,
111: JAXBException;
112:
113: public abstract void write(Marshaller m, XMLStreamWriter out,
114: Object value, Namer namer) throws IOException,
115: XMLStreamException, JAXBException;
116:
117: public abstract Node bindTo(BinderImpl binder, Node node,
118: Object value, Namer namer) throws IOException,
119: JAXBException;
120:
121: public void write(Marshaller m, XMLStreamWriter out, Object value,
122: Namer namer, Object obj) throws IOException,
123: XMLStreamException, JAXBException {
124: write(m, out, value, namer);
125: }
126:
127: public void write(Marshaller m, XMLStreamWriter out, Object value,
128: Namer namer, Object obj, ArrayList<XmlMapping> attributes)
129: throws IOException, XMLStreamException, JAXBException {
130: write(m, out, value, namer, obj);
131: }
132:
133: public Node bindTo(BinderImpl binder, Node node, Object value,
134: Namer namer, ArrayList<XmlMapping> attributes)
135: throws IOException, JAXBException {
136: return bindTo(binder, node, value, namer);
137: }
138: }
|