< prev index next >

jaxws/src/java.xml.bind/share/classes/com/sun/xml/internal/bind/v2/ContextFactory.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2015, 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


  95 
  96         Boolean improvedXsiTypeHandling = getPropertyValue(properties, JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING, Boolean.class);
  97         if (improvedXsiTypeHandling == null) {
  98             String improvedXsiSystemProperty = Util.getSystemProperty(JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING);
  99             if (improvedXsiSystemProperty == null) {
 100                 improvedXsiTypeHandling = true;
 101             } else {
 102                 improvedXsiTypeHandling = Boolean.valueOf(improvedXsiSystemProperty);
 103             }
 104         }
 105 
 106         Boolean xmlAccessorFactorySupport = getPropertyValue(properties,
 107            JAXBRIContext.XMLACCESSORFACTORY_SUPPORT,Boolean.class);
 108         if(xmlAccessorFactorySupport==null){
 109             xmlAccessorFactorySupport = false;
 110             Util.getClassLogger().log(Level.FINE, "Property " +
 111                 JAXBRIContext.XMLACCESSORFACTORY_SUPPORT +
 112                 "is not active.  Using JAXB's implementation");
 113         }
 114 


 115         RuntimeAnnotationReader ar = getPropertyValue(properties,JAXBRIContext.ANNOTATION_READER,RuntimeAnnotationReader.class);
 116 
 117         Collection<TypeReference> tr = getPropertyValue(properties, JAXBRIContext.TYPE_REFERENCES, Collection.class);
 118         if (tr == null) {
 119             tr = Collections.<TypeReference>emptyList();
 120         }
 121 
 122         Map<Class,Class> subclassReplacements;
 123         try {
 124             subclassReplacements = TypeCast.checkedCast(
 125                 getPropertyValue(properties, JAXBRIContext.SUBCLASS_REPLACEMENTS, Map.class), Class.class, Class.class);
 126         } catch (ClassCastException e) {
 127             throw new JAXBException(Messages.INVALID_TYPE_IN_MAP.format(),e);
 128         }
 129 
 130         if(!properties.isEmpty()) {
 131             throw new JAXBException(Messages.UNSUPPORTED_PROPERTY.format(properties.keySet().iterator().next()));
 132         }
 133 
 134         JAXBContextImpl.JAXBContextBuilder builder = new JAXBContextImpl.JAXBContextBuilder();
 135         builder.setClasses(classes);
 136         builder.setTypeRefs(tr);
 137         builder.setSubclassReplacements(subclassReplacements);
 138         builder.setDefaultNsUri(defaultNsUri);
 139         builder.setC14NSupport(c14nSupport);
 140         builder.setAnnotationReader(ar);
 141         builder.setXmlAccessorFactorySupport(xmlAccessorFactorySupport);
 142         builder.setAllNillable(allNillable);
 143         builder.setRetainPropertyInfo(retainPropertyInfo);
 144         builder.setSupressAccessorWarnings(supressAccessorWarnings);
 145         builder.setImprovedXsiTypeHandling(improvedXsiTypeHandling);
 146         builder.setDisableSecurityProcessing(disablesecurityProcessing);

 147         return builder.build();
 148     }
 149 
 150     /**
 151      * If a key is present in the map, remove the value and return it.
 152      */
 153     private static <T> T getPropertyValue(Map<String, Object> properties, String keyName, Class<T> type ) throws JAXBException {
 154         Object o = properties.get(keyName);
 155         if(o==null)     return null;
 156 
 157         properties.remove(keyName);
 158         if(!type.isInstance(o))
 159             throw new JAXBException(Messages.INVALID_PROPERTY_VALUE.format(keyName,o));
 160         else
 161             return type.cast(o);
 162     }
 163 
 164     /**
 165      *
 166      * @param classes


   1 /*
   2  * Copyright (c) 1997, 2017, 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


  95 
  96         Boolean improvedXsiTypeHandling = getPropertyValue(properties, JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING, Boolean.class);
  97         if (improvedXsiTypeHandling == null) {
  98             String improvedXsiSystemProperty = Util.getSystemProperty(JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING);
  99             if (improvedXsiSystemProperty == null) {
 100                 improvedXsiTypeHandling = true;
 101             } else {
 102                 improvedXsiTypeHandling = Boolean.valueOf(improvedXsiSystemProperty);
 103             }
 104         }
 105 
 106         Boolean xmlAccessorFactorySupport = getPropertyValue(properties,
 107            JAXBRIContext.XMLACCESSORFACTORY_SUPPORT,Boolean.class);
 108         if(xmlAccessorFactorySupport==null){
 109             xmlAccessorFactorySupport = false;
 110             Util.getClassLogger().log(Level.FINE, "Property " +
 111                 JAXBRIContext.XMLACCESSORFACTORY_SUPPORT +
 112                 "is not active.  Using JAXB's implementation");
 113         }
 114 
 115         Boolean backupWithParentNamespace = getPropertyValue(properties, JAXBRIContext.BACKUP_WITH_PARENT_NAMESPACE, Boolean.class);
 116 
 117         RuntimeAnnotationReader ar = getPropertyValue(properties,JAXBRIContext.ANNOTATION_READER,RuntimeAnnotationReader.class);
 118 
 119         Collection<TypeReference> tr = getPropertyValue(properties, JAXBRIContext.TYPE_REFERENCES, Collection.class);
 120         if (tr == null) {
 121             tr = Collections.<TypeReference>emptyList();
 122         }
 123 
 124         Map<Class,Class> subclassReplacements;
 125         try {
 126             subclassReplacements = TypeCast.checkedCast(
 127                 getPropertyValue(properties, JAXBRIContext.SUBCLASS_REPLACEMENTS, Map.class), Class.class, Class.class);
 128         } catch (ClassCastException e) {
 129             throw new JAXBException(Messages.INVALID_TYPE_IN_MAP.format(),e);
 130         }
 131 
 132         if(!properties.isEmpty()) {
 133             throw new JAXBException(Messages.UNSUPPORTED_PROPERTY.format(properties.keySet().iterator().next()));
 134         }
 135 
 136         JAXBContextImpl.JAXBContextBuilder builder = new JAXBContextImpl.JAXBContextBuilder();
 137         builder.setClasses(classes);
 138         builder.setTypeRefs(tr);
 139         builder.setSubclassReplacements(subclassReplacements);
 140         builder.setDefaultNsUri(defaultNsUri);
 141         builder.setC14NSupport(c14nSupport);
 142         builder.setAnnotationReader(ar);
 143         builder.setXmlAccessorFactorySupport(xmlAccessorFactorySupport);
 144         builder.setAllNillable(allNillable);
 145         builder.setRetainPropertyInfo(retainPropertyInfo);
 146         builder.setSupressAccessorWarnings(supressAccessorWarnings);
 147         builder.setImprovedXsiTypeHandling(improvedXsiTypeHandling);
 148         builder.setDisableSecurityProcessing(disablesecurityProcessing);
 149         builder.setBackupWithParentNamespace(backupWithParentNamespace);
 150         return builder.build();
 151     }
 152 
 153     /**
 154      * If a key is present in the map, remove the value and return it.
 155      */
 156     private static <T> T getPropertyValue(Map<String, Object> properties, String keyName, Class<T> type ) throws JAXBException {
 157         Object o = properties.get(keyName);
 158         if(o==null)     return null;
 159 
 160         properties.remove(keyName);
 161         if(!type.isInstance(o))
 162             throw new JAXBException(Messages.INVALID_PROPERTY_VALUE.format(keyName,o));
 163         else
 164             return type.cast(o);
 165     }
 166 
 167     /**
 168      *
 169      * @param classes


< prev index next >