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
191 }
192
193 };
194 }
195
196 /**
197 * Use the previous {@link UnmarshallingContext.State}'s target to store
198 * {@link JAXBElement} object to be unmarshalled. This allows the property {@link Loader}
199 * to correctly find the parent object.
200 * This is a hack.
201 */
202 private final class IntercepterLoader extends Loader implements Intercepter {
203 private final Loader core;
204
205 public IntercepterLoader(Loader core) {
206 this.core = core;
207 }
208
209 @Override
210 public final void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
211 state.loader = core;
212 state.intercepter = this;
213
214 // TODO: make sure there aren't too many duplicate of this code
215 // create the object to unmarshal
216 Object child;
217 UnmarshallingContext context = state.getContext();
218
219 // let's see if we can reuse the existing peer object
220 child = context.getOuterPeer();
221
222 if(child!=null && jaxbType!=child.getClass())
223 child = null; // unexpected type.
224
225 if(child!=null)
226 reset((JAXBElement)child,context);
227
228 if(child==null)
229 child = context.createInstance(ElementBeanInfoImpl.this);
230
231 fireBeforeUnmarshal(ElementBeanInfoImpl.this, child, state);
232
233 context.recordOuterPeer(child);
234 UnmarshallingContext.State p = state.prev;
235 p.backup = p.target;
236 p.target = child;
237
238 core.startElement(state,ea);
239 }
240
241 public Object intercept(UnmarshallingContext.State state, Object o) throws SAXException {
242 JAXBElement e = (JAXBElement)state.target;
243 state.target = state.backup;
244 state.backup = null;
245
246 if (state.nil) {
247 e.setNil(true);
248 state.nil = false;
249 }
250
251 if(o!=null)
252 // if the value is a leaf type, it's often already set to the element
253 // through Accessor.
254 e.setValue(o);
255
256 fireAfterUnmarshal(ElementBeanInfoImpl.this, e, state);
257
258 return e;
259 }
260 }
261
262 public String getElementNamespaceURI(JAXBElement e) {
263 return e.getName().getNamespaceURI();
264 }
265
266 public String getElementLocalName(JAXBElement e) {
267 return e.getName().getLocalPart();
268 }
|
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
191 }
192
193 };
194 }
195
196 /**
197 * Use the previous {@link UnmarshallingContext.State}'s target to store
198 * {@link JAXBElement} object to be unmarshalled. This allows the property {@link Loader}
199 * to correctly find the parent object.
200 * This is a hack.
201 */
202 private final class IntercepterLoader extends Loader implements Intercepter {
203 private final Loader core;
204
205 public IntercepterLoader(Loader core) {
206 this.core = core;
207 }
208
209 @Override
210 public final void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException {
211 state.setLoader(core);
212 state.setIntercepter(this);
213
214 // TODO: make sure there aren't too many duplicate of this code
215 // create the object to unmarshal
216 Object child;
217 UnmarshallingContext context = state.getContext();
218
219 // let's see if we can reuse the existing peer object
220 child = context.getOuterPeer();
221
222 if(child!=null && jaxbType!=child.getClass())
223 child = null; // unexpected type.
224
225 if(child!=null)
226 reset((JAXBElement)child,context);
227
228 if(child==null)
229 child = context.createInstance(ElementBeanInfoImpl.this);
230
231 fireBeforeUnmarshal(ElementBeanInfoImpl.this, child, state);
232
233 context.recordOuterPeer(child);
234 UnmarshallingContext.State p = state.getPrev();
235 p.setBackup(p.getTarget());
236 p.setTarget(child);
237
238 core.startElement(state,ea);
239 }
240
241 public Object intercept(UnmarshallingContext.State state, Object o) throws SAXException {
242 JAXBElement e = (JAXBElement)state.getTarget();
243 state.setTarget(state.getBackup());
244 state.setBackup(null);
245
246 if (state.isNil()) {
247 e.setNil(true);
248 state.setNil(false);
249 }
250
251 if(o!=null)
252 // if the value is a leaf type, it's often already set to the element
253 // through Accessor.
254 e.setValue(o);
255
256 fireAfterUnmarshal(ElementBeanInfoImpl.this, e, state);
257
258 return e;
259 }
260 }
261
262 public String getElementNamespaceURI(JAXBElement e) {
263 return e.getName().getNamespaceURI();
264 }
265
266 public String getElementLocalName(JAXBElement e) {
267 return e.getName().getLocalPart();
268 }
|