001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.bind.v2.model.impl;
038:
039: import java.lang.reflect.Field;
040: import java.lang.reflect.Method;
041: import java.lang.reflect.Type;
042: import java.util.Collection;
043: import java.util.Collections;
044: import java.util.List;
045:
046: import javax.xml.bind.JAXBElement;
047: import javax.xml.bind.annotation.adapters.XmlAdapter;
048:
049: import com.sun.xml.bind.v2.model.core.Adapter;
050: import com.sun.xml.bind.v2.model.runtime.RuntimeClassInfo;
051: import com.sun.xml.bind.v2.model.runtime.RuntimeElementInfo;
052: import com.sun.xml.bind.v2.model.runtime.RuntimeElementPropertyInfo;
053: import com.sun.xml.bind.v2.model.runtime.RuntimeNonElement;
054: import com.sun.xml.bind.v2.model.runtime.RuntimePropertyInfo;
055: import com.sun.xml.bind.v2.model.runtime.RuntimeTypeRef;
056: import com.sun.xml.bind.v2.model.nav.Navigator;
057: import com.sun.xml.bind.v2.runtime.IllegalAnnotationException;
058: import com.sun.xml.bind.v2.runtime.Transducer;
059: import com.sun.xml.bind.v2.runtime.reflect.Accessor;
060:
061: /**
062: * @author Kohsuke Kawaguchi
063: */
064: final class RuntimeElementInfoImpl extends
065: ElementInfoImpl<Type, Class, Field, Method> implements
066: RuntimeElementInfo {
067:
068: public RuntimeElementInfoImpl(RuntimeModelBuilder modelBuilder,
069: RegistryInfoImpl registry, Method method)
070: throws IllegalAnnotationException {
071: super (modelBuilder, registry, method);
072:
073: Adapter<Type, Class> a = getProperty().getAdapter();
074:
075: if (a != null)
076: adapterType = a.adapterType;
077: else
078: adapterType = null;
079: }
080:
081: @Override
082: protected PropertyImpl createPropertyImpl() {
083: return new RuntimePropertyImpl();
084: }
085:
086: class RuntimePropertyImpl extends PropertyImpl implements
087: RuntimeElementPropertyInfo, RuntimeTypeRef {
088: public Accessor getAccessor() {
089: if (adapterType == null)
090: return Accessor.JAXB_ELEMENT_VALUE;
091: else
092: return Accessor.JAXB_ELEMENT_VALUE.adapt(
093: (Class) getAdapter().defaultType,
094: (Class) adapterType);
095: }
096:
097: public Type getRawType() {
098: return Collection.class;
099: }
100:
101: public Type getIndividualType() {
102: return getContentType().getType();
103: }
104:
105: public boolean elementOnlyContent() {
106: return false; // this method doesn't make sense here
107: }
108:
109: public List<? extends RuntimeTypeRef> getTypes() {
110: return Collections.singletonList(this );
111: }
112:
113: public List<? extends RuntimeNonElement> ref() {
114: return (List<? extends RuntimeNonElement>) super .ref();
115: }
116:
117: public RuntimeNonElement getTarget() {
118: return (RuntimeNonElement) super .getTarget();
119: }
120:
121: public RuntimePropertyInfo getSource() {
122: return this ;
123: }
124:
125: public Transducer getTransducer() {
126: return RuntimeModelBuilder.createTransducer(this );
127: }
128: }
129:
130: /**
131: * The adapter specified by <code>getProperty().getAdapter()</code>.
132: */
133: private final Class<? extends XmlAdapter> adapterType;
134:
135: public RuntimeElementPropertyInfo getProperty() {
136: return (RuntimeElementPropertyInfo) super .getProperty();
137: }
138:
139: public Class<? extends JAXBElement> getType() {
140: return Navigator.REFLECTION.erasure(super .getType());
141: }
142:
143: public RuntimeClassInfo getScope() {
144: return (RuntimeClassInfo) super .getScope();
145: }
146:
147: public RuntimeNonElement getContentType() {
148: return (RuntimeNonElement) super.getContentType();
149: }
150: }
|