src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/ElementBeanInfoImpl.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
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.bind.v2.runtime;
  27 
  28 import java.io.IOException;
  29 import java.lang.reflect.Constructor;
  30 import java.lang.reflect.InvocationTargetException;
  31 
  32 import javax.xml.bind.JAXBElement;
  33 import javax.xml.bind.JAXBException;
  34 import javax.xml.namespace.QName;
  35 import javax.xml.stream.XMLStreamException;
  36 
  37 import com.sun.xml.internal.bind.api.AccessorException;
  38 import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
  39 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
  40 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElementInfo;
  41 import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
  42 import com.sun.xml.internal.bind.v2.runtime.property.Property;
  43 import com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory;
  44 import com.sun.xml.internal.bind.v2.runtime.property.UnmarshallerChain;
  45 import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
  46 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.ChildLoader;
  47 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Discarder;
  48 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Intercepter;
  49 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;
  50 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.TagName;
  51 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
  52 import com.sun.xml.internal.bind.v2.util.QNameMap;
  53 
  54 import org.xml.sax.SAXException;
  55 
  56 /**
  57  * {@link JaxBeanInfo} implementation for {@link RuntimeElementInfo}.
  58  *
  59  * @author Kohsuke Kawaguchi


  64 
  65     private final Property property;
  66 
  67     // used to create new instances of JAXBElement.
  68     private final QName tagName;
  69     public final Class expectedType;
  70     private final Class scope;
  71 
  72     /**
  73      * If non-null, use this to create an instance.
  74      * It takes one value.
  75      */
  76     private final Constructor<? extends JAXBElement> constructor;
  77 
  78     ElementBeanInfoImpl(JAXBContextImpl grammar, RuntimeElementInfo rei) {
  79         super(grammar,rei,(Class<JAXBElement>)rei.getType(),true,false,true);
  80 
  81         this.property = PropertyFactory.create(grammar,rei.getProperty());
  82 
  83         tagName = rei.getElementName();
  84         expectedType = Navigator.REFLECTION.erasure(rei.getContentInMemoryType());
  85         scope = rei.getScope()==null ? JAXBElement.GlobalScope.class : rei.getScope().getClazz();
  86 
  87         Class type = Navigator.REFLECTION.erasure(rei.getType());
  88         if(type==JAXBElement.class)
  89             constructor = null;
  90         else {
  91             try {
  92                 constructor = type.getConstructor(expectedType);
  93             } catch (NoSuchMethodException e) {
  94                 NoSuchMethodError x = new NoSuchMethodError("Failed to find the constructor for " + type + " with " + expectedType);
  95                 x.initCause(e);
  96                 throw x;
  97             }
  98         }
  99     }
 100 
 101     /**
 102      * The constructor for the sole instanceof {@link JaxBeanInfo} for
 103      * handling user-created {@link JAXBElement}.
 104      *
 105      * Such {@link JaxBeanInfo} is used only for marshalling.
 106      *
 107      * This is a hack.


   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
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.bind.v2.runtime;
  27 
  28 import java.io.IOException;
  29 import java.lang.reflect.Constructor;
  30 import java.lang.reflect.InvocationTargetException;
  31 
  32 import javax.xml.bind.JAXBElement;
  33 import javax.xml.bind.JAXBException;
  34 import javax.xml.namespace.QName;
  35 import javax.xml.stream.XMLStreamException;
  36 
  37 import com.sun.xml.internal.bind.api.AccessorException;
  38 import com.sun.xml.internal.bind.v2.model.core.PropertyKind;

  39 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElementInfo;
  40 import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo;
  41 import com.sun.xml.internal.bind.v2.runtime.property.Property;
  42 import com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory;
  43 import com.sun.xml.internal.bind.v2.runtime.property.UnmarshallerChain;
  44 import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
  45 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.ChildLoader;
  46 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Discarder;
  47 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Intercepter;
  48 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;
  49 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.TagName;
  50 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
  51 import com.sun.xml.internal.bind.v2.util.QNameMap;
  52 
  53 import org.xml.sax.SAXException;
  54 
  55 /**
  56  * {@link JaxBeanInfo} implementation for {@link RuntimeElementInfo}.
  57  *
  58  * @author Kohsuke Kawaguchi


  63 
  64     private final Property property;
  65 
  66     // used to create new instances of JAXBElement.
  67     private final QName tagName;
  68     public final Class expectedType;
  69     private final Class scope;
  70 
  71     /**
  72      * If non-null, use this to create an instance.
  73      * It takes one value.
  74      */
  75     private final Constructor<? extends JAXBElement> constructor;
  76 
  77     ElementBeanInfoImpl(JAXBContextImpl grammar, RuntimeElementInfo rei) {
  78         super(grammar,rei,(Class<JAXBElement>)rei.getType(),true,false,true);
  79 
  80         this.property = PropertyFactory.create(grammar,rei.getProperty());
  81 
  82         tagName = rei.getElementName();
  83         expectedType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(rei.getContentInMemoryType());
  84         scope = rei.getScope()==null ? JAXBElement.GlobalScope.class : rei.getScope().getClazz();
  85 
  86         Class type = (Class) Utils.REFLECTION_NAVIGATOR.erasure(rei.getType());
  87         if(type==JAXBElement.class)
  88             constructor = null;
  89         else {
  90             try {
  91                 constructor = type.getConstructor(expectedType);
  92             } catch (NoSuchMethodException e) {
  93                 NoSuchMethodError x = new NoSuchMethodError("Failed to find the constructor for " + type + " with " + expectedType);
  94                 x.initCause(e);
  95                 throw x;
  96             }
  97         }
  98     }
  99 
 100     /**
 101      * The constructor for the sole instanceof {@link JaxBeanInfo} for
 102      * handling user-created {@link JAXBElement}.
 103      *
 104      * Such {@link JaxBeanInfo} is used only for marshalling.
 105      *
 106      * This is a hack.