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
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.Iterator;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.WeakHashMap;
40 import java.util.LinkedList;
41 import java.util.HashSet;
42 import java.util.TreeSet;
43 import java.util.Stack;
44 import java.util.concurrent.Callable;
45
46 import javax.xml.bind.JAXBException;
47
48 import com.sun.istack.internal.SAXException2;
49 import com.sun.xml.internal.bind.api.AccessorException;
50 import com.sun.xml.internal.bind.v2.ClassFactory;
51 import com.sun.xml.internal.bind.v2.TODO;
52 import com.sun.xml.internal.bind.v2.model.core.Adapter;
53 import com.sun.xml.internal.bind.v2.model.core.ID;
54 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
55 import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
56 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Patcher;
57 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
58 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.LocatorEx;
59
60 import org.xml.sax.SAXException;
61
62 /**
63 * Used to list individual values of a multi-value property, and
64 * to pack individual values into a multi-value property.
65 *
66 * @author Kohsuke Kawaguchi (kk@kohsuke.org)
67 */
68 public abstract class Lister<BeanT,PropT,ItemT,PackT> {
69
70 protected Lister() {}
71
72 /**
73 * Iterates values of a multi-value property.
74 *
99 /**
100 * Clears the values of the property.
101 */
102 public abstract void reset(BeanT o,Accessor<BeanT,PropT> acc) throws AccessorException;
103
104
105 /**
106 * Gets a reference to the appropriate {@link Lister} object
107 * if the field is a multi-value field. Otherwise null.
108 *
109 * @param fieldType
110 * the type of the field that stores the collection
111 * @param idness
112 * ID-ness of the property.
113 * @param adapter
114 * adapter to be used for individual items. can be null.
115 */
116 public static <BeanT,PropT,ItemT,PackT>
117 Lister<BeanT,PropT,ItemT,PackT> create(Type fieldType,ID idness, Adapter<Type,Class> adapter) {
118
119 Class rawType = Navigator.REFLECTION.erasure(fieldType);
120 Class itemType;
121
122 Lister l;
123 if( rawType.isArray() ) {
124 itemType = rawType.getComponentType();
125 l = getArrayLister(itemType);
126 } else
127 if( Collection.class.isAssignableFrom(rawType) ) {
128 Type bt = Navigator.REFLECTION.getBaseClass(fieldType,Collection.class);
129 if(bt instanceof ParameterizedType)
130 itemType = Navigator.REFLECTION.erasure(((ParameterizedType)bt).getActualTypeArguments()[0]);
131 else
132 itemType = Object.class;
133 l = new CollectionLister(getImplClass(rawType));
134 } else
135 return null;
136
137 if(idness==ID.IDREF)
138 l = new IDREFS(l,itemType);
139
140 if(adapter!=null)
141 l = new AdaptedLister(l,adapter.adapterType);
142
143 return l;
144 }
145
146 private static Class getImplClass(Class<?> fieldType) {
147 return ClassFactory.inferImplClass(fieldType,COLLECTION_IMPL_CLASSES);
148 }
149
150 /**
|
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
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.Iterator;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.WeakHashMap;
40 import java.util.LinkedList;
41 import java.util.HashSet;
42 import java.util.TreeSet;
43 import java.util.Stack;
44 import java.util.concurrent.Callable;
45
46 import javax.xml.bind.JAXBException;
47
48 import com.sun.istack.internal.SAXException2;
49 import com.sun.xml.internal.bind.api.AccessorException;
50 import com.sun.xml.internal.bind.v2.ClassFactory;
51 import com.sun.xml.internal.bind.v2.TODO;
52 import com.sun.xml.internal.bind.v2.model.core.Adapter;
53 import com.sun.xml.internal.bind.v2.model.core.ID;
54 import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
55 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Patcher;
56 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
57 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.LocatorEx;
58
59 import org.xml.sax.SAXException;
60
61 /**
62 * Used to list individual values of a multi-value property, and
63 * to pack individual values into a multi-value property.
64 *
65 * @author Kohsuke Kawaguchi (kk@kohsuke.org)
66 */
67 public abstract class Lister<BeanT,PropT,ItemT,PackT> {
68
69 protected Lister() {}
70
71 /**
72 * Iterates values of a multi-value property.
73 *
98 /**
99 * Clears the values of the property.
100 */
101 public abstract void reset(BeanT o,Accessor<BeanT,PropT> acc) throws AccessorException;
102
103
104 /**
105 * Gets a reference to the appropriate {@link Lister} object
106 * if the field is a multi-value field. Otherwise null.
107 *
108 * @param fieldType
109 * the type of the field that stores the collection
110 * @param idness
111 * ID-ness of the property.
112 * @param adapter
113 * adapter to be used for individual items. can be null.
114 */
115 public static <BeanT,PropT,ItemT,PackT>
116 Lister<BeanT,PropT,ItemT,PackT> create(Type fieldType,ID idness, Adapter<Type,Class> adapter) {
117
118 Class rawType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(fieldType);
119 Class itemType;
120
121 Lister l;
122 if( rawType.isArray() ) {
123 itemType = rawType.getComponentType();
124 l = getArrayLister(itemType);
125 } else
126 if( Collection.class.isAssignableFrom(rawType) ) {
127 Type bt = Utils.REFLECTION_NAVIGATOR.getBaseClass(fieldType,Collection.class);
128 if(bt instanceof ParameterizedType)
129 itemType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(((ParameterizedType)bt).getActualTypeArguments()[0]);
130 else
131 itemType = Object.class;
132 l = new CollectionLister(getImplClass(rawType));
133 } else
134 return null;
135
136 if(idness==ID.IDREF)
137 l = new IDREFS(l,itemType);
138
139 if(adapter!=null)
140 l = new AdaptedLister(l,adapter.adapterType);
141
142 return l;
143 }
144
145 private static Class getImplClass(Class<?> fieldType) {
146 return ClassFactory.inferImplClass(fieldType,COLLECTION_IMPL_CLASSES);
147 }
148
149 /**
|