|
Java example source code file (RuntimeClassInfoImpl.java)
The RuntimeClassInfoImpl.java Java example source code/* * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.xml.internal.bind.v2.model.impl; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.util.List; import java.util.Map; import javax.xml.bind.JAXBException; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import com.sun.istack.internal.NotNull; import com.sun.xml.internal.bind.AccessorFactory; import com.sun.xml.internal.bind.AccessorFactoryImpl; import com.sun.xml.internal.bind.InternalAccessorFactory; import com.sun.xml.internal.bind.XmlAccessorFactory; import com.sun.xml.internal.bind.annotation.XmlLocation; import com.sun.xml.internal.bind.api.AccessorException; import com.sun.xml.internal.bind.v2.ClassFactory; import com.sun.xml.internal.bind.v2.model.annotation.Locatable; import com.sun.xml.internal.bind.v2.model.core.PropertyKind; import com.sun.xml.internal.bind.v2.model.runtime.RuntimeClassInfo; import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElement; import com.sun.xml.internal.bind.v2.model.runtime.RuntimePropertyInfo; import com.sun.xml.internal.bind.v2.model.runtime.RuntimeValuePropertyInfo; import com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException; import com.sun.xml.internal.bind.v2.runtime.Location; import com.sun.xml.internal.bind.v2.runtime.Name; import com.sun.xml.internal.bind.v2.runtime.Transducer; import com.sun.xml.internal.bind.v2.runtime.XMLSerializer; import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor; import com.sun.xml.internal.bind.v2.runtime.reflect.TransducedAccessor; import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext; import org.xml.sax.Locator; import org.xml.sax.SAXException; /** * @author Kohsuke Kawaguchi (kk@kohsuke.org) */ class RuntimeClassInfoImpl extends ClassInfoImpl<Type,Class,Field,Method> implements RuntimeClassInfo, RuntimeElement { /** * If this class has a property annotated with {@link XmlLocation}, * this field will get the accessor for it. * * TODO: support method based XmlLocation */ private Accessor<?,Locator> xmlLocationAccessor; private AccessorFactory accessorFactory; private boolean supressAccessorWarnings = false; public RuntimeClassInfoImpl(RuntimeModelBuilder modelBuilder, Locatable upstream, Class clazz) { super(modelBuilder, upstream, clazz); accessorFactory = createAccessorFactory(clazz); } protected AccessorFactory createAccessorFactory(Class clazz) { XmlAccessorFactory factoryAnn; AccessorFactory accFactory = null; // user providing class to be used. JAXBContextImpl context = ((RuntimeModelBuilder) builder).context; if (context!=null) { this.supressAccessorWarnings = context.supressAccessorWarnings; if (context.xmlAccessorFactorySupport) { factoryAnn = findXmlAccessorFactoryAnnotation(clazz); if (factoryAnn != null) { try { accFactory = factoryAnn.value().newInstance(); } catch (InstantiationException e) { builder.reportError(new IllegalAnnotationException( Messages.ACCESSORFACTORY_INSTANTIATION_EXCEPTION.format( factoryAnn.getClass().getName(), nav().getClassName(clazz)), this)); } catch (IllegalAccessException e) { builder.reportError(new IllegalAnnotationException( Messages.ACCESSORFACTORY_ACCESS_EXCEPTION.format( factoryAnn.getClass().getName(), nav().getClassName(clazz)),this)); } } } } // Fall back to local AccessorFactory when no // user not providing one or as error recovery. if (accFactory == null){ accFactory = AccessorFactoryImpl.getInstance(); } return accFactory; } protected XmlAccessorFactory findXmlAccessorFactoryAnnotation(Class clazz) { XmlAccessorFactory factoryAnn = reader().getClassAnnotation(XmlAccessorFactory.class,clazz,this); if (factoryAnn == null) { factoryAnn = reader().getPackageAnnotation(XmlAccessorFactory.class,clazz,this); } return factoryAnn; } public Method getFactoryMethod(){ return super.getFactoryMethod(); } public final RuntimeClassInfoImpl getBaseClass() { return (RuntimeClassInfoImpl)super.getBaseClass(); } @Override protected ReferencePropertyInfoImpl createReferenceProperty(PropertySeed<Type,Class,Field,Method> seed) { return new RuntimeReferencePropertyInfoImpl(this,seed); } @Override protected AttributePropertyInfoImpl createAttributeProperty(PropertySeed<Type,Class,Field,Method> seed) { return new RuntimeAttributePropertyInfoImpl(this,seed); } @Override protected ValuePropertyInfoImpl createValueProperty(PropertySeed<Type,Class,Field,Method> seed) { return new RuntimeValuePropertyInfoImpl(this,seed); } @Override protected ElementPropertyInfoImpl createElementProperty(PropertySeed<Type,Class,Field,Method> seed) { return new RuntimeElementPropertyInfoImpl(this,seed); } @Override protected MapPropertyInfoImpl createMapProperty(PropertySeed<Type,Class,Field,Method> seed) { return new RuntimeMapPropertyInfoImpl(this,seed); } @Override public List<? extends RuntimePropertyInfo> getProperties() { return (List<? extends RuntimePropertyInfo>)super.getProperties(); } @Override public RuntimePropertyInfo getProperty(String name) { return (RuntimePropertyInfo)super.getProperty(name); } public void link() { getTransducer(); // populate the transducer super.link(); } private Accessor<?,Map |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.