aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.ws.db.glassfish; aoqi@0: aoqi@0: import java.io.IOException; aoqi@0: import java.util.List; aoqi@0: import java.util.Map; aoqi@0: aoqi@0: import javax.xml.bind.JAXBContext; aoqi@0: import javax.xml.bind.JAXBException; aoqi@0: import javax.xml.bind.Marshaller; aoqi@0: import javax.xml.bind.SchemaOutputResolver; aoqi@0: import javax.xml.bind.Unmarshaller; aoqi@0: import javax.xml.namespace.QName; aoqi@0: import com.sun.xml.internal.bind.api.JAXBRIContext; aoqi@0: import com.sun.xml.internal.bind.api.TypeReference; aoqi@0: import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet; aoqi@0: import com.sun.xml.internal.ws.spi.db.BindingContext; aoqi@0: import com.sun.xml.internal.ws.spi.db.XMLBridge; aoqi@0: import com.sun.xml.internal.ws.spi.db.TypeInfo; aoqi@0: import com.sun.xml.internal.ws.spi.db.WrapperComposite; aoqi@0: aoqi@0: class JAXBRIContextWrapper implements BindingContext { aoqi@0: aoqi@0: private Map typeRefs; aoqi@0: private Map typeInfos; aoqi@0: private JAXBRIContext context; aoqi@0: aoqi@0: JAXBRIContextWrapper(JAXBRIContext cxt, Map refs) { aoqi@0: context = cxt; aoqi@0: typeRefs = refs; aoqi@0: if (refs != null) { aoqi@0: typeInfos = new java.util.HashMap(); aoqi@0: for (TypeInfo ti : refs.keySet()) { aoqi@0: typeInfos.put(typeRefs.get(ti), ti); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: TypeReference typeReference(TypeInfo ti) { aoqi@0: return (typeRefs != null) ? typeRefs.get(ti) : null; aoqi@0: } aoqi@0: aoqi@0: TypeInfo typeInfo(TypeReference tr) { aoqi@0: return (typeInfos != null) ? typeInfos.get(tr) : null; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public Marshaller createMarshaller() throws JAXBException { aoqi@0: return context.createMarshaller(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public Unmarshaller createUnmarshaller() throws JAXBException { aoqi@0: return context.createUnmarshaller(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public void generateSchema(SchemaOutputResolver outputResolver) aoqi@0: throws IOException { aoqi@0: context.generateSchema(outputResolver); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String getBuildId() { aoqi@0: return context.getBuildId(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public QName getElementName(Class o) throws JAXBException { aoqi@0: return context.getElementName(o); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public QName getElementName(Object o) throws JAXBException { aoqi@0: return context.getElementName(o); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public com.sun.xml.internal.ws.spi.db.PropertyAccessor getElementPropertyAccessor( aoqi@0: Class wrapperBean, String nsUri, String localName) aoqi@0: throws JAXBException { aoqi@0: return new RawAccessorWrapper(context.getElementPropertyAccessor(wrapperBean, nsUri, localName)); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public List getKnownNamespaceURIs() { aoqi@0: return context.getKnownNamespaceURIs(); aoqi@0: } aoqi@0: aoqi@0: public RuntimeTypeInfoSet getRuntimeTypeInfoSet() { aoqi@0: return context.getRuntimeTypeInfoSet(); aoqi@0: } aoqi@0: aoqi@0: public QName getTypeName(com.sun.xml.internal.bind.api.TypeReference tr) { aoqi@0: return context.getTypeName(tr); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public int hashCode() { aoqi@0: return context.hashCode(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public boolean equals(Object obj) { aoqi@0: if (obj == null) { aoqi@0: return false; aoqi@0: } aoqi@0: if (getClass() != obj.getClass()) { aoqi@0: return false; aoqi@0: } aoqi@0: final JAXBRIContextWrapper other = (JAXBRIContextWrapper) obj; aoqi@0: if (this.context != other.context && (this.context == null || !this.context.equals(other.context))) { aoqi@0: return false; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public boolean hasSwaRef() { aoqi@0: return context.hasSwaRef(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public String toString() { aoqi@0: return JAXBRIContextWrapper.class.getName() + " : " + context.toString(); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public XMLBridge createBridge(TypeInfo ti) { aoqi@0: TypeReference tr = typeRefs.get(ti); aoqi@0: com.sun.xml.internal.bind.api.Bridge b = context.createBridge(tr); aoqi@0: return WrapperComposite.class.equals(ti.type) aoqi@0: ? new WrapperBridge(this, b) aoqi@0: : new BridgeWrapper(this, b); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public JAXBContext getJAXBContext() { aoqi@0: return context; aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public QName getTypeName(TypeInfo ti) { aoqi@0: TypeReference tr = typeRefs.get(ti); aoqi@0: return context.getTypeName(tr); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public XMLBridge createFragmentBridge() { aoqi@0: return new MarshallerBridge((com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl) context); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public Object newWrapperInstace(Class wrapperType) aoqi@0: throws InstantiationException, IllegalAccessException { aoqi@0: return wrapperType.newInstance(); aoqi@0: } aoqi@0: }