src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/reflect/Accessor.java

Print this page
rev 447 : 8029237: Update copyright year to match last edit in jdk8 jaxws repository (2013)
Summary: Fixing Copyrights for year 2013
Reviewed-by: chegar
rev 472 : 8036030: Update JAX-WS RI integration to latest version
   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  29 import java.lang.reflect.InvocationTargetException;
  30 import java.lang.reflect.Method;
  31 import java.lang.reflect.Modifier;
  32 import java.lang.reflect.Type;
  33 import java.util.Arrays;
  34 import java.util.HashMap;
  35 import java.util.List;
  36 import java.util.Map;
  37 import java.util.logging.Level;
  38 import java.util.logging.Logger;
  39 
  40 import javax.xml.bind.JAXBElement;
  41 import javax.xml.bind.annotation.adapters.XmlAdapter;
  42 
  43 import com.sun.istack.internal.Nullable;
  44 import com.sun.xml.internal.bind.Util;
  45 import com.sun.xml.internal.bind.api.AccessorException;
  46 import com.sun.xml.internal.bind.api.JAXBRIContext;
  47 import com.sun.xml.internal.bind.v2.model.core.Adapter;
  48 import com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder;
  49 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
  50 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
  51 import com.sun.xml.internal.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory;
  52 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;
  53 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Receiver;
  54 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
  55 
  56 import org.xml.sax.SAXException;
  57 
  58 /**
  59  * Accesses a particular property of a bean.
  60  * <p/>
  61  * <p/>
  62  * This interface encapsulates the access to the actual data store.
  63  * The intention is to generate implementations for a particular bean
  64  * and a property to improve the performance.
  65  * <p/>
  66  * <p/>
  67  * Accessor can be used as a receiver. Upon receiving an object
  68  * it sets that to the field.
  69  *


 181 
 182     /**
 183      * Checks if it is not builtin jaxb class
 184      * @param clazz to be checked
 185      * @return true if it is NOT builtin class
 186      */
 187     public boolean isAbstractable(Class clazz) {
 188         return !nonAbstractableClasses.contains(clazz);
 189     }
 190 
 191     /**
 192      * Wraps this  {@link Accessor} into another {@link Accessor}
 193      * and performs the type adaption as necessary.
 194      */
 195     public final <T> Accessor<BeanT, T> adapt(Class<T> targetType, final Class<? extends XmlAdapter<T, ValueT>> adapter) {
 196         return new AdaptedAccessor<BeanT, ValueT, T>(targetType, this, adapter);
 197     }
 198 
 199     public final <T> Accessor<BeanT, T> adapt(Adapter<Type, Class> adapter) {
 200         return new AdaptedAccessor<BeanT, ValueT, T>(
 201                 (Class<T>) Navigator.REFLECTION.erasure(adapter.defaultType),
 202                 this,
 203                 adapter.adapterType);
 204     }
 205 
 206     /**
 207      * Flag that will be set to true after issueing a warning
 208      * about the lack of permission to access non-public fields.
 209      */
 210     private static boolean accessWarned = false;
 211 
 212 
 213     /**
 214      * {@link Accessor} that uses Java reflection to access a field.
 215      */
 216     public static class FieldReflection<BeanT, ValueT> extends Accessor<BeanT, ValueT> {
 217         public final Field f;
 218 
 219         private static final Logger logger = Util.getClassLogger();
 220 
 221         public FieldReflection(Field f) {


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  29 import java.lang.reflect.InvocationTargetException;
  30 import java.lang.reflect.Method;
  31 import java.lang.reflect.Modifier;
  32 import java.lang.reflect.Type;
  33 import java.util.Arrays;
  34 import java.util.HashMap;
  35 import java.util.List;
  36 import java.util.Map;
  37 import java.util.logging.Level;
  38 import java.util.logging.Logger;
  39 
  40 import javax.xml.bind.JAXBElement;
  41 import javax.xml.bind.annotation.adapters.XmlAdapter;
  42 
  43 import com.sun.istack.internal.Nullable;
  44 import com.sun.xml.internal.bind.Util;
  45 import com.sun.xml.internal.bind.api.AccessorException;
  46 import com.sun.xml.internal.bind.api.JAXBRIContext;
  47 import com.sun.xml.internal.bind.v2.model.core.Adapter;
  48 import com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder;

  49 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
  50 import com.sun.xml.internal.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory;
  51 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;
  52 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Receiver;
  53 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
  54 
  55 import org.xml.sax.SAXException;
  56 
  57 /**
  58  * Accesses a particular property of a bean.
  59  * <p/>
  60  * <p/>
  61  * This interface encapsulates the access to the actual data store.
  62  * The intention is to generate implementations for a particular bean
  63  * and a property to improve the performance.
  64  * <p/>
  65  * <p/>
  66  * Accessor can be used as a receiver. Upon receiving an object
  67  * it sets that to the field.
  68  *


 180 
 181     /**
 182      * Checks if it is not builtin jaxb class
 183      * @param clazz to be checked
 184      * @return true if it is NOT builtin class
 185      */
 186     public boolean isAbstractable(Class clazz) {
 187         return !nonAbstractableClasses.contains(clazz);
 188     }
 189 
 190     /**
 191      * Wraps this  {@link Accessor} into another {@link Accessor}
 192      * and performs the type adaption as necessary.
 193      */
 194     public final <T> Accessor<BeanT, T> adapt(Class<T> targetType, final Class<? extends XmlAdapter<T, ValueT>> adapter) {
 195         return new AdaptedAccessor<BeanT, ValueT, T>(targetType, this, adapter);
 196     }
 197 
 198     public final <T> Accessor<BeanT, T> adapt(Adapter<Type, Class> adapter) {
 199         return new AdaptedAccessor<BeanT, ValueT, T>(
 200                 (Class<T>) Utils.REFLECTION_NAVIGATOR.erasure(adapter.defaultType),
 201                 this,
 202                 adapter.adapterType);
 203     }
 204 
 205     /**
 206      * Flag that will be set to true after issueing a warning
 207      * about the lack of permission to access non-public fields.
 208      */
 209     private static boolean accessWarned = false;
 210 
 211 
 212     /**
 213      * {@link Accessor} that uses Java reflection to access a field.
 214      */
 215     public static class FieldReflection<BeanT, ValueT> extends Accessor<BeanT, ValueT> {
 216         public final Field f;
 217 
 218         private static final Logger logger = Util.getClassLogger();
 219 
 220         public FieldReflection(Field f) {