Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.bind.v2.runtime.property; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.io.IOException; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import javax.xml.bind.JAXBException; |
aoqi@0 | 31 | import javax.xml.bind.annotation.DomHandler; |
aoqi@0 | 32 | import javax.xml.stream.XMLStreamException; |
aoqi@0 | 33 | |
aoqi@0 | 34 | import com.sun.xml.internal.bind.v2.ClassFactory; |
aoqi@0 | 35 | import com.sun.xml.internal.bind.v2.model.core.PropertyKind; |
aoqi@0 | 36 | import com.sun.xml.internal.bind.v2.model.core.WildcardMode; |
aoqi@0 | 37 | import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElement; |
aoqi@0 | 38 | import com.sun.xml.internal.bind.v2.model.runtime.RuntimeReferencePropertyInfo; |
aoqi@0 | 39 | import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; |
aoqi@0 | 40 | import com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo; |
aoqi@0 | 41 | import com.sun.xml.internal.bind.v2.runtime.XMLSerializer; |
aoqi@0 | 42 | import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor; |
aoqi@0 | 43 | import com.sun.xml.internal.bind.v2.runtime.reflect.ListIterator; |
aoqi@0 | 44 | import com.sun.xml.internal.bind.v2.runtime.unmarshaller.ChildLoader; |
aoqi@0 | 45 | import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader; |
aoqi@0 | 46 | import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Receiver; |
aoqi@0 | 47 | import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext; |
aoqi@0 | 48 | import com.sun.xml.internal.bind.v2.runtime.unmarshaller.WildcardLoader; |
aoqi@0 | 49 | import com.sun.xml.internal.bind.v2.util.QNameMap; |
aoqi@0 | 50 | |
aoqi@0 | 51 | import org.xml.sax.SAXException; |
aoqi@0 | 52 | |
aoqi@0 | 53 | /** |
aoqi@0 | 54 | * @author Kohsuke Kawaguchi |
aoqi@0 | 55 | */ |
aoqi@0 | 56 | class ArrayReferenceNodeProperty<BeanT,ListT,ItemT> extends ArrayERProperty<BeanT,ListT,ItemT> { |
aoqi@0 | 57 | |
aoqi@0 | 58 | /** |
aoqi@0 | 59 | * Expected element names and what class to unmarshal. |
aoqi@0 | 60 | */ |
aoqi@0 | 61 | private final QNameMap<JaxBeanInfo> expectedElements = new QNameMap<JaxBeanInfo>(); |
aoqi@0 | 62 | |
aoqi@0 | 63 | private final boolean isMixed; |
aoqi@0 | 64 | |
aoqi@0 | 65 | private final DomHandler domHandler; |
aoqi@0 | 66 | private final WildcardMode wcMode; |
aoqi@0 | 67 | |
aoqi@0 | 68 | public ArrayReferenceNodeProperty(JAXBContextImpl p, RuntimeReferencePropertyInfo prop) { |
aoqi@0 | 69 | super(p, prop, prop.getXmlName(), prop.isCollectionNillable()); |
aoqi@0 | 70 | |
aoqi@0 | 71 | for (RuntimeElement e : prop.getElements()) { |
aoqi@0 | 72 | JaxBeanInfo bi = p.getOrCreate(e); |
aoqi@0 | 73 | expectedElements.put( e.getElementName().getNamespaceURI(),e.getElementName().getLocalPart(), bi ); |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | isMixed = prop.isMixed(); |
aoqi@0 | 77 | |
aoqi@0 | 78 | if(prop.getWildcard()!=null) { |
aoqi@0 | 79 | domHandler = (DomHandler) ClassFactory.create(prop.getDOMHandler()); |
aoqi@0 | 80 | wcMode = prop.getWildcard(); |
aoqi@0 | 81 | } else { |
aoqi@0 | 82 | domHandler = null; |
aoqi@0 | 83 | wcMode = null; |
aoqi@0 | 84 | } |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | protected final void serializeListBody(BeanT o, XMLSerializer w, ListT list) throws IOException, XMLStreamException, SAXException { |
aoqi@0 | 88 | ListIterator<ItemT> itr = lister.iterator(list, w); |
aoqi@0 | 89 | |
aoqi@0 | 90 | while(itr.hasNext()) { |
aoqi@0 | 91 | try { |
aoqi@0 | 92 | ItemT item = itr.next(); |
aoqi@0 | 93 | if (item != null) { |
aoqi@0 | 94 | if(isMixed && item.getClass()==String.class) { |
aoqi@0 | 95 | w.text((String)item,null); |
aoqi@0 | 96 | } else { |
aoqi@0 | 97 | JaxBeanInfo bi = w.grammar.getBeanInfo(item,true); |
aoqi@0 | 98 | if(bi.jaxbType==Object.class && domHandler!=null) |
aoqi@0 | 99 | // even if 'v' is a DOM node, it always derive from Object, |
aoqi@0 | 100 | // so the getBeanInfo returns BeanInfo for Object |
aoqi@0 | 101 | w.writeDom(item,domHandler,o,fieldName); |
aoqi@0 | 102 | else |
aoqi@0 | 103 | bi.serializeRoot(item,w); |
aoqi@0 | 104 | } |
aoqi@0 | 105 | } |
aoqi@0 | 106 | } catch (JAXBException e) { |
aoqi@0 | 107 | w.reportError(fieldName,e); |
aoqi@0 | 108 | // recover by ignoring this item |
aoqi@0 | 109 | } |
aoqi@0 | 110 | } |
aoqi@0 | 111 | } |
aoqi@0 | 112 | |
aoqi@0 | 113 | public void createBodyUnmarshaller(UnmarshallerChain chain, QNameMap<ChildLoader> loaders) { |
aoqi@0 | 114 | final int offset = chain.allocateOffset(); |
aoqi@0 | 115 | |
aoqi@0 | 116 | Receiver recv = new ReceiverImpl(offset); |
aoqi@0 | 117 | |
aoqi@0 | 118 | for( QNameMap.Entry<JaxBeanInfo> n : expectedElements.entrySet() ) { |
aoqi@0 | 119 | final JaxBeanInfo beanInfo = n.getValue(); |
aoqi@0 | 120 | loaders.put(n.nsUri,n.localName,new ChildLoader(beanInfo.getLoader(chain.context,true),recv)); |
aoqi@0 | 121 | } |
aoqi@0 | 122 | |
aoqi@0 | 123 | if(isMixed) { |
aoqi@0 | 124 | // handler for processing mixed contents. |
aoqi@0 | 125 | loaders.put(TEXT_HANDLER, |
aoqi@0 | 126 | new ChildLoader(new MixedTextLoader(recv),null)); |
aoqi@0 | 127 | } |
aoqi@0 | 128 | |
aoqi@0 | 129 | if(domHandler!=null) { |
aoqi@0 | 130 | loaders.put(CATCH_ALL, |
aoqi@0 | 131 | new ChildLoader(new WildcardLoader(domHandler,wcMode),recv)); |
aoqi@0 | 132 | } |
aoqi@0 | 133 | } |
aoqi@0 | 134 | |
aoqi@0 | 135 | private static final class MixedTextLoader extends Loader { |
aoqi@0 | 136 | |
aoqi@0 | 137 | private final Receiver recv; |
aoqi@0 | 138 | |
aoqi@0 | 139 | public MixedTextLoader(Receiver recv) { |
aoqi@0 | 140 | super(true); |
aoqi@0 | 141 | this.recv = recv; |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException { |
aoqi@0 | 145 | if(text.length()!=0) // length 0 text is pointless |
aoqi@0 | 146 | recv.receive(state,text.toString()); |
aoqi@0 | 147 | } |
aoqi@0 | 148 | } |
aoqi@0 | 149 | |
aoqi@0 | 150 | |
aoqi@0 | 151 | public PropertyKind getKind() { |
aoqi@0 | 152 | return PropertyKind.REFERENCE; |
aoqi@0 | 153 | } |
aoqi@0 | 154 | |
aoqi@0 | 155 | @Override |
aoqi@0 | 156 | public Accessor getElementPropertyAccessor(String nsUri, String localName) { |
aoqi@0 | 157 | // TODO: unwrap JAXBElement |
aoqi@0 | 158 | if(wrapperTagName!=null) { |
aoqi@0 | 159 | if(wrapperTagName.equals(nsUri,localName)) |
aoqi@0 | 160 | return acc; |
aoqi@0 | 161 | } else { |
aoqi@0 | 162 | if(expectedElements.containsKey(nsUri,localName)) |
aoqi@0 | 163 | return acc; |
aoqi@0 | 164 | } |
aoqi@0 | 165 | return null; |
aoqi@0 | 166 | } |
aoqi@0 | 167 | } |