jaxws/src/share/jaxws_classes/com/sun/xml/internal/ws/spi/db/JAXBWrapperAccessor.java
author mkos
Mon, 31 Mar 2014 10:43:20 +0200
changeset 23782 953bfc3fbe31
parent 18372 4d90cbb0d70a
permissions -rw-r--r--
8036030: Update JAX-WS RI integration to latest version Summary: JAX-WS RI upgrade from 2.2.9-b130926.1035 to 2.2.10-b140228.1436; Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     1
/*
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     4
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    10
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    15
 * accompanied this code).
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    16
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    20
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    23
 * questions.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    24
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    25
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    26
package com.sun.xml.internal.ws.spi.db;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    27
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    28
import java.lang.reflect.Array;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    29
import java.lang.reflect.Field;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    30
import java.lang.reflect.GenericArrayType;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    31
import java.lang.reflect.Method;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    32
import java.lang.reflect.ParameterizedType;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    33
import java.lang.reflect.Type;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    34
import java.security.AccessController;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    35
import java.security.PrivilegedActionException;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    36
import java.security.PrivilegedExceptionAction;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    37
import java.util.ArrayList;
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
    38
import java.util.Arrays;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    39
import java.util.HashMap;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    40
import java.util.HashSet;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    41
import java.util.List;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    42
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    43
import javax.xml.bind.JAXBElement;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    44
import javax.xml.bind.annotation.XmlElement;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    45
import javax.xml.bind.annotation.XmlElementRef;
18372
4d90cbb0d70a 8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents: 16791
diff changeset
    46
import javax.xml.bind.annotation.XmlElementWrapper;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    47
import javax.xml.namespace.QName;
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
    48
import javax.xml.ws.WebServiceException;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
    49
import static com.sun.xml.internal.ws.spi.db.PropertyGetterBase.verifyWrapperType;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    50
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    51
/**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    52
 * JAXBWrapperAccessor
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    53
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    54
 * @author shih-chang.chen@oracle.com
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    55
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    56
@SuppressWarnings({ "unchecked", "rawtypes" })
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    57
public class JAXBWrapperAccessor extends WrapperAccessor {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    58
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    59
    protected Class<?> contentClass;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    60
    protected HashMap<Object, Class> elementDeclaredTypes;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    61
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    62
    public JAXBWrapperAccessor(Class<?> wrapperBean) {
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
    63
        verifyWrapperType(wrapperBean);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    64
        contentClass = (Class<?>) wrapperBean;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    65
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    66
        HashMap<Object, PropertySetter> setByQName = new HashMap<Object, PropertySetter>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    67
        HashMap<Object, PropertySetter> setByLocalpart = new HashMap<Object, PropertySetter>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    68
        HashMap<String, Method> publicSetters = new HashMap<String, Method>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    69
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    70
        HashMap<Object, PropertyGetter> getByQName = new HashMap<Object, PropertyGetter>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    71
        HashMap<Object, PropertyGetter> getByLocalpart = new HashMap<Object, PropertyGetter>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    72
        HashMap<String, Method> publicGetters = new HashMap<String, Method>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    73
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    74
        HashMap<Object, Class> elementDeclaredTypesByQName = new HashMap<Object, Class>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    75
        HashMap<Object, Class> elementDeclaredTypesByLocalpart = new HashMap<Object, Class>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    76
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    77
        for (Method method : contentClass.getMethods()) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    78
            if (PropertySetterBase.setterPattern(method)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    79
                String key = method.getName()
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    80
                        .substring(3, method.getName().length()).toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    81
                publicSetters.put(key, method);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    82
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    83
            if (PropertyGetterBase.getterPattern(method)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    84
                String methodName = method.getName();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    85
                String key = methodName.startsWith("is") ? methodName
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    86
                        .substring(2, method.getName().length()).toLowerCase()
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    87
                        : methodName.substring(3, method.getName().length())
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    88
                                .toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    89
                publicGetters.put(key, method);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    90
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    91
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    92
        HashSet<String> elementLocalNames = new HashSet<String>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    93
        for (Field field : getAllFields(contentClass)) {
18372
4d90cbb0d70a 8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents: 16791
diff changeset
    94
            XmlElementWrapper xmlElemWrapper = field.getAnnotation(XmlElementWrapper.class);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    95
            XmlElement xmlElem = field.getAnnotation(XmlElement.class);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    96
            XmlElementRef xmlElemRef = field.getAnnotation(XmlElementRef.class);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    97
            String fieldName = field.getName().toLowerCase();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    98
            String namespace = "";
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    99
            String localName = field.getName();
18372
4d90cbb0d70a 8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents: 16791
diff changeset
   100
            if (xmlElemWrapper != null) {
4d90cbb0d70a 8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents: 16791
diff changeset
   101
                namespace = xmlElemWrapper.namespace();
4d90cbb0d70a 8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents: 16791
diff changeset
   102
                if (xmlElemWrapper.name() != null && !xmlElemWrapper.name().equals("")
4d90cbb0d70a 8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents: 16791
diff changeset
   103
                        && !xmlElemWrapper.name().equals("##default")) {
4d90cbb0d70a 8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents: 16791
diff changeset
   104
                    localName = xmlElemWrapper.name();
4d90cbb0d70a 8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents: 16791
diff changeset
   105
                }
4d90cbb0d70a 8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
mkos
parents: 16791
diff changeset
   106
            }else if (xmlElem != null) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   107
                namespace = xmlElem.namespace();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   108
                if (xmlElem.name() != null && !xmlElem.name().equals("")
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   109
                        && !xmlElem.name().equals("##default")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   110
                    localName = xmlElem.name();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   111
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   112
            } else if (xmlElemRef != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   113
                namespace = xmlElemRef.namespace();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   114
                if (xmlElemRef.name() != null && !xmlElemRef.name().equals("")
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   115
                        && !xmlElemRef.name().equals("##default")) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   116
                    localName = xmlElemRef.name();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   117
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   118
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   119
            if (elementLocalNames.contains(localName)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   120
                this.elementLocalNameCollision = true;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   121
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   122
                elementLocalNames.add(localName);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   123
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   124
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   125
            QName qname = new QName(namespace, localName);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   126
            if (field.getType().equals(JAXBElement.class)) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   127
                if (field.getGenericType() instanceof ParameterizedType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   128
                    Type arg = ((ParameterizedType) field.getGenericType())
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   129
                            .getActualTypeArguments()[0];
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   130
                    if (arg instanceof Class) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   131
                        elementDeclaredTypesByQName.put(qname, (Class) arg);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   132
                        elementDeclaredTypesByLocalpart.put(localName,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   133
                                (Class) arg);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   134
                    } else if (arg instanceof GenericArrayType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   135
                        Type componentType = ((GenericArrayType) arg)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   136
                                .getGenericComponentType();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   137
                        if (componentType instanceof Class) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   138
                            Class arrayClass = Array.newInstance(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   139
                                    (Class) componentType, 0).getClass();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   140
                            elementDeclaredTypesByQName.put(qname, arrayClass);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   141
                            elementDeclaredTypesByLocalpart.put(localName,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   142
                                    arrayClass);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   143
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   144
                    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   145
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   146
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   147
            }
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   148
            Method setMethod = accessor(publicSetters, fieldName, localName);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   149
            Method getMethod = accessor(publicGetters, fieldName, localName);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   150
            if ( isProperty(field, getMethod, setMethod) ) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   151
                PropertySetter setter = createPropertySetter(field, setMethod);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   152
                PropertyGetter getter = createPropertyGetter(field, getMethod);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   153
                setByQName.put(qname, setter);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   154
                setByLocalpart.put(localName, setter);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   155
                getByQName.put(qname, getter);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   156
                getByLocalpart.put(localName, getter);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   157
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   158
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   159
        if (this.elementLocalNameCollision) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   160
            this.propertySetters = setByQName;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   161
            this.propertyGetters = getByQName;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   162
            elementDeclaredTypes = elementDeclaredTypesByQName;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   163
        } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   164
            this.propertySetters = setByLocalpart;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   165
            this.propertyGetters = getByLocalpart;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   166
            elementDeclaredTypes = elementDeclaredTypesByLocalpart;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   167
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   168
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   169
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   170
    static private Method accessor(HashMap<String, Method> map, String fieldName, String localName) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   171
        Method a = map.get(fieldName);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   172
        if (a == null) a = map.get(localName);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   173
        if (a == null && fieldName.startsWith("_")) a = map.get(fieldName.substring(1));
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   174
        return a;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   175
    }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   176
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   177
    static private boolean isProperty(Field field, Method getter, Method setter) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   178
        if (java.lang.reflect.Modifier.isPublic(field.getModifiers())) return true;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   179
        if (getter == null) return false;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   180
        if (setter == null) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   181
            return java.util.Collection.class.isAssignableFrom(field.getType()) ||
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   182
                   java.util.Map.class.isAssignableFrom(field.getType()) ;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   183
        } else {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   184
            return true;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   185
        }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   186
    }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   187
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   188
    static private List<Field> getAllFields(Class<?> clz) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   189
        List<Field> list = new ArrayList<Field>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   190
        while (!Object.class.equals(clz)) {
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   191
            list.addAll(Arrays.asList(getDeclaredFields(clz)));
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   192
            clz = clz.getSuperclass();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   193
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   194
        return list;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   195
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   196
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   197
    static private Field[] getDeclaredFields(final Class<?> clz) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   198
        try {
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   199
            return AccessController.doPrivileged(new PrivilegedExceptionAction<Field[]>() {
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   200
                        @Override
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   201
                        public Field[] run() throws IllegalAccessException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   202
                            return clz.getDeclaredFields();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   203
                        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   204
                    });
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   205
        } catch (PrivilegedActionException e) {
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   206
            throw new WebServiceException(e);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   207
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   208
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   209
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   210
    static private PropertyGetter createPropertyGetter(Field field, Method getMethod) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   211
        if (!field.isAccessible()) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   212
            if (getMethod != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   213
                MethodGetter methodGetter = new MethodGetter(getMethod);
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   214
                if (methodGetter.getType().toString().equals(field.getType().toString())) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   215
                    return methodGetter;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   216
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   217
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   218
        }
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   219
        return new PrivFieldGetter(field);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   220
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   221
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   222
    static private PropertySetter createPropertySetter(Field field,
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   223
            Method setter) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   224
        if (!field.isAccessible()) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   225
            if (setter != null) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   226
                MethodSetter injection = new MethodSetter(setter);
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   227
                if (injection.getType().toString().equals(field.getType().toString())) {
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   228
                    return injection;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   229
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   230
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   231
        }
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   232
        return new PrivFieldSetter(field);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   233
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   234
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   235
    private Class getElementDeclaredType(QName name) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   236
        Object key = (this.elementLocalNameCollision) ? name : name
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   237
                .getLocalPart();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   238
        return elementDeclaredTypes.get(key);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   239
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   240
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   241
    @Override
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   242
    public PropertyAccessor getPropertyAccessor(String ns, String name) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   243
        final QName n = new QName(ns, name);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   244
        final PropertySetter setter = getPropertySetter(n);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   245
        final PropertyGetter getter = getPropertyGetter(n);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   246
        final boolean isJAXBElement = setter.getType()
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   247
                .equals(JAXBElement.class);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   248
        final boolean isListType = java.util.List.class.isAssignableFrom(setter
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   249
                .getType());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   250
        final Class elementDeclaredType = isJAXBElement ? getElementDeclaredType(n)
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   251
                : null;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   252
        return new PropertyAccessor() {
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   253
            @Override
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   254
            public Object get(Object bean) throws DatabindingException {
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   255
                Object val;
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   256
                if (isJAXBElement) {
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   257
                    JAXBElement<Object> jaxbElement = (JAXBElement<Object>) JAXBWrapperAccessor.get(getter, bean);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   258
                    val = (jaxbElement == null) ? null : jaxbElement.getValue();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   259
                } else {
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   260
                    val = JAXBWrapperAccessor.get(getter, bean);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   261
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   262
                if (val == null && isListType) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   263
                    val = new java.util.ArrayList();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   264
                    set(bean, val);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   265
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   266
                return val;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   267
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   268
16791
fe5141eabb0e 8010393: Update JAX-WS RI to 2.2.9-b12941
alanb
parents: 12009
diff changeset
   269
            @Override
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   270
            public void set(Object bean, Object value) throws DatabindingException {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   271
                if (isJAXBElement) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   272
                    JAXBElement<Object> jaxbElement = new JAXBElement<Object>(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   273
                            n, elementDeclaredType, contentClass, value);
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   274
                    JAXBWrapperAccessor.set(setter, bean, jaxbElement);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   275
                } else {
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   276
                    JAXBWrapperAccessor.set(setter, bean, value);
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   277
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   278
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   279
        };
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   280
    }
23782
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   281
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   282
    static  private Object get(PropertyGetter getter, Object wrapperInstance) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   283
        return (getter instanceof PrivFieldGetter)?
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   284
            ((PrivFieldGetter)getter).getPriv(wrapperInstance):
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   285
            getter.get(wrapperInstance);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   286
    }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   287
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   288
    static private void set(PropertySetter setter, Object wrapperInstance, Object value) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   289
        if (setter instanceof PrivFieldSetter)
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   290
            ((PrivFieldSetter)setter).setPriv(wrapperInstance, value);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   291
        else
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   292
            setter.set(wrapperInstance, value);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   293
    }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   294
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   295
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   296
    static private class PrivFieldSetter extends FieldSetter {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   297
        private PrivFieldSetter(Field f) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   298
            super(f);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   299
        }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   300
        private void setPriv(final Object instance, final Object val) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   301
            final Object resource = (type.isPrimitive() && val == null)? uninitializedValue(type): val;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   302
            if (field.isAccessible()) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   303
                try {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   304
                    field.set(instance, resource);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   305
                } catch (Exception e) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   306
                    throw new WebServiceException(e);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   307
                }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   308
            } else {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   309
                try {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   310
                    AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   311
                        public Object run() throws IllegalAccessException {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   312
                            if (!field.isAccessible()) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   313
                                field.setAccessible(true);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   314
                            }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   315
                            field.set(instance, resource);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   316
                            return null;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   317
                        }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   318
                    });
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   319
                } catch (PrivilegedActionException e) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   320
                    throw new WebServiceException(e);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   321
                }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   322
            }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   323
        }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   324
    }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   325
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   326
    static private class PrivFieldGetter extends FieldGetter {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   327
        private PrivFieldGetter(Field f) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   328
            super(f);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   329
        }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   330
        static private class PrivilegedGetter implements PrivilegedExceptionAction {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   331
            private Object value;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   332
            private Field  field;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   333
            private Object instance;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   334
            public PrivilegedGetter(Field field, Object instance) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   335
                super();
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   336
                this.field = field;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   337
                this.instance = instance;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   338
            }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   339
            public Object run() throws IllegalAccessException {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   340
                if (!field.isAccessible()) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   341
                    field.setAccessible(true);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   342
                }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   343
                value = field.get(instance);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   344
                return null;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   345
            }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   346
        }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   347
        private Object getPriv(final Object instance) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   348
            if (field.isAccessible()) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   349
                try {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   350
                    return field.get(instance);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   351
                } catch (Exception e) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   352
                    throw new WebServiceException(e);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   353
                }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   354
            } else {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   355
                PrivilegedGetter privilegedGetter = new PrivilegedGetter(field, instance);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   356
                try {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   357
                    AccessController.doPrivileged(privilegedGetter);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   358
                } catch (PrivilegedActionException e) {
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   359
                    throw new WebServiceException(e);
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   360
                }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   361
                return privilegedGetter.value;
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   362
            }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   363
        }
953bfc3fbe31 8036030: Update JAX-WS RI integration to latest version
mkos
parents: 18372
diff changeset
   364
    }
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   365
}