001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.tools.ws.processor.modeler.annotation;
037:
038: import com.sun.mirror.declaration.MethodDeclaration;
039: import com.sun.mirror.declaration.ParameterDeclaration;
040: import com.sun.mirror.declaration.TypeDeclaration;
041: import com.sun.tools.ws.processor.model.Model;
042: import com.sun.tools.ws.processor.model.Operation;
043: import com.sun.tools.ws.processor.model.Port;
044: import com.sun.tools.ws.processor.model.Service;
045: import com.sun.tools.ws.wsdl.document.soap.SOAPUse;
046:
047: import java.util.Collection;
048: import java.util.HashMap;
049: import java.util.Map;
050:
051: /**
052: *
053: * @author dkohlert
054: */
055: public class AnnotationProcessorContext {
056:
057: private Map<String, SEIContext> seiContextMap;
058: private int round = 1;
059: private boolean modelCompleted = false;
060:
061: /** Creates a new instance of AnnotationProcessorContext */
062: public AnnotationProcessorContext() {
063: seiContextMap = new HashMap<String, SEIContext>();
064: }
065:
066: public void addSEIContext(String seiName, SEIContext seiContext) {
067: seiContextMap.put(seiName, seiContext);
068: }
069:
070: public SEIContext getSEIContext(String seiName) {
071: SEIContext context = seiContextMap.get(seiName);
072: if (context == null) {
073: context = new SEIContext(seiName);
074: addSEIContext(seiName, context);
075: }
076: return context;
077: }
078:
079: public SEIContext getSEIContext(TypeDeclaration d) {
080: SEIContext context = getSEIContext(d.getQualifiedName());
081: return context;
082: }
083:
084: public Collection<SEIContext> getSEIContexts() {
085: return seiContextMap.values();
086: }
087:
088: public int getRound() {
089: return round;
090: }
091:
092: public void incrementRound() {
093: round++;
094: }
095:
096: public static boolean isEncoded(Model model) {
097: if (model == null)
098: return false;
099: for (Service service : model.getServices()) {
100: for (Port port : service.getPorts()) {
101: for (Operation operation : port.getOperations()) {
102: if (operation.getUse() != null
103: && operation.getUse().equals(
104: SOAPUse.LITERAL))
105: return false;
106: }
107: }
108: }
109: return true;
110: }
111:
112: public void setModelCompleted(boolean modelCompleted) {
113: this .modelCompleted = modelCompleted;
114: }
115:
116: public boolean isModelCompleted() {
117: return modelCompleted;
118: }
119:
120: public static class SEIContext {
121: private Map<String, WrapperInfo> reqOperationWrapperMap;
122: private Map<String, WrapperInfo> resOperationWrapperMap;
123: private Map<String, FaultInfo> exceptionBeanMap;
124:
125: private String seiName;
126: private String seiImplName;
127: private boolean implements SEI = false;
128: private String namespaceURI = null;
129:
130: public SEIContext(String seiName) {
131: reqOperationWrapperMap = new HashMap<String, WrapperInfo>();
132: resOperationWrapperMap = new HashMap<String, WrapperInfo>();
133: exceptionBeanMap = new HashMap<String, FaultInfo>();
134: this .seiName = seiName;
135: }
136:
137: public void setImplementsSEI(boolean implements SEI) {
138: this .implements SEI = implements SEI;
139: }
140:
141: public boolean getImplementsSEI() {
142: return implements SEI;
143: }
144:
145: public void setNamespaceURI(String namespaceURI) {
146: this .namespaceURI = namespaceURI;
147: }
148:
149: public String getNamespaceURI() {
150: return namespaceURI;
151: }
152:
153: public String getSEIImplName() {
154: return seiImplName;
155: }
156:
157: public void setSEIImplName(String implName) {
158: seiImplName = implName;
159: }
160:
161: public void setReqWrapperOperation(MethodDeclaration method,
162: WrapperInfo wrapperInfo) {
163: reqOperationWrapperMap.put(methodToString(method),
164: wrapperInfo);
165: }
166:
167: public WrapperInfo getReqOperationWrapper(
168: MethodDeclaration method) {
169: return reqOperationWrapperMap.get(methodToString(method));
170: }
171:
172: public void setResWrapperOperation(MethodDeclaration method,
173: WrapperInfo wrapperInfo) {
174: resOperationWrapperMap.put(methodToString(method),
175: wrapperInfo);
176: }
177:
178: public WrapperInfo getResOperationWrapper(
179: MethodDeclaration method) {
180: return resOperationWrapperMap.get(methodToString(method));
181: }
182:
183: public String methodToString(MethodDeclaration method) {
184: StringBuffer buf = new StringBuffer(method.getSimpleName());
185: for (ParameterDeclaration param : method.getParameters())
186: buf.append(";" + param.getType().toString());
187: return buf.toString();
188: }
189:
190: public void clearExceptionMap() {
191: exceptionBeanMap.clear();
192: }
193:
194: public void addExceptionBeanEntry(String exception,
195: FaultInfo faultInfo, ModelBuilder builder) {
196: exceptionBeanMap.put(exception, faultInfo);
197: }
198:
199: public FaultInfo getExceptionBeanName(String exception) {
200: return exceptionBeanMap.get(exception);
201: }
202: }
203: }
|