1 /* 2 * Copyright (c) 1997, 2012, 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(); 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 seiImplName; 111 private boolean implementsSei; 112 private String namespaceUri; 113 114 public SeiContext() {}; 115 116 /** 117 * @deprecated use empty constructor, seiName value is ignored 118 * @param seiName 119 */ 120 public SeiContext(Name seiName) {}; 121 122 public void setImplementsSei(boolean implementsSei) { 123 this.implementsSei = implementsSei; 124 } 125 126 public boolean getImplementsSei() { 127 return implementsSei; 128 } 129 130 public void setNamespaceUri(String namespaceUri) { 131 this.namespaceUri = namespaceUri; 132 } 133 134 public String getNamespaceUri() { 135 return namespaceUri; 136 } 137 138 public Name getSeiImplName() { 139 return seiImplName; 140 } 141 142 public void setSeiImplName(Name implName) { 143 seiImplName = implName; 144 } 145 146 public void setReqWrapperOperation(ExecutableElement method, WrapperInfo wrapperInfo) { 147 reqOperationWrapperMap.put(methodToString(method), wrapperInfo); 148 } 149 150 public WrapperInfo getReqOperationWrapper(ExecutableElement method) { 151 return reqOperationWrapperMap.get(methodToString(method)); 152 } 153 154 public void setResWrapperOperation(ExecutableElement method, WrapperInfo wrapperInfo) { 155 resOperationWrapperMap.put(methodToString(method), wrapperInfo); 156 } 157 158 public WrapperInfo getResOperationWrapper(ExecutableElement method) { 159 return resOperationWrapperMap.get(methodToString(method)); 160 } 161 162 public String methodToString(ExecutableElement method) { 163 StringBuilder buf = new StringBuilder(method.getSimpleName()); 164 for (VariableElement param : method.getParameters()) 165 buf.append(';').append(param.asType()); 166 return buf.toString(); 167 } 168 169 public void clearExceptionMap() { 170 exceptionBeanMap.clear(); 171 } 172 173 public void addExceptionBeanEntry(Name exception, FaultInfo faultInfo, ModelBuilder builder) { 174 exceptionBeanMap.put(exception, faultInfo); 175 } 176 177 public FaultInfo getExceptionBeanName(Name exception) { 178 return exceptionBeanMap.get(exception); 179 } 180 } 181 }