1 /*
2 * Copyright (c) 1997, 2016, 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.unmarshaller;
27
28 import java.util.Collection;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import javax.xml.namespace.QName;
33
34 import com.sun.xml.internal.bind.api.AccessorException;
35 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
36 import com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl;
37 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
38 import com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo;
39 import com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty;
40 import com.sun.xml.internal.bind.v2.runtime.property.Property;
41 import com.sun.xml.internal.bind.v2.runtime.property.StructureLoaderBuilder;
42 import com.sun.xml.internal.bind.v2.runtime.property.UnmarshallerChain;
43 import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
44 import com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor;
45 import com.sun.xml.internal.bind.v2.util.QNameMap;
46
47 import java.util.Iterator;
48 import org.xml.sax.Attributes;
49 import org.xml.sax.SAXException;
50
51 /**
52 * Loads children of an element.
53 *
54 * <p>
214 attCatchAll.set(o,map);
215 }
216
217 String prefix;
218 int idx = qname.indexOf(':');
219 if(idx<0) prefix="";
220 else prefix=qname.substring(0,idx);
221
222 map.put(new QName(auri,alocal,prefix),avalue);
223 }
224 } catch (AccessorException e) {
225 handleGenericException(e,true);
226 }
227 }
228 }
229 }
230
231 @Override
232 public void childElement(UnmarshallingContext.State state, TagName arg) throws SAXException {
233 ChildLoader child = childUnmarshallers.get(arg.uri,arg.local);
234 if (child == null) {
235 child = catchAll;
236 if (child==null) {
237 super.childElement(state,arg);
238 return;
239 }
240 }
241
242 state.setLoader(child.loader);
243 state.setReceiver(child.receiver);
244 }
245
246 @Override
247 public Collection<QName> getExpectedChildElements() {
248 return childUnmarshallers.keySet();
249 }
250
251 @Override
252 public Collection<QName> getExpectedAttributes() {
253 return attUnmarshallers.keySet();
254 }
255
256 @Override
257 public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException {
258 if(textHandler!=null)
|
1 /*
2 * Copyright (c) 1997, 2017, 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.unmarshaller;
27
28 import java.util.Collection;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import javax.xml.namespace.QName;
33
34 import com.sun.xml.internal.bind.Util;
35 import com.sun.xml.internal.bind.api.AccessorException;
36 import com.sun.xml.internal.bind.api.JAXBRIContext;
37 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
38 import com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl;
39 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
40 import com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo;
41 import com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty;
42 import com.sun.xml.internal.bind.v2.runtime.property.Property;
43 import com.sun.xml.internal.bind.v2.runtime.property.StructureLoaderBuilder;
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.reflect.TransducedAccessor;
47 import com.sun.xml.internal.bind.v2.util.QNameMap;
48
49 import java.util.Iterator;
50 import org.xml.sax.Attributes;
51 import org.xml.sax.SAXException;
52
53 /**
54 * Loads children of an element.
55 *
56 * <p>
216 attCatchAll.set(o,map);
217 }
218
219 String prefix;
220 int idx = qname.indexOf(':');
221 if(idx<0) prefix="";
222 else prefix=qname.substring(0,idx);
223
224 map.put(new QName(auri,alocal,prefix),avalue);
225 }
226 } catch (AccessorException e) {
227 handleGenericException(e,true);
228 }
229 }
230 }
231 }
232
233 @Override
234 public void childElement(UnmarshallingContext.State state, TagName arg) throws SAXException {
235 ChildLoader child = childUnmarshallers.get(arg.uri,arg.local);
236 if(child == null) {
237 Boolean backupWithParentNamespace = ((JAXBContextImpl) state.getContext().getJAXBContext()).backupWithParentNamespace;
238 backupWithParentNamespace = backupWithParentNamespace != null
239 ? backupWithParentNamespace
240 : Boolean.parseBoolean(Util.getSystemProperty(JAXBRIContext.BACKUP_WITH_PARENT_NAMESPACE));
241 if ((beanInfo != null) && (beanInfo.getTypeNames() != null) && backupWithParentNamespace) {
242 Iterator<?> typeNamesIt = beanInfo.getTypeNames().iterator();
243 QName parentQName = null;
244 if ((typeNamesIt != null) && (typeNamesIt.hasNext()) && (catchAll == null)) {
245 parentQName = (QName) typeNamesIt.next();
246 String parentUri = parentQName.getNamespaceURI();
247 child = childUnmarshallers.get(parentUri, arg.local);
248 }
249 }
250 if (child == null) {
251 child = catchAll;
252 if(child==null) {
253 super.childElement(state,arg);
254 return;
255 }
256 }
257 }
258
259 state.setLoader(child.loader);
260 state.setReceiver(child.receiver);
261 }
262
263 @Override
264 public Collection<QName> getExpectedChildElements() {
265 return childUnmarshallers.keySet();
266 }
267
268 @Override
269 public Collection<QName> getExpectedAttributes() {
270 return attUnmarshallers.keySet();
271 }
272
273 @Override
274 public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException {
275 if(textHandler!=null)
|