001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.message.databinding;
020:
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023:
024: import javax.xml.bind.JAXBContext;
025: import javax.xml.bind.JAXBException;
026: import javax.xml.ws.Holder;
027: import java.util.TreeSet;
028:
029: /*
030: * A JAXBBlockContext controls access to the JAXB Context
031: * In addition the JAXBBlockContext contains additional contextural information needed
032: * by the JAX-WS component
033: *
034: * This class is immutable after construction.
035: */
036:
037: public class JAXBBlockContext {
038:
039: private static final Log log = LogFactory
040: .getLog(JAXBBlockContext.class);
041:
042: private TreeSet<String> contextPackages; // List of packages needed by the context
043: private String contextPackagesKey; // Unique key that represents the set of contextPackages (usually toString)
044: private JAXBContext jaxbContext = null; // JAXBContext
045: private JAXBUtils.CONSTRUCTION_TYPE // How the JAXBContext is constructed
046: constructionType = JAXBUtils.CONSTRUCTION_TYPE.UNKNOWN;
047:
048: // There are two modes of marshalling and unmarshalling: "by java type" and "by schema element".
049: // The prefered mode is "by schema element" because it is safe and xml-centric.
050: // However there are some circumstances when "by schema element" is not available.
051: // Examples: RPC Lit processing (the wire element is defined by a wsdl:part...not schema)
052: // Doc/Lit Bare "Minimal" Processing (JAXB ObjectFactories are missing...and thus we must use "by type" for primitives/String)
053: // Please don't use "by java type" processing to get around errors.
054:
055: private Class processType = null;
056: private boolean isxmlList = false;
057:
058: /**
059: * Full Constructor JAXBBlockContext (most performant)
060: *
061: * @param packages Set of packages needed by the JAXBContext.
062: */
063: public JAXBBlockContext(TreeSet<String> packages, String packagesKey) {
064: this .contextPackages = packages;
065: this .contextPackagesKey = packagesKey;
066: }
067:
068: /**
069: * Slightly slower constructor
070: *
071: * @param packages
072: */
073: public JAXBBlockContext(TreeSet<String> packages) {
074: this (packages, packages.toString());
075: }
076:
077: /**
078: * Normal Constructor JAXBBlockContext
079: *
080: * @param contextPackage
081: * @deprecated
082: */
083: public JAXBBlockContext(String contextPackage) {
084: this .contextPackages = new TreeSet();
085: this .contextPackages.add(contextPackage);
086: this .contextPackagesKey = this .contextPackages.toString();
087: }
088:
089: /**
090: * "Dispatch" Constructor Use this full constructor when the JAXBContent is provided by the
091: * customer.
092: *
093: * @param jaxbContext
094: */
095: public JAXBBlockContext(JAXBContext jaxbContext) {
096: this .jaxbContext = jaxbContext;
097: }
098:
099: /** @return Class representing type of the element */
100: public TreeSet<String> getContextPackages() {
101: return contextPackages;
102: }
103:
104: /**
105: * @return get the JAXBContext
106: * @throws JAXBException
107: */
108: public JAXBContext getJAXBContext() throws JAXBException {
109: if (jaxbContext == null) {
110: if (log.isDebugEnabled()) {
111: log
112: .debug("A JAXBContext did not exist, creating a new one with the context packages.");
113: }
114: Holder<JAXBUtils.CONSTRUCTION_TYPE> constructType = new Holder<JAXBUtils.CONSTRUCTION_TYPE>();
115: jaxbContext = JAXBUtils.getJAXBContext(contextPackages,
116: constructType, contextPackagesKey);
117: constructionType = constructType.value;
118: } else {
119: if (log.isDebugEnabled()) {
120: log.debug("Using an existing JAXBContext");
121: }
122: }
123: return jaxbContext;
124: }
125:
126: /** @return RPC Declared Type */
127: public Class getProcessType() {
128: return processType;
129: }
130:
131: /**
132: * Set RPC Declared Type. The use of use this property if the message is style=document is
133: * discouraged.
134: *
135: * @param type
136: */
137: public void setProcessType(Class type) {
138: processType = type;
139: }
140:
141: public JAXBUtils.CONSTRUCTION_TYPE getConstructionType() {
142: return constructionType;
143: }
144:
145: public boolean isxmlList() {
146: return isxmlList;
147: }
148:
149: public void setIsxmlList(boolean isxmlList) {
150: this.isxmlList = isxmlList;
151: }
152:
153: }
|