1 /* 2 * Copyright (c) 1997, 2010, 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 23 * questions. 24 */ 25 26 package com.sun.tools.internal.ws.processor.modeler.annotation; 27 28 import com.sun.tools.internal.ws.processor.model.Model; 29 import com.sun.tools.internal.ws.processor.model.Operation; 30 import com.sun.tools.internal.ws.processor.model.Port; 31 import com.sun.tools.internal.ws.processor.model.Service; 32 import com.sun.tools.internal.ws.wsdl.document.soap.SOAPUse; 33 34 import javax.lang.model.element.ExecutableElement; 35 import javax.lang.model.element.Name; 36 import javax.lang.model.element.TypeElement; 37 import javax.lang.model.element.VariableElement; 38 import java.util.Collection; 39 import java.util.HashMap; 40 import java.util.Map; 41 42 43 /** 44 * 45 * @author dkohlert 46 */ 47 public class AnnotationProcessorContext { 48 49 private Map<Name, SeiContext> seiContextMap = new HashMap<Name, SeiContext>(); 50 private int round = 1; 51 private boolean modelCompleted = false; 52 53 public void addSeiContext(Name seiName, SeiContext seiContext) { 54 seiContextMap.put(seiName, seiContext); 55 } 56 57 public SeiContext getSeiContext(Name seiName) { 58 SeiContext context = seiContextMap.get(seiName); 59 if (context == null) { 60 context = new SeiContext(seiName); 61 addSeiContext(seiName, context); 62 } 63 return context; 64 } 65 66 public SeiContext getSeiContext(TypeElement d) { 67 return getSeiContext(d.getQualifiedName()); 68 } 69 70 public Collection<SeiContext> getSeiContexts() { 71 return seiContextMap.values(); 72 } 73 74 public int getRound() { 75 return round; 76 } 77 78 public void incrementRound() { 79 round++; 80 } 81 82 public static boolean isEncoded(Model model) { 83 if (model == null) 84 return false; 85 for (Service service : model.getServices()) { 86 for (Port port : service.getPorts()) { 87 for (Operation operation : port.getOperations()) { 88 if (operation.getUse() != null && operation.getUse().equals(SOAPUse.LITERAL)) 89 return false; 90 } 91 } 92 } 93 return true; 94 } 95 96 public void setModelCompleted(boolean modelCompleted) { 97 this.modelCompleted = modelCompleted; 98 } 99 100 public boolean isModelCompleted() { 101 return modelCompleted; 102 } 103 104 public static class SeiContext { 105 106 private Map<String, WrapperInfo> reqOperationWrapperMap = new HashMap<String, WrapperInfo>(); 107 private Map<String, WrapperInfo> resOperationWrapperMap = new HashMap<String, WrapperInfo>(); 108 private Map<Name, FaultInfo> exceptionBeanMap = new HashMap<Name, FaultInfo>(); 109 110 private Name seiName; 111 private Name seiImplName; 112 private boolean implementsSei; 113 private String namespaceUri; 114 115 public SeiContext(Name seiName) { 116 this.seiName = seiName; 117 } 118 119 public void setImplementsSei(boolean implementsSei) { 120 this.implementsSei = implementsSei; 121 } 122 123 public boolean getImplementsSei() { 124 return implementsSei; 125 } 126 127 public void setNamespaceUri(String namespaceUri) { 128 this.namespaceUri = namespaceUri; 129 } 130 131 public String getNamespaceUri() { 132 return namespaceUri; 133 } 134 135 public Name getSeiImplName() { 136 return seiImplName; 137 } 138 139 public void setSeiImplName(Name implName) { 140 seiImplName = implName; 141 } 142 143 public void setReqWrapperOperation(ExecutableElement method, WrapperInfo wrapperInfo) { 144 reqOperationWrapperMap.put(methodToString(method), wrapperInfo); 145 } 146 147 public WrapperInfo getReqOperationWrapper(ExecutableElement method) { 148 return reqOperationWrapperMap.get(methodToString(method)); 149 } 150 151 public void setResWrapperOperation(ExecutableElement method, WrapperInfo wrapperInfo) { 152 resOperationWrapperMap.put(methodToString(method), wrapperInfo); 153 } 154 155 public WrapperInfo getResOperationWrapper(ExecutableElement method) { 156 return resOperationWrapperMap.get(methodToString(method)); 157 } 158 159 public String methodToString(ExecutableElement method) { 160 StringBuilder buf = new StringBuilder(method.getSimpleName()); 161 for (VariableElement param : method.getParameters()) 162 buf.append(';').append(param.asType()); 163 return buf.toString(); 164 } 165 166 public void clearExceptionMap() { 167 exceptionBeanMap.clear(); 168 } 169 170 public void addExceptionBeanEntry(Name exception, FaultInfo faultInfo, ModelBuilder builder) { 171 exceptionBeanMap.put(exception, faultInfo); 172 } 173 174 public FaultInfo getExceptionBeanName(Name exception) { 175 return exceptionBeanMap.get(exception); 176 } 177 } 178 }