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
25
26 package com.sun.xml.internal.bind.v2.runtime.property;
27
28 import java.io.IOException;
29 import java.util.HashMap;
30 import java.util.LinkedHashMap;
31 import java.util.Map;
32 import java.util.TreeMap;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.Arrays;
36 import java.util.Set;
37
38 import javax.xml.stream.XMLStreamException;
39 import javax.xml.namespace.QName;
40
41 import com.sun.xml.internal.bind.api.AccessorException;
42 import com.sun.xml.internal.bind.v2.ClassFactory;
43 import com.sun.xml.internal.bind.v2.util.QNameMap;
44 import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
45 import com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator;
46 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeMapPropertyInfo;
47 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
48 import com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo;
49 import com.sun.xml.internal.bind.v2.runtime.Name;
50 import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
51 import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
52 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.ChildLoader;
53 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.TagName;
54 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;
55 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Receiver;
56 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
57 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.State;
58
59 import org.xml.sax.SAXException;
60
61 /**
62 * @author Kohsuke Kawaguchi
63 */
64 final class SingleMapNodeProperty<BeanT,ValueT extends Map> extends PropertyImpl<BeanT> {
65
81 private JaxBeanInfo valueBeanInfo;
82
83 /**
84 * The implementation class for this property.
85 * If the property is null, we create an instance of this class.
86 */
87 private final Class<? extends ValueT> mapImplClass;
88
89 public SingleMapNodeProperty(JAXBContextImpl context, RuntimeMapPropertyInfo prop) {
90 super(context, prop);
91 acc = prop.getAccessor().optimize(context);
92 this.tagName = context.nameBuilder.createElementName(prop.getXmlName());
93 this.entryTag = context.nameBuilder.createElementName("","entry");
94 this.keyTag = context.nameBuilder.createElementName("","key");
95 this.valueTag = context.nameBuilder.createElementName("","value");
96 this.nillable = prop.isCollectionNillable();
97 this.keyBeanInfo = context.getOrCreate(prop.getKeyType());
98 this.valueBeanInfo = context.getOrCreate(prop.getValueType());
99
100 // infer the implementation class
101 Class<ValueT> sig = ReflectionNavigator.REFLECTION.erasure(prop.getRawType());
102 mapImplClass = ClassFactory.inferImplClass(sig,knownImplClasses);
103 // TODO: error check for mapImplClass==null
104 // what is the error reporting path for this part of the code?
105 }
106
107 private static final Class[] knownImplClasses = {
108 HashMap.class, TreeMap.class, LinkedHashMap.class
109 };
110
111 public void reset(BeanT bean) throws AccessorException {
112 acc.set(bean,null);
113 }
114
115
116 /**
117 * A Map property can never be ID.
118 */
119 public String getIdValue(BeanT bean) {
120 return null;
121 }
|
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
25
26 package com.sun.xml.internal.bind.v2.runtime.property;
27
28 import java.io.IOException;
29 import java.util.HashMap;
30 import java.util.LinkedHashMap;
31 import java.util.Map;
32 import java.util.TreeMap;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.Arrays;
36 import java.util.Set;
37
38 import javax.xml.stream.XMLStreamException;
39 import javax.xml.namespace.QName;
40
41 import com.sun.xml.internal.bind.api.AccessorException;
42 import com.sun.xml.internal.bind.v2.ClassFactory;
43 import com.sun.xml.internal.bind.v2.util.QNameMap;
44 import com.sun.xml.internal.bind.v2.model.core.PropertyKind;
45 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeMapPropertyInfo;
46 import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
47 import com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo;
48 import com.sun.xml.internal.bind.v2.runtime.Name;
49 import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
50 import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
51 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.ChildLoader;
52 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.TagName;
53 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;
54 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Receiver;
55 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
56 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.State;
57
58 import org.xml.sax.SAXException;
59
60 /**
61 * @author Kohsuke Kawaguchi
62 */
63 final class SingleMapNodeProperty<BeanT,ValueT extends Map> extends PropertyImpl<BeanT> {
64
80 private JaxBeanInfo valueBeanInfo;
81
82 /**
83 * The implementation class for this property.
84 * If the property is null, we create an instance of this class.
85 */
86 private final Class<? extends ValueT> mapImplClass;
87
88 public SingleMapNodeProperty(JAXBContextImpl context, RuntimeMapPropertyInfo prop) {
89 super(context, prop);
90 acc = prop.getAccessor().optimize(context);
91 this.tagName = context.nameBuilder.createElementName(prop.getXmlName());
92 this.entryTag = context.nameBuilder.createElementName("","entry");
93 this.keyTag = context.nameBuilder.createElementName("","key");
94 this.valueTag = context.nameBuilder.createElementName("","value");
95 this.nillable = prop.isCollectionNillable();
96 this.keyBeanInfo = context.getOrCreate(prop.getKeyType());
97 this.valueBeanInfo = context.getOrCreate(prop.getValueType());
98
99 // infer the implementation class
100 //noinspection unchecked
101 Class<ValueT> sig = (Class<ValueT>) Utils.REFLECTION_NAVIGATOR.erasure(prop.getRawType());
102 mapImplClass = ClassFactory.inferImplClass(sig,knownImplClasses);
103 // TODO: error check for mapImplClass==null
104 // what is the error reporting path for this part of the code?
105 }
106
107 private static final Class[] knownImplClasses = {
108 HashMap.class, TreeMap.class, LinkedHashMap.class
109 };
110
111 public void reset(BeanT bean) throws AccessorException {
112 acc.set(bean,null);
113 }
114
115
116 /**
117 * A Map property can never be ID.
118 */
119 public String getIdValue(BeanT bean) {
120 return null;
121 }
|