001: /*
002: * Copyright (c) 1998-2006 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 javax.xml.bind;
031:
032: import javax.xml.namespace.QName;
033: import java.io.Serializable;
034:
035: public class JAXBElement<T> implements Serializable {
036:
037: protected final Class<T> declaredType;
038:
039: protected final QName name;
040:
041: protected final Class scope;
042:
043: protected T value;
044:
045: protected boolean nil;
046:
047: public JAXBElement(QName name, Class<T> declaredType, Class scope,
048: T value) {
049: this .name = name;
050: this .declaredType = declaredType;
051: this .scope = scope;
052: this .value = value;
053: this .nil = false;
054: }
055:
056: public JAXBElement(QName name, Class<T> declaredType, T value) {
057: this (name, declaredType, JAXBElement.GlobalScope.class, value);
058: }
059:
060: public Class<T> getDeclaredType() {
061: return declaredType;
062: }
063:
064: public QName getName() {
065: return name;
066: }
067:
068: public Class getScope() {
069: return scope;
070: }
071:
072: public T getValue() {
073: return value;
074: }
075:
076: public boolean isGlobalScope() {
077: return scope == JAXBElement.GlobalScope.class;
078: }
079:
080: public boolean isNil() {
081: return nil;
082: }
083:
084: public boolean isTypeSubstituted() {
085: return !declaredType.isInstance(value);
086: }
087:
088: public void setNil(boolean value) {
089: nil = value;
090: }
091:
092: public void setValue(T t) {
093: value = t;
094: }
095:
096: public static final class GlobalScope {
097: public GlobalScope() {
098: }
099: }
100: }
|