src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/JaxBeanInfo.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/JaxBeanInfo.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,550 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.bind.v2.runtime;
    1.30 +
    1.31 +import java.io.IOException;
    1.32 +import java.lang.reflect.InvocationTargetException;
    1.33 +import java.lang.reflect.Method;
    1.34 +import java.util.Arrays;
    1.35 +import java.util.Collection;
    1.36 +import java.util.Collections;
    1.37 +import java.util.logging.Level;
    1.38 +import java.util.logging.Logger;
    1.39 +
    1.40 +import javax.xml.bind.JAXBContext;
    1.41 +import javax.xml.bind.Marshaller;
    1.42 +import javax.xml.bind.Unmarshaller;
    1.43 +import javax.xml.datatype.XMLGregorianCalendar;
    1.44 +import javax.xml.namespace.QName;
    1.45 +import javax.xml.stream.XMLStreamException;
    1.46 +
    1.47 +import com.sun.istack.internal.NotNull;
    1.48 +import com.sun.xml.internal.bind.Util;
    1.49 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfo;
    1.50 +import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;
    1.51 +import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl;
    1.52 +import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
    1.53 +
    1.54 +import org.xml.sax.SAXException;
    1.55 +
    1.56 +/**
    1.57 + * Encapsulates various JAXB operations on objects bound by JAXB.
    1.58 + * Immutable and thread-safe.
    1.59 + *
    1.60 + * <p>
    1.61 + * Each JAXB-bound class has a corresponding {@link JaxBeanInfo} object,
    1.62 + * which performs all the JAXB related operations on behalf of
    1.63 + * the JAXB-bound object.
    1.64 + *
    1.65 + * <p>
    1.66 + * Given a class, the corresponding {@link JaxBeanInfo} can be located
    1.67 + * via {@link JAXBContextImpl#getBeanInfo(Class,boolean)}.
    1.68 + *
    1.69 + * <p>
    1.70 + * Typically, {@link JaxBeanInfo} implementations should be generated
    1.71 + * by XJC/JXC. Those impl classes will register themselves to their
    1.72 + * master <tt>ObjectFactory</tt> class.
    1.73 + *
    1.74 + * <p>
    1.75 + * The type parameter BeanT is the Java class of the bean that this represents.
    1.76 + *
    1.77 + * @author
    1.78 + *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
    1.79 + */
    1.80 +public abstract class JaxBeanInfo<BeanT> {
    1.81 +
    1.82 +    protected boolean isNilIncluded = false;
    1.83 +
    1.84 +    /**
    1.85 +     * For {@link JaxBeanInfo} that has multiple type names.
    1.86 +     */
    1.87 +    protected JaxBeanInfo(JAXBContextImpl grammar, RuntimeTypeInfo rti, Class<BeanT> jaxbType, QName[] typeNames, boolean isElement,boolean isImmutable, boolean hasLifecycleEvents) {
    1.88 +        this(grammar,rti,jaxbType,(Object)typeNames,isElement,isImmutable,hasLifecycleEvents);
    1.89 +    }
    1.90 +
    1.91 +    /**
    1.92 +     * For {@link JaxBeanInfo} that has one type name.
    1.93 +     */
    1.94 +    protected JaxBeanInfo(JAXBContextImpl grammar, RuntimeTypeInfo rti, Class<BeanT> jaxbType, QName typeName, boolean isElement,boolean isImmutable, boolean hasLifecycleEvents) {
    1.95 +        this(grammar,rti,jaxbType,(Object)typeName,isElement,isImmutable,hasLifecycleEvents);
    1.96 +    }
    1.97 +
    1.98 +    /**
    1.99 +     * For {@link JaxBeanInfo} that has no type names.
   1.100 +     */
   1.101 +    protected JaxBeanInfo(JAXBContextImpl grammar, RuntimeTypeInfo rti, Class<BeanT> jaxbType, boolean isElement,boolean isImmutable, boolean hasLifecycleEvents) {
   1.102 +        this(grammar,rti,jaxbType,(Object)null,isElement,isImmutable,hasLifecycleEvents);
   1.103 +    }
   1.104 +
   1.105 +    private JaxBeanInfo(JAXBContextImpl grammar, RuntimeTypeInfo rti, Class<BeanT> jaxbType, Object typeName, boolean isElement,boolean isImmutable, boolean hasLifecycleEvents) {
   1.106 +        grammar.beanInfos.put(rti,this);
   1.107 +
   1.108 +        this.jaxbType = jaxbType;
   1.109 +        this.typeName = typeName;
   1.110 +        this.flag = (short)((isElement?FLAG_IS_ELEMENT:0)
   1.111 +                |(isImmutable?FLAG_IS_IMMUTABLE:0)
   1.112 +                |(hasLifecycleEvents?FLAG_HAS_LIFECYCLE_EVENTS:0));
   1.113 +    }
   1.114 +
   1.115 +    /**
   1.116 +     * Various boolean flags combined into one field to improve memory footprint.
   1.117 +     */
   1.118 +    protected short flag;
   1.119 +
   1.120 +    private static final short FLAG_IS_ELEMENT = 1;
   1.121 +    private static final short FLAG_IS_IMMUTABLE = 2;
   1.122 +    private static final short FLAG_HAS_ELEMENT_ONLY_CONTENTMODEL = 4;
   1.123 +    private static final short FLAG_HAS_BEFORE_UNMARSHAL_METHOD = 8;
   1.124 +    private static final short FLAG_HAS_AFTER_UNMARSHAL_METHOD = 16;
   1.125 +    private static final short FLAG_HAS_BEFORE_MARSHAL_METHOD = 32;
   1.126 +    private static final short FLAG_HAS_AFTER_MARSHAL_METHOD = 64;
   1.127 +    private static final short FLAG_HAS_LIFECYCLE_EVENTS = 128;
   1.128 +
   1.129 +    /** cache of lifecycle methods */
   1.130 +    private LifecycleMethods lcm = null;
   1.131 +
   1.132 +    /**
   1.133 +     * True if {@link #jaxbType} has the  lifecycle method.
   1.134 +     */
   1.135 +    public final boolean hasBeforeUnmarshalMethod() {
   1.136 +        return (flag&FLAG_HAS_BEFORE_UNMARSHAL_METHOD) != 0;
   1.137 +    }
   1.138 +
   1.139 +    /**
   1.140 +     * True if {@link #jaxbType} has the  lifecycle method.
   1.141 +     */
   1.142 +    public final boolean hasAfterUnmarshalMethod() {
   1.143 +        return (flag&FLAG_HAS_AFTER_UNMARSHAL_METHOD) != 0;
   1.144 +    }
   1.145 +
   1.146 +    /**
   1.147 +     * True if {@link #jaxbType} has the  lifecycle method.
   1.148 +     */
   1.149 +    public final boolean hasBeforeMarshalMethod() {
   1.150 +        return (flag&FLAG_HAS_BEFORE_MARSHAL_METHOD) != 0;
   1.151 +    }
   1.152 +
   1.153 +    /**
   1.154 +     * True if {@link #jaxbType} has the  lifecycle method.
   1.155 +     */
   1.156 +    public final boolean hasAfterMarshalMethod() {
   1.157 +        return (flag&FLAG_HAS_AFTER_MARSHAL_METHOD) != 0;
   1.158 +    }
   1.159 +
   1.160 +    /**
   1.161 +     * Gets the JAXB bound class type that this {@link JaxBeanInfo}
   1.162 +     * handles.
   1.163 +     *
   1.164 +     * <p>
   1.165 +     * IOW, when a bean info object is requested for T,
   1.166 +     * sometimes the bean info for one of its base classes might be
   1.167 +     * returned.
   1.168 +     */
   1.169 +    public final Class<BeanT> jaxbType;
   1.170 +
   1.171 +    /**
   1.172 +     * Returns true if the bean is mapped to/from an XML element.
   1.173 +     *
   1.174 +     * <p>
   1.175 +     * When this method returns true, {@link #getElementNamespaceURI(Object)}
   1.176 +     * and {@link #getElementLocalName(Object)} returns the element name of
   1.177 +     * the bean.
   1.178 +     */
   1.179 +    public final boolean isElement() {
   1.180 +        return (flag&FLAG_IS_ELEMENT)!=0;
   1.181 +    }
   1.182 +
   1.183 +    /**
   1.184 +     * Returns true if the bean is immutable.
   1.185 +     *
   1.186 +     * <p>
   1.187 +     * If this is true, Binder won't try to ueuse this object, and the unmarshaller
   1.188 +     * won't create a new instance of it before it starts.
   1.189 +     */
   1.190 +    public final boolean isImmutable() {
   1.191 +        return (flag&FLAG_IS_IMMUTABLE)!=0;
   1.192 +    }
   1.193 +
   1.194 +    /**
   1.195 +     * True if this bean has an element-only content model.
   1.196 +     * <p>
   1.197 +     * If this flag is true, the unmarshaller can work
   1.198 +     * faster by ignoring whitespaces more efficiently.
   1.199 +     */
   1.200 +    public final boolean hasElementOnlyContentModel() {
   1.201 +        return (flag&FLAG_HAS_ELEMENT_ONLY_CONTENTMODEL)!=0;
   1.202 +    }
   1.203 +
   1.204 +    /**
   1.205 +     * True if this bean has an element-only content model.
   1.206 +     * <p>
   1.207 +     * Should be considered immutable, though I can't mark it final
   1.208 +     * because it cannot be computed in this constructor.
   1.209 +     */
   1.210 +    protected final void hasElementOnlyContentModel(boolean value) {
   1.211 +        if(value)
   1.212 +            flag |= FLAG_HAS_ELEMENT_ONLY_CONTENTMODEL;
   1.213 +        else
   1.214 +            flag &= ~FLAG_HAS_ELEMENT_ONLY_CONTENTMODEL;
   1.215 +    }
   1.216 +
   1.217 +    public boolean isNilIncluded() {
   1.218 +        return isNilIncluded;
   1.219 +    }
   1.220 +
   1.221 +    /**
   1.222 +     * This method is used to determine which of the sub-classes should be
   1.223 +     * interrogated for the existence of lifecycle methods.
   1.224 +     *
   1.225 +     * @return true if the un|marshaller should look for lifecycle methods
   1.226 +     *         on this beanInfo, false otherwise.
   1.227 +     */
   1.228 +    public boolean lookForLifecycleMethods() {
   1.229 +        return (flag&FLAG_HAS_LIFECYCLE_EVENTS)!=0;
   1.230 +    }
   1.231 +
   1.232 +    /**
   1.233 +     * Returns the namespace URI portion of the element name,
   1.234 +     * if the bean that this class represents is mapped from/to
   1.235 +     * an XML element.
   1.236 +     *
   1.237 +     * @throws UnsupportedOperationException
   1.238 +     *      if {@link #isElement} is false.
   1.239 +     */
   1.240 +    public abstract String getElementNamespaceURI(BeanT o);
   1.241 +
   1.242 +    /**
   1.243 +     * Returns the local name portion of the element name,
   1.244 +     * if the bean that this class represents is mapped from/to
   1.245 +     * an XML element.
   1.246 +     *
   1.247 +     * @throws UnsupportedOperationException
   1.248 +     *      if {@link #isElement} is false.
   1.249 +     */
   1.250 +    public abstract String getElementLocalName(BeanT o);
   1.251 +
   1.252 +    /**
   1.253 +     * Type names associated with this {@link JaxBeanInfo}.
   1.254 +     *
   1.255 +     * @see #getTypeNames()
   1.256 +     */
   1.257 +    private final Object typeName; // either null, QName, or QName[]. save memory since most of them have just one.
   1.258 +
   1.259 +    /**
   1.260 +     * Returns XML Schema type names if the bean is mapped from
   1.261 +     * a complex/simple type of XML Schema.
   1.262 +     *
   1.263 +     * <p>
   1.264 +     * This is an ugly necessity to correctly handle
   1.265 +     * the type substitution semantics of XML Schema.
   1.266 +     *
   1.267 +     * <p>
   1.268 +     * A single Java class maybe mapped to more than one
   1.269 +     * XML types. All the types listed here are recognized
   1.270 +     * when we are unmarshalling XML.
   1.271 +     *
   1.272 +     * <p>
   1.273 +     * null if the class is not bound to a named schema type.
   1.274 +     *
   1.275 +     * <p>
   1.276 +     */
   1.277 +    public Collection<QName> getTypeNames() {
   1.278 +        if(typeName==null)  return Collections.emptyList();
   1.279 +        if(typeName instanceof QName)   return Collections.singletonList((QName)typeName);
   1.280 +        return Arrays.asList((QName[])typeName);
   1.281 +    }
   1.282 +
   1.283 +    /**
   1.284 +     * Returns the XML type name to be used to marshal the specified instance.
   1.285 +     *
   1.286 +     * <P>
   1.287 +     * Most of the times the type can be determined regardless of the actual
   1.288 +     * instance, but there's a few exceptions (most notably {@link XMLGregorianCalendar}),
   1.289 +     * so as a general rule we need an instance to determine it.
   1.290 +     */
   1.291 +    public QName getTypeName(@NotNull BeanT instance) {
   1.292 +        if(typeName==null)  return null;
   1.293 +        if(typeName instanceof QName)   return (QName)typeName;
   1.294 +        return ((QName[])typeName)[0];
   1.295 +    }
   1.296 +
   1.297 +    /**
   1.298 +     * Creates a new instance of the bean.
   1.299 +     *
   1.300 +     * <p>
   1.301 +     * This operation is only supported when {@link #isImmutable} is false.
   1.302 +     *
   1.303 +     * @param context
   1.304 +     *      Sometimes the created bean remembers the corresponding source location,
   1.305 +     */
   1.306 +    public abstract BeanT createInstance(UnmarshallingContext context) throws IllegalAccessException, InvocationTargetException, InstantiationException, SAXException;
   1.307 +
   1.308 +    /**
   1.309 +     * Resets the object to the initial state, as if the object
   1.310 +     * is created fresh.
   1.311 +     *
   1.312 +     * <p>
   1.313 +     * This is used to reuse an existing object for unmarshalling.
   1.314 +     *
   1.315 +     * @param context
   1.316 +     *      used for reporting any errors.
   1.317 +     *
   1.318 +     * @return
   1.319 +     *      true if the object was successfuly resetted.
   1.320 +     *      False if the object is not resettable, in which case the object will be
   1.321 +     *      discarded and new one will be created.
   1.322 +     *      <p>
   1.323 +     *      If the object is resettable but failed by an error, it should be reported to the context,
   1.324 +     *      then return false. If the object is not resettable to begin with, do not report an error.
   1.325 +     *
   1.326 +     * @throws SAXException
   1.327 +     *      as a result of reporting an error, the context may throw a {@link SAXException}.
   1.328 +     */
   1.329 +    public abstract boolean reset( BeanT o, UnmarshallingContext context ) throws SAXException;
   1.330 +
   1.331 +    /**
   1.332 +     * Gets the ID value of the given bean, if it has an ID value.
   1.333 +     * Otherwise return null.
   1.334 +     */
   1.335 +    public abstract String getId(BeanT o, XMLSerializer target) throws SAXException;
   1.336 +
   1.337 +    /**
   1.338 +     * Serializes child elements and texts into the specified target.
   1.339 +     */
   1.340 +    public abstract void serializeBody( BeanT o, XMLSerializer target ) throws SAXException, IOException, XMLStreamException;
   1.341 +
   1.342 +    /**
   1.343 +     * Serializes attributes into the specified target.
   1.344 +     */
   1.345 +    public abstract void serializeAttributes( BeanT o, XMLSerializer target ) throws SAXException, IOException, XMLStreamException;
   1.346 +
   1.347 +    /**
   1.348 +     * Serializes the bean as the root element.
   1.349 +     *
   1.350 +     * <p>
   1.351 +     * In the java-to-schema binding, an object might marshal in two different
   1.352 +     * ways depending on whether it is used as the root of the graph or not.
   1.353 +     * In the former case, an object could marshal as an element, whereas
   1.354 +     * in the latter case, it marshals as a type.
   1.355 +     *
   1.356 +     * <p>
   1.357 +     * This method is used to marshal the root of the object graph to allow
   1.358 +     * this semantics to be implemented.
   1.359 +     *
   1.360 +     * <p>
   1.361 +     * It is doubtful to me if it's a good idea for an object to marshal
   1.362 +     * in two ways depending on the context.
   1.363 +     *
   1.364 +     * <p>
   1.365 +     * For schema-to-java, this is equivalent to {@link #serializeBody(Object, XMLSerializer)}.
   1.366 +     */
   1.367 +    public abstract void serializeRoot( BeanT o, XMLSerializer target ) throws SAXException, IOException, XMLStreamException;
   1.368 +
   1.369 +    /**
   1.370 +     * Declares all the namespace URIs this object is using at
   1.371 +     * its top-level scope into the specified target.
   1.372 +     */
   1.373 +    public abstract void serializeURIs( BeanT o, XMLSerializer target ) throws SAXException;
   1.374 +
   1.375 +    /**
   1.376 +     * Gets the {@link Loader} that will unmarshall the given object.
   1.377 +     *
   1.378 +     * @param context
   1.379 +     *      The {@link JAXBContextImpl} object that governs this object.
   1.380 +     *      This object is taken as a parameter so that {@link JaxBeanInfo} doesn't have
   1.381 +     *      to store them on its own.
   1.382 +     *
   1.383 +     *      When this method is invoked from within the unmarshaller, tihs parameter can be
   1.384 +     *      null (because the loader is constructed already.)
   1.385 +     *
   1.386 +     * @param typeSubstitutionCapable
   1.387 +     *      If true, the returned {@link Loader} is capable of recognizing @xsi:type (if necessary)
   1.388 +     *      and unmarshals a subtype. This allowes an optimization where this bean info
   1.389 +     *      is guaranteed not to have a type substitution.
   1.390 +     *      If false, the returned {@link Loader} doesn't look for @xsi:type.
   1.391 +     * @return
   1.392 +     *      must return non-null valid object
   1.393 +     */
   1.394 +    public abstract Loader getLoader(JAXBContextImpl context, boolean typeSubstitutionCapable);
   1.395 +
   1.396 +    /**
   1.397 +     * If the bean's representation in XML is just a text,
   1.398 +     * this method return a {@link Transducer} that lets you convert
   1.399 +     * values between the text and the bean.
   1.400 +     */
   1.401 +    public abstract Transducer<BeanT> getTransducer();
   1.402 +
   1.403 +
   1.404 +    /**
   1.405 +     * Called after all the {@link JaxBeanInfo}s are created.
   1.406 +     * @param grammar
   1.407 +     */
   1.408 +    protected  void link(JAXBContextImpl grammar) {
   1.409 +    }
   1.410 +
   1.411 +    /**
   1.412 +     * Called at the end of the {@link JAXBContext} initialization phase
   1.413 +     * to clean up any unnecessary references.
   1.414 +     */
   1.415 +    public void wrapUp() {}
   1.416 +
   1.417 +
   1.418 +    private static final Class[] unmarshalEventParams = { Unmarshaller.class, Object.class };
   1.419 +    private static Class[] marshalEventParams = { Marshaller.class };
   1.420 +
   1.421 +    /**
   1.422 +     * use reflection to determine which of the 4 object lifecycle methods exist on
   1.423 +     * the JAXB bound type.
   1.424 +     */
   1.425 +    protected final void setLifecycleFlags() {
   1.426 +        try {
   1.427 +            Class<BeanT> jt = jaxbType;
   1.428 +
   1.429 +            if (lcm == null) {
   1.430 +                lcm = new LifecycleMethods();
   1.431 +            }
   1.432 +
   1.433 +            while (jt != null) {
   1.434 +                for (Method m : jt.getDeclaredMethods()) {
   1.435 +                    String name = m.getName();
   1.436 +
   1.437 +                    if (lcm.beforeUnmarshal == null) {
   1.438 +                        if (name.equals("beforeUnmarshal")) {
   1.439 +                            if (match(m, unmarshalEventParams)) {
   1.440 +                                cacheLifecycleMethod(m, FLAG_HAS_BEFORE_UNMARSHAL_METHOD);
   1.441 +                            }
   1.442 +                        }
   1.443 +                    }
   1.444 +
   1.445 +                    if (lcm.afterUnmarshal == null) {
   1.446 +                        if (name.equals("afterUnmarshal")) {
   1.447 +                            if (match(m, unmarshalEventParams)) {
   1.448 +                                cacheLifecycleMethod(m, FLAG_HAS_AFTER_UNMARSHAL_METHOD);
   1.449 +                            }
   1.450 +                        }
   1.451 +                    }
   1.452 +
   1.453 +                    if (lcm.beforeMarshal == null) {
   1.454 +                        if (name.equals("beforeMarshal")) {
   1.455 +                            if (match(m, marshalEventParams)) {
   1.456 +                                cacheLifecycleMethod(m, FLAG_HAS_BEFORE_MARSHAL_METHOD);
   1.457 +                            }
   1.458 +                        }
   1.459 +                    }
   1.460 +
   1.461 +                    if (lcm.afterMarshal == null) {
   1.462 +                        if (name.equals("afterMarshal")) {
   1.463 +                            if (match(m, marshalEventParams)) {
   1.464 +                                cacheLifecycleMethod(m, FLAG_HAS_AFTER_MARSHAL_METHOD);
   1.465 +                            }
   1.466 +                        }
   1.467 +                    }
   1.468 +                }
   1.469 +                jt = (Class<BeanT>) jt.getSuperclass();
   1.470 +            }
   1.471 +        } catch (SecurityException e) {
   1.472 +            // this happens when we don't have enough permission.
   1.473 +            logger.log(Level.WARNING, Messages.UNABLE_TO_DISCOVER_EVENTHANDLER.format(
   1.474 +                    jaxbType.getName(), e));
   1.475 +        }
   1.476 +    }
   1.477 +
   1.478 +    private boolean match(Method m, Class[] params) {
   1.479 +        return Arrays.equals(m.getParameterTypes(),params);
   1.480 +    }
   1.481 +
   1.482 +    /**
   1.483 +     * Cache a reference to the specified lifecycle method for the jaxbType
   1.484 +     * associated with this beanInfo.
   1.485 +     *
   1.486 +     * @param m Method reference
   1.487 +     * @param lifecycleFlag byte representing which of the 4 lifecycle methods
   1.488 +     *        is being cached
   1.489 +     */
   1.490 +    private void cacheLifecycleMethod(Method m, short lifecycleFlag) {
   1.491 +        //LifecycleMethods lcm = getLifecycleMethods();
   1.492 +        if(lcm==null) {
   1.493 +            lcm = new LifecycleMethods();
   1.494 +            //lcmCache.put(jaxbType, lcm);
   1.495 +        }
   1.496 +
   1.497 +        m.setAccessible(true);
   1.498 +
   1.499 +        flag |= lifecycleFlag;
   1.500 +
   1.501 +        switch (lifecycleFlag) {
   1.502 +        case FLAG_HAS_BEFORE_UNMARSHAL_METHOD:
   1.503 +            lcm.beforeUnmarshal = m;
   1.504 +            break;
   1.505 +        case FLAG_HAS_AFTER_UNMARSHAL_METHOD:
   1.506 +            lcm.afterUnmarshal = m;
   1.507 +            break;
   1.508 +        case FLAG_HAS_BEFORE_MARSHAL_METHOD:
   1.509 +            lcm.beforeMarshal = m;
   1.510 +            break;
   1.511 +        case FLAG_HAS_AFTER_MARSHAL_METHOD:
   1.512 +            lcm.afterMarshal = m;
   1.513 +            break;
   1.514 +        }
   1.515 +    }
   1.516 +
   1.517 +    /**
   1.518 +     * Return the LifecycleMethods cache for this ClassBeanInfo's corresponding
   1.519 +     * jaxbType if it exists, else return null.
   1.520 +     *
   1.521 +     */
   1.522 +    public final LifecycleMethods getLifecycleMethods() {
   1.523 +        return lcm;
   1.524 +    }
   1.525 +
   1.526 +    /**
   1.527 +     * Invokes the beforeUnmarshal method if applicable.
   1.528 +     */
   1.529 +    public final void invokeBeforeUnmarshalMethod(UnmarshallerImpl unm, Object child, Object parent) throws SAXException {
   1.530 +        Method m = getLifecycleMethods().beforeUnmarshal;
   1.531 +        invokeUnmarshallCallback(m, child, unm, parent);
   1.532 +    }
   1.533 +
   1.534 +    /**
   1.535 +     * Invokes the afterUnmarshal method if applicable.
   1.536 +     */
   1.537 +    public final void invokeAfterUnmarshalMethod(UnmarshallerImpl unm, Object child, Object parent) throws SAXException {
   1.538 +        Method m = getLifecycleMethods().afterUnmarshal;
   1.539 +        invokeUnmarshallCallback(m, child, unm, parent);
   1.540 +    }
   1.541 +
   1.542 +    private void invokeUnmarshallCallback(Method m, Object child, UnmarshallerImpl unm, Object parent) throws SAXException {
   1.543 +        try {
   1.544 +            m.invoke(child,unm,parent);
   1.545 +        } catch (IllegalAccessException e) {
   1.546 +            UnmarshallingContext.getInstance().handleError(e, false);
   1.547 +        } catch (InvocationTargetException e) {
   1.548 +            UnmarshallingContext.getInstance().handleError(e, false);
   1.549 +        }
   1.550 +    }
   1.551 +
   1.552 +    private static final Logger logger = Util.getClassLogger();
   1.553 +}

mercurial