01: /*
02: * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation; either version 2 of the License, or
12: * (at your option) any later version.
13: *
14: * Resin Open Source is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17: * of NON-INFRINGEMENT. See the GNU General Public License for more
18: * details.
19: *
20: * You should have received a copy of the GNU General Public License
21: * along with Resin Open Source; if not, write to the
22: *
23: * Free Software Foundation, Inc.
24: * 59 Temple Place, Suite 330
25: * Boston, MA 02111-1307 USA
26: *
27: * @author Emil Ong
28: */
29:
30: package com.caucho.jaxb.skeleton;
31:
32: import com.caucho.jaxb.JAXBContextImpl;
33: import com.caucho.jaxb.accessor.Accessor;
34: import com.caucho.jaxb.accessor.JAXBElementAccessor;
35: import com.caucho.jaxb.mapping.JAXBElementMapping;
36: import com.caucho.util.L10N;
37:
38: import javax.xml.bind.annotation.*;
39: import javax.xml.bind.JAXBElement;
40: import javax.xml.bind.JAXBException;
41: import javax.xml.namespace.QName;
42:
43: import java.lang.reflect.Method;
44: import java.util.logging.Logger;
45:
46: public class JAXBElementSkeleton<C> extends
47: ClassSkeleton<JAXBElement<C>> {
48: private static final Logger log = Logger
49: .getLogger(JAXBElementSkeleton.class.getName());
50: private static final L10N L = new L10N(JAXBElementSkeleton.class);
51: private static final Object[] SINGLE_NULL_ARG = new Object[] { null };
52:
53: private final Class<C> _contents;
54: private final Method _createMethod;
55: private final Object _factory;
56: private final JAXBElementAccessor _accessor;
57:
58: public JAXBElementSkeleton(JAXBContextImpl context, Class<C> cl,
59: Method createMethod, Object factory) throws JAXBException {
60: super (context);
61:
62: _contents = cl;
63: _createMethod = createMethod;
64: _factory = factory;
65:
66: JAXBElementMapping mapping = new JAXBElementMapping(context);
67: mapping.setQName(_elementName);
68: mapping.setProperty(context.createProperty(cl));
69: _value = mapping;
70:
71: _accessor = (JAXBElementAccessor) _value.getAccessor();
72: _accessor.setType(cl);
73: }
74:
75: public JAXBElement<C> newInstance() throws JAXBException {
76: try {
77: // passing a null makes invoke think that it is receiving a null instance
78: // of an Object[]. need an explicit array with a null.
79: return (JAXBElement<C>) _createMethod.invoke(_factory,
80: SINGLE_NULL_ARG);
81: } catch (Exception e) {
82: throw new JAXBException(e);
83: }
84: }
85:
86: public String toString() {
87: return "JAXBElementSkeleton[" + _contents + "]";
88: }
89: }
|