View Javadoc

1   /*
2    *  Copyright (c) 2008 Rodrigo Ruiz
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.apache.axis.message.addressing.handler;
17  
18  import org.apache.axis.AxisFault;
19  import org.apache.axis.handlers.BasicHandler;
20  import org.apache.ws.addressing.uuid.AxisUUIdGenerator;
21  import org.apache.ws.addressing.uuid.UUIdGeneratorFactory;
22  
23  import javax.xml.namespace.QName;
24  import javax.xml.rpc.JAXRPCException;
25  import javax.xml.rpc.handler.Handler;
26  import javax.xml.rpc.handler.HandlerInfo;
27  
28  /**
29   * Helper class to which the Axis-specific JAX-RPC handlers in this package
30   * can delegate methods defined in the Axis {@link org.apache.axis.Handler}
31   * interface. This is done so that the Axis handler base class
32   * {@link BasicHandler} can be leveraged.
33   *
34   * @author Ian P. Springer
35   * @version $Revision: 14 $
36   */
37  class GenericAxisHandler extends BasicHandler {
38  
39    /**
40     * <code>serialVersionUID</code> attribute.
41     */
42    private static final long serialVersionUID = 8224510670209322980L;
43  
44    /**
45     * Wrapped handler.
46     */
47    private transient Handler jaxRpcHandler;
48  
49    /**
50     * Creates a new instance.
51     *
52     * @param handler Wrapped handler
53     */
54    public GenericAxisHandler(Handler handler) {
55      jaxRpcHandler = handler;
56    }
57  
58    /**
59     * {@inheritDoc}
60     */
61    @Override
62    public void init() {
63      jaxRpcHandler.init(new HandlerInfo(jaxRpcHandler.getClass(), getOptions(),
64          new QName[0]));
65    }
66  
67    /**
68     * {@inheritDoc}
69     */
70    public void invoke(org.apache.axis.MessageContext msgContext) throws AxisFault {
71      if (!msgContext.getPastPivot()) {
72        jaxRpcHandler.handleRequest(msgContext);
73      } else {
74        jaxRpcHandler.handleResponse(msgContext);
75      }
76    }
77  
78    /**
79     * {@inheritDoc}
80     */
81    @Override
82    public void onFault(org.apache.axis.MessageContext msgContext) {
83      jaxRpcHandler.handleFault(msgContext);
84    }
85  
86    /**
87     * Use the UUID generator that comes with Axis.
88     *
89     * @return a UUID
90     */
91    String generateUUId() {
92      try {
93        return UUIdGeneratorFactory.getGenerator().generateUUId();
94      } catch (RuntimeException re) {
95        throw new JAXRPCException("Failed to generate UUId using Axis UUId generator "
96            + AxisUUIdGenerator.class.getName() + ".", re);
97      }
98    }
99  
100 }