Home » geronimo-2.2-source-release » org.apache.geronimo.axis2.pojo » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.axis2.pojo;
   19   
   20   import java.security.Principal;
   21   
   22   import javax.xml.ws.EndpointReference;
   23   import javax.xml.ws.WebServiceContext;
   24   import javax.xml.ws.handler.MessageContext;
   25   
   26   import org.apache.axis2.jaxws.context.WebServiceContextImpl;
   27   import org.w3c.dom.Element;
   28   
   29   /**
   30    * Implementation of WebServiceContext that uses ThreadLocal to associate MessageContext with 
   31    * the thread.
   32    * 
   33    * @version $Rev$ $Date$
   34    */
   35   public class POJOWebServiceContext implements WebServiceContext {
   36   
   37       private static ThreadLocal<WebServiceContextImpl> context = 
   38           new ThreadLocal<WebServiceContextImpl>();
   39       
   40       public POJOWebServiceContext() {        
   41       }
   42           
   43       public final MessageContext getMessageContext() {
   44           WebServiceContextImpl wsContext = context.get();
   45           return (wsContext == null) ? null : wsContext.getMessageContext();
   46       }
   47   
   48       public final Principal getUserPrincipal() {
   49           WebServiceContextImpl wsContext = context.get();
   50           return (wsContext == null) ? null : wsContext.getUserPrincipal();
   51       }
   52   
   53       public final boolean isUserInRole(String user) {
   54           WebServiceContextImpl wsContext = context.get();
   55           return (wsContext == null) ? null : wsContext.isUserInRole(user);
   56       }
   57               
   58       public final EndpointReference getEndpointReference(Element... referenceParameters) {
   59           WebServiceContextImpl wsContext = context.get();
   60           return (wsContext == null) ? null : wsContext.getEndpointReference(referenceParameters);
   61       }
   62       
   63       public final <T extends EndpointReference> T getEndpointReference(Class<T> clazz,
   64                                                                         Element... referenceParameters) {
   65           WebServiceContextImpl wsContext = context.get();
   66           return (wsContext == null) ? null : wsContext.getEndpointReference(clazz, referenceParameters);
   67       }
   68       
   69       static WebServiceContextImpl get() {
   70           return context.get();
   71       }
   72       
   73       static void set(WebServiceContextImpl ctx) {
   74           context.set(ctx);
   75       }
   76       
   77       static void clear() {
   78           context.set(null);
   79       }
   80       
   81   }

Home » geronimo-2.2-source-release » org.apache.geronimo.axis2.pojo » [javadoc | source]