KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > soap > jaxws > PortProxyHandler


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.soap.jaxws;
31
32 import com.caucho.soap.skeleton.Skeleton;
33 import com.caucho.util.L10N;
34
35 import javax.xml.ws.BindingProvider;
36 import java.lang.reflect.InvocationHandler JavaDoc;
37 import java.lang.reflect.Method JavaDoc;
38 import java.util.HashMap JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40
41 /**
42  * Port handler
43  */

44 public class PortProxyHandler implements InvocationHandler JavaDoc {
45   private final static Logger JavaDoc log
46     = Logger.getLogger(PortProxyHandler.class.getName());
47   private final static L10N L = new L10N(PortProxyHandler.class);
48
49   private final static HashMap JavaDoc<Method JavaDoc,SpecialMethod> _specialMethods
50     = new HashMap JavaDoc<Method JavaDoc,SpecialMethod>();
51   
52   private Skeleton _skeleton;
53   private String JavaDoc _url;
54
55   private HashMap JavaDoc<String JavaDoc,Object JavaDoc> _requestContext
56     = new HashMap JavaDoc<String JavaDoc,Object JavaDoc>();
57
58   private HashMap JavaDoc<String JavaDoc,Object JavaDoc> _responseContext
59     = new HashMap JavaDoc<String JavaDoc,Object JavaDoc>();
60
61   public PortProxyHandler(Skeleton skeleton, String JavaDoc url)
62   {
63     _url = url;
64     _skeleton = skeleton;
65   }
66
67   public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args)
68     throws Throwable JavaDoc
69   {
70     SpecialMethod specialMethod = _specialMethods.get(method);
71
72     if (specialMethod != null) {
73       switch (specialMethod) {
74         case TO_STRING:
75           return "PortProxyHandler[]";
76         case EQUALS:
77           return false;
78         case HASH_CODE:
79           return System.identityHashCode(this);
80
81         case GET_REQUEST_CONTEXT:
82           return _requestContext;
83
84         case GET_RESPONSE_CONTEXT:
85           return _responseContext;
86       }
87     }
88     
89     Object JavaDoc ret = _skeleton.invoke(method, _url, args);
90
91     return ret;
92   }
93
94   static {
95     try {
96       _specialMethods.put(Object JavaDoc.class.getMethod("toString",
97                                                  new Class JavaDoc[0]),
98                           SpecialMethod.TO_STRING);
99     
100       _specialMethods.put(Object JavaDoc.class.getMethod("equals",
101                                                  new Class JavaDoc[] { Object JavaDoc.class }),
102                           SpecialMethod.EQUALS);
103     
104       _specialMethods.put(Object JavaDoc.class.getMethod("hashCode",
105                                                  new Class JavaDoc[0]),
106                           SpecialMethod.HASH_CODE);
107       
108       _specialMethods.put(BindingProvider.class.getMethod("getRequestContext",
109                                                           new Class JavaDoc[0]),
110                           SpecialMethod.GET_REQUEST_CONTEXT);
111       
112       _specialMethods.put(BindingProvider.class.getMethod("getResponseContext",
113                                                           new Class JavaDoc[0]),
114                           SpecialMethod.GET_RESPONSE_CONTEXT);
115     }
116     catch (Exception JavaDoc e) {
117       e.printStackTrace();
118     }
119   }
120
121   enum SpecialMethod {
122     TO_STRING,
123     EQUALS,
124     HASH_CODE,
125     
126     GET_REQUEST_CONTEXT,
127     GET_RESPONSE_CONTEXT
128   };
129 }
130
Popular Tags