1 /*
2 * Copyright (c) 1997, 2012, 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
155 UnmarshallingContext context = state.getContext();
156
157 // create the object to unmarshal
158 Object child;
159 assert !beanInfo.isImmutable();
160
161 // let's see if we can reuse the existing peer object
162 child = context.getInnerPeer();
163
164 if(child != null && beanInfo.jaxbType!=child.getClass())
165 child = null; // unexpected type.
166
167 if(child != null)
168 beanInfo.reset(child,context);
169
170 if(child == null)
171 child = context.createInstance(beanInfo);
172
173 context.recordInnerPeer(child);
174
175 state.target = child;
176
177 fireBeforeUnmarshal(beanInfo, child, state);
178
179
180 context.startScope(frameSize);
181
182 if(attUnmarshallers!=null) {
183 Attributes atts = ea.atts;
184 for (int i = 0; i < atts.getLength(); i ++){
185 String auri = atts.getURI(i);
186 // may be empty string based on parser settings
187 String alocal = atts.getLocalName(i);
188 if ("".equals(alocal)) {
189 alocal = atts.getQName(i);
190 }
191 String avalue = atts.getValue(i);
192 TransducedAccessor xacc = attUnmarshallers.get(auri, alocal);
193 try {
194 if(xacc!=null) {
195 xacc.parse(child,avalue);
196 } else if (attCatchAll!=null) {
197 String qname = atts.getQName(i);
198 if(atts.getURI(i).equals(WellKnownNamespace.XML_SCHEMA_INSTANCE))
199 continue; // xsi:* attributes are meant to be processed by us, not by user apps.
200 Object o = state.target;
201 Map<QName,String> map = attCatchAll.get(o);
202 if(map==null) {
203 // TODO: use ClassFactory.inferImplClass(sig,knownImplClasses)
204
205 // if null, create a new map.
206 if(attCatchAll.valueType.isAssignableFrom(HashMap.class))
207 map = new HashMap<QName,String>();
208 else {
209 // we don't know how to create a map for this.
210 // report an error and back out
211 context.handleError(Messages.UNABLE_TO_CREATE_MAP.format(attCatchAll.valueType));
212 return;
213 }
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);
233 ChildLoader child = childUnmarshallers.get(arg.uri,arg.local);
234 if(child==null) {
235 if ((beanInfo != null) && (beanInfo.getTypeNames() != null)) {
236 Iterator typeNamesIt = beanInfo.getTypeNames().iterator();
237 QName parentQName = null;
238 if ((typeNamesIt != null) && (typeNamesIt.hasNext()) && (catchAll == null)) {
239 parentQName = (QName) typeNamesIt.next();
240 String parentUri = parentQName.getNamespaceURI();
241 child = childUnmarshallers.get(parentUri, arg.local);
242 }
243 }
244 if (child == null) {
245 child = catchAll;
246 if(child==null) {
247 super.childElement(state,arg);
248 return;
249 }
250 }
251 }
252
253 state.loader = child.loader;
254 state.receiver = child.receiver;
255 }
256
257 @Override
258 public Collection<QName> getExpectedChildElements() {
259 return childUnmarshallers.keySet();
260 }
261
262 @Override
263 public Collection<QName> getExpectedAttributes() {
264 return attUnmarshallers.keySet();
265 }
266
267 @Override
268 public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException {
269 if(textHandler!=null)
270 textHandler.loader.text(state,text);
271 }
272
273 @Override
274 public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
275 state.getContext().endScope(frameSize);
276 fireAfterUnmarshal(beanInfo, state.target, state.prev);
277 }
278
279 private static final QNameMap<TransducedAccessor> EMPTY = new QNameMap<TransducedAccessor>();
280
281 public JaxBeanInfo getBeanInfo() {
282 return beanInfo;
283 }
284 }
|
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
155 UnmarshallingContext context = state.getContext();
156
157 // create the object to unmarshal
158 Object child;
159 assert !beanInfo.isImmutable();
160
161 // let's see if we can reuse the existing peer object
162 child = context.getInnerPeer();
163
164 if(child != null && beanInfo.jaxbType!=child.getClass())
165 child = null; // unexpected type.
166
167 if(child != null)
168 beanInfo.reset(child,context);
169
170 if(child == null)
171 child = context.createInstance(beanInfo);
172
173 context.recordInnerPeer(child);
174
175 state.setTarget(child);
176
177 fireBeforeUnmarshal(beanInfo, child, state);
178
179
180 context.startScope(frameSize);
181
182 if(attUnmarshallers!=null) {
183 Attributes atts = ea.atts;
184 for (int i = 0; i < atts.getLength(); i ++){
185 String auri = atts.getURI(i);
186 // may be empty string based on parser settings
187 String alocal = atts.getLocalName(i);
188 if ("".equals(alocal)) {
189 alocal = atts.getQName(i);
190 }
191 String avalue = atts.getValue(i);
192 TransducedAccessor xacc = attUnmarshallers.get(auri, alocal);
193 try {
194 if(xacc!=null) {
195 xacc.parse(child,avalue);
196 } else if (attCatchAll!=null) {
197 String qname = atts.getQName(i);
198 if(atts.getURI(i).equals(WellKnownNamespace.XML_SCHEMA_INSTANCE))
199 continue; // xsi:* attributes are meant to be processed by us, not by user apps.
200 Object o = state.getTarget();
201 Map<QName,String> map = attCatchAll.get(o);
202 if(map==null) {
203 // TODO: use ClassFactory.inferImplClass(sig,knownImplClasses)
204
205 // if null, create a new map.
206 if(attCatchAll.valueType.isAssignableFrom(HashMap.class))
207 map = new HashMap<QName,String>();
208 else {
209 // we don't know how to create a map for this.
210 // report an error and back out
211 context.handleError(Messages.UNABLE_TO_CREATE_MAP.format(attCatchAll.valueType));
212 return;
213 }
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);
233 ChildLoader child = childUnmarshallers.get(arg.uri,arg.local);
234 if(child==null) {
235 if ((beanInfo != null) && (beanInfo.getTypeNames() != null)) {
236 Iterator typeNamesIt = beanInfo.getTypeNames().iterator();
237 QName parentQName = null;
238 if ((typeNamesIt != null) && (typeNamesIt.hasNext()) && (catchAll == null)) {
239 parentQName = (QName) typeNamesIt.next();
240 String parentUri = parentQName.getNamespaceURI();
241 child = childUnmarshallers.get(parentUri, arg.local);
242 }
243 }
244 if (child == null) {
245 child = catchAll;
246 if(child==null) {
247 super.childElement(state,arg);
248 return;
249 }
250 }
251 }
252
253 state.setLoader(child.loader);
254 state.setReceiver(child.receiver);
255 }
256
257 @Override
258 public Collection<QName> getExpectedChildElements() {
259 return childUnmarshallers.keySet();
260 }
261
262 @Override
263 public Collection<QName> getExpectedAttributes() {
264 return attUnmarshallers.keySet();
265 }
266
267 @Override
268 public void text(UnmarshallingContext.State state, CharSequence text) throws SAXException {
269 if(textHandler!=null)
270 textHandler.loader.text(state,text);
271 }
272
273 @Override
274 public void leaveElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
275 state.getContext().endScope(frameSize);
276 fireAfterUnmarshal(beanInfo, state.getTarget(), state.getPrev());
277 }
278
279 private static final QNameMap<TransducedAccessor> EMPTY = new QNameMap<TransducedAccessor>();
280
281 public JaxBeanInfo getBeanInfo() {
282 return beanInfo;
283 }
284 }
|