1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/db/glassfish/JAXBRIContextFactory.java Thu Apr 04 19:05:24 2013 -0700 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/db/glassfish/JAXBRIContextFactory.java Tue Apr 09 14:51:13 2013 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -31,11 +31,8 @@ 1.11 import java.util.Map; 1.12 import java.lang.reflect.Type; 1.13 import javax.xml.bind.JAXBContext; 1.14 -import javax.xml.bind.JAXBException; 1.15 import javax.xml.bind.Marshaller; 1.16 1.17 -import com.sun.istack.internal.NotNull; 1.18 -import com.sun.istack.internal.Nullable; 1.19 import com.sun.xml.internal.bind.api.TypeReference; 1.20 import com.sun.xml.internal.bind.api.JAXBRIContext; 1.21 import com.sun.xml.internal.bind.api.CompositeStructure; 1.22 @@ -49,6 +46,7 @@ 1.23 import com.sun.xml.internal.ws.spi.db.DatabindingException; 1.24 import com.sun.xml.internal.ws.spi.db.TypeInfo; 1.25 import com.sun.xml.internal.ws.spi.db.WrapperComposite; 1.26 +import java.util.Arrays; 1.27 1.28 /** 1.29 * JAXBRIContextFactory 1.30 @@ -57,68 +55,76 @@ 1.31 */ 1.32 public class JAXBRIContextFactory extends BindingContextFactory { 1.33 1.34 - public BindingContext newContext(JAXBContext context) { 1.35 - return new JAXBRIContextWrapper((JAXBRIContext)context, null); 1.36 + @Override 1.37 + public BindingContext newContext(JAXBContext context) { 1.38 + return new JAXBRIContextWrapper((JAXBRIContext) context, null); 1.39 + } 1.40 + 1.41 + @Override 1.42 + public BindingContext newContext(BindingInfo bi) { 1.43 + Class[] classes = bi.contentClasses().toArray(new Class[bi.contentClasses().size()]); 1.44 + for (int i = 0; i < classes.length; i++) { 1.45 + if (WrapperComposite.class.equals(classes[i])) { 1.46 + classes[i] = CompositeStructure.class; 1.47 + } 1.48 } 1.49 + Map<TypeInfo, TypeReference> typeInfoMappings = typeInfoMappings(bi.typeInfos()); 1.50 + Map<Class, Class> subclassReplacements = bi.subclassReplacements(); 1.51 + String defaultNamespaceRemap = bi.getDefaultNamespace(); 1.52 + Boolean c14nSupport = (Boolean) bi.properties().get("c14nSupport"); 1.53 + RuntimeAnnotationReader ar = (RuntimeAnnotationReader) bi.properties().get("com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader"); 1.54 + JAXBContextFactory jaxbContextFactory = (JAXBContextFactory) bi.properties().get(JAXBContextFactory.class.getName()); 1.55 + try { 1.56 + JAXBRIContext context = (jaxbContextFactory != null) 1.57 + ? jaxbContextFactory.createJAXBContext( 1.58 + bi.getSEIModel(), 1.59 + toList(classes), 1.60 + toList(typeInfoMappings.values())) 1.61 + : ContextFactory.createContext( 1.62 + classes, typeInfoMappings.values(), 1.63 + subclassReplacements, defaultNamespaceRemap, 1.64 + (c14nSupport != null) ? c14nSupport : false, 1.65 + ar, false, false, false); 1.66 + return new JAXBRIContextWrapper(context, typeInfoMappings); 1.67 + } catch (Exception e) { 1.68 + throw new DatabindingException(e); 1.69 + } 1.70 + } 1.71 1.72 - public BindingContext newContext(BindingInfo bi) { 1.73 - Class[] classes = bi.contentClasses().toArray(new Class[bi.contentClasses().size()]); 1.74 - for (int i = 0; i < classes.length; i++) if (WrapperComposite.class.equals(classes[i])) 1.75 - classes[i] = CompositeStructure.class; 1.76 - Map<TypeInfo, TypeReference> typeInfoMappings = typeInfoMappings(bi.typeInfos()); 1.77 - Map<Class,Class> subclassReplacements = bi.subclassReplacements(); 1.78 - String defaultNamespaceRemap = bi.getDefaultNamespace(); 1.79 - Boolean c14nSupport = (Boolean)bi.properties().get("c14nSupport"); 1.80 - RuntimeAnnotationReader ar = (RuntimeAnnotationReader)bi.properties().get("com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader"); 1.81 - JAXBContextFactory jaxbContextFactory = (JAXBContextFactory)bi.properties().get(JAXBContextFactory.class.getName()); 1.82 - try { 1.83 - JAXBRIContext context = (jaxbContextFactory != null)? 1.84 - jaxbContextFactory.createJAXBContext( 1.85 - bi.getSEIModel(), 1.86 - toList(classes), 1.87 - toList(typeInfoMappings.values())) : 1.88 - ContextFactory.createContext( 1.89 - classes, typeInfoMappings.values(), 1.90 - subclassReplacements, defaultNamespaceRemap, 1.91 - (c14nSupport != null)? c14nSupport : false, 1.92 - ar, false, false, false); 1.93 - return new JAXBRIContextWrapper(context, typeInfoMappings); 1.94 - } catch (Exception e) { 1.95 - throw new DatabindingException(e); 1.96 - } 1.97 + private <T> List<T> toList(T[] a) { 1.98 + List<T> l = new ArrayList<T>(); 1.99 + l.addAll(Arrays.asList(a)); 1.100 + return l; 1.101 + } 1.102 + 1.103 + private <T> List<T> toList(Collection<T> col) { 1.104 + if (col instanceof List) { 1.105 + return (List<T>) col; 1.106 } 1.107 + List<T> l = new ArrayList<T>(); 1.108 + l.addAll(col); 1.109 + return l; 1.110 + } 1.111 1.112 + private Map<TypeInfo, TypeReference> typeInfoMappings(Collection<TypeInfo> typeInfos) { 1.113 + Map<TypeInfo, TypeReference> map = new java.util.HashMap<TypeInfo, TypeReference>(); 1.114 + for (TypeInfo ti : typeInfos) { 1.115 + Type type = WrapperComposite.class.equals(ti.type) ? CompositeStructure.class : ti.type; 1.116 + TypeReference tr = new TypeReference(ti.tagName, type, ti.annotations); 1.117 + map.put(ti, tr); 1.118 + } 1.119 + return map; 1.120 + } 1.121 1.122 - private <T> List<T> toList(T[] a) { 1.123 - List<T> l = new ArrayList<T>(); 1.124 - for(T t : a) l.add(t); 1.125 - return l; 1.126 - } 1.127 + @Override 1.128 + protected BindingContext getContext(Marshaller m) { 1.129 + return newContext(((MarshallerImpl) m).getContext()); 1.130 + } 1.131 1.132 - private <T> List<T> toList(Collection<T> col) { 1.133 - if (col instanceof List) return (List<T>) col; 1.134 - List<T> l = new ArrayList<T>(); 1.135 - l.addAll(col); 1.136 - return l; 1.137 - } 1.138 - 1.139 - private Map<TypeInfo, TypeReference> typeInfoMappings(Collection<TypeInfo> typeInfos) { 1.140 - Map<TypeInfo, TypeReference> map = new java.util.HashMap<TypeInfo, TypeReference>(); 1.141 - for (TypeInfo ti : typeInfos) { 1.142 - Type type = WrapperComposite.class.equals(ti.type)? CompositeStructure.class : ti.type; 1.143 - TypeReference tr = new TypeReference(ti.tagName, type, ti.annotations); 1.144 - map.put(ti, tr); 1.145 - } 1.146 - return map; 1.147 - } 1.148 - 1.149 - protected BindingContext getContext(Marshaller m) { 1.150 - return newContext(((MarshallerImpl)m).getContext()); 1.151 - } 1.152 - 1.153 - protected boolean isFor(String str) { 1.154 - return (str.equals("glassfish.jaxb") || 1.155 - str.equals(this.getClass().getName())|| 1.156 - str.equals("com.sun.xml.internal.bind.v2.runtime")); 1.157 - } 1.158 + @Override 1.159 + protected boolean isFor(String str) { 1.160 + return (str.equals("glassfish.jaxb") 1.161 + || str.equals(this.getClass().getName()) 1.162 + || str.equals("com.sun.xml.internal.bind.v2.runtime")); 1.163 + } 1.164 }