< prev index next >

src/java.xml.bind/share/classes/com/sun/xml/internal/bind/v2/runtime/RuntimeUtil.java

Print this page


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


  36  */
  37 public class RuntimeUtil {
  38     /**
  39      * XmlAdapter for printing arbitrary object by using {@link Object#toString()}.
  40      */
  41     public static final class ToStringAdapter extends XmlAdapter<String,Object> {
  42         public Object unmarshal(String s) {
  43             throw new UnsupportedOperationException();
  44         }
  45 
  46         public String marshal(Object o) {
  47             if(o==null)     return null;
  48             return o.toString();
  49         }
  50     }
  51 
  52     /**
  53      * Map from {@link Class} objects representing primitive types
  54      * to {@link Class} objects representing their boxed types.
  55      * <p>
  56      * e.g., int -> Integer.
  57      */
  58     public static final Map<Class,Class> boxToPrimitive;
  59 
  60     /**
  61      * Reverse map of {@link #boxToPrimitive}.
  62      */
  63     public static final Map<Class,Class> primitiveToBox;
  64 
  65     static {
  66         Map<Class,Class> b = new HashMap<Class,Class>();
  67         b.put(Byte.TYPE,Byte.class);
  68         b.put(Short.TYPE,Short.class);
  69         b.put(Integer.TYPE,Integer.class);
  70         b.put(Long.TYPE,Long.class);
  71         b.put(Character.TYPE,Character.class);
  72         b.put(Boolean.TYPE,Boolean.class);
  73         b.put(Float.TYPE,Float.class);
  74         b.put(Double.TYPE,Double.class);
  75         b.put(Void.TYPE,Void.class);
  76 


   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


  36  */
  37 public class RuntimeUtil {
  38     /**
  39      * XmlAdapter for printing arbitrary object by using {@link Object#toString()}.
  40      */
  41     public static final class ToStringAdapter extends XmlAdapter<String,Object> {
  42         public Object unmarshal(String s) {
  43             throw new UnsupportedOperationException();
  44         }
  45 
  46         public String marshal(Object o) {
  47             if(o==null)     return null;
  48             return o.toString();
  49         }
  50     }
  51 
  52     /**
  53      * Map from {@link Class} objects representing primitive types
  54      * to {@link Class} objects representing their boxed types.
  55      * <p>
  56      * e.g., {@code int -> Integer}.
  57      */
  58     public static final Map<Class,Class> boxToPrimitive;
  59 
  60     /**
  61      * Reverse map of {@link #boxToPrimitive}.
  62      */
  63     public static final Map<Class,Class> primitiveToBox;
  64 
  65     static {
  66         Map<Class,Class> b = new HashMap<Class,Class>();
  67         b.put(Byte.TYPE,Byte.class);
  68         b.put(Short.TYPE,Short.class);
  69         b.put(Integer.TYPE,Integer.class);
  70         b.put(Long.TYPE,Long.class);
  71         b.put(Character.TYPE,Character.class);
  72         b.put(Boolean.TYPE,Boolean.class);
  73         b.put(Float.TYPE,Float.class);
  74         b.put(Double.TYPE,Double.class);
  75         b.put(Void.TYPE,Void.class);
  76 


< prev index next >