|
Java example source code file (ContextFactory.java)
The ContextFactory.java Java example source code/* * Copyright (c) 1997, 2012, 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; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.logging.Level; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import com.sun.istack.internal.FinalArrayList; import com.sun.xml.internal.bind.Util; import com.sun.xml.internal.bind.api.JAXBRIContext; import com.sun.xml.internal.bind.api.TypeReference; import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader; import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; import com.sun.xml.internal.bind.v2.util.TypeCast; /** * This class is responsible for producing RI JAXBContext objects. In * the RI, this is the class that the javax.xml.bind.context.factory * property will point to. * * <p> * Used to create JAXBContext objects for v1.0.1 and forward * * @since 2.0 * @author Kohsuke Kawaguchi */ public class ContextFactory { /** * The API will invoke this method via reflection */ public static JAXBContext createContext(Class[] classes, Map<String,Object> properties ) throws JAXBException { // fool-proof check, and copy the map to make it easier to find unrecognized properties. if(properties==null) properties = Collections.emptyMap(); else properties = new HashMap<String,Object>(properties); String defaultNsUri = getPropertyValue(properties,JAXBRIContext.DEFAULT_NAMESPACE_REMAP,String.class); Boolean c14nSupport = getPropertyValue(properties,JAXBRIContext.CANONICALIZATION_SUPPORT,Boolean.class); if(c14nSupport==null) c14nSupport = false; Boolean disablesecurityProcessing = getPropertyValue(properties, JAXBRIContext.DISABLE_XML_SECURITY, Boolean.class); if (disablesecurityProcessing==null) disablesecurityProcessing = false; Boolean allNillable = getPropertyValue(properties,JAXBRIContext.TREAT_EVERYTHING_NILLABLE,Boolean.class); if(allNillable==null) allNillable = false; Boolean retainPropertyInfo = getPropertyValue(properties, JAXBRIContext.RETAIN_REFERENCE_TO_INFO, Boolean.class); if(retainPropertyInfo==null) retainPropertyInfo = false; Boolean supressAccessorWarnings = getPropertyValue(properties, JAXBRIContext.SUPRESS_ACCESSOR_WARNINGS, Boolean.class); if(supressAccessorWarnings==null) supressAccessorWarnings = false; Boolean improvedXsiTypeHandling = getPropertyValue(properties, JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING, Boolean.class); if (improvedXsiTypeHandling == null) { String improvedXsiSystemProperty = Util.getSystemProperty(JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING); if (improvedXsiSystemProperty == null) { improvedXsiTypeHandling = true; } else { improvedXsiTypeHandling = Boolean.valueOf(improvedXsiSystemProperty); } } Boolean xmlAccessorFactorySupport = getPropertyValue(properties, JAXBRIContext.XMLACCESSORFACTORY_SUPPORT,Boolean.class); if(xmlAccessorFactorySupport==null){ xmlAccessorFactorySupport = false; Util.getClassLogger().log(Level.FINE, "Property " + JAXBRIContext.XMLACCESSORFACTORY_SUPPORT + "is not active. Using JAXB's implementation"); } RuntimeAnnotationReader ar = getPropertyValue(properties,JAXBRIContext.ANNOTATION_READER,RuntimeAnnotationReader.class); Collection<TypeReference> tr = getPropertyValue(properties, JAXBRIContext.TYPE_REFERENCES, Collection.class); if (tr == null) { tr = Collections.<TypeReference>emptyList(); } Map<Class,Class> subclassReplacements; try { subclassReplacements = TypeCast.checkedCast( getPropertyValue(properties, JAXBRIContext.SUBCLASS_REPLACEMENTS, Map.class), Class.class, Class.class); } catch (ClassCastException e) { throw new JAXBException(Messages.INVALID_TYPE_IN_MAP.format(),e); } if(!properties.isEmpty()) { throw new JAXBException(Messages.UNSUPPORTED_PROPERTY.format(properties.keySet().iterator().next())); } JAXBContextImpl.JAXBContextBuilder builder = new JAXBContextImpl.JAXBContextBuilder(); builder.setClasses(classes); builder.setTypeRefs(tr); builder.setSubclassReplacements(subclassReplacements); builder.setDefaultNsUri(defaultNsUri); builder.setC14NSupport(c14nSupport); builder.setAnnotationReader(ar); builder.setXmlAccessorFactorySupport(xmlAccessorFactorySupport); builder.setAllNillable(allNillable); builder.setRetainPropertyInfo(retainPropertyInfo); builder.setSupressAccessorWarnings(supressAccessorWarnings); builder.setImprovedXsiTypeHandling(improvedXsiTypeHandling); builder.setDisableSecurityProcessing(disablesecurityProcessing); return builder.build(); } /** * If a key is present in the map, remove the value and return it. */ private static <T> T getPropertyValue(Map Other Java examples (source code examples)Here is a short list of links related to this Java ContextFactory.java source code file: |
... 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.