| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * |
|---|
| 4 | * Copyright 2006, The jCoderZ.org Project. All rights reserved. |
|---|
| 5 | * |
|---|
| 6 | * Redistribution and use in source and binary forms, with or without |
|---|
| 7 | * modification, are permitted provided that the following conditions are |
|---|
| 8 | * met: |
|---|
| 9 | * |
|---|
| 10 | * * Redistributions of source code must retain the above copyright |
|---|
| 11 | * notice, this list of conditions and the following disclaimer. |
|---|
| 12 | * * Redistributions in binary form must reproduce the above |
|---|
| 13 | * copyright notice, this list of conditions and the following |
|---|
| 14 | * disclaimer in the documentation and/or other materials |
|---|
| 15 | * provided with the distribution. |
|---|
| 16 | * * Neither the name of the jCoderZ.org Project nor the names of |
|---|
| 17 | * its contributors may be used to endorse or promote products |
|---|
| 18 | * derived from this software without specific prior written |
|---|
| 19 | * permission. |
|---|
| 20 | * |
|---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND |
|---|
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS |
|---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|---|
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|---|
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|---|
| 30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|---|
| 31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | */ |
|---|
| 33 | package org.jcoderz.commons.connector.http; |
|---|
| 34 | |
|---|
| 35 | import javax.naming.Reference; |
|---|
| 36 | import javax.resource.ResourceException; |
|---|
| 37 | import javax.resource.spi.ConnectionManager; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | * Factory for the creation of a connection handle used by the client. |
|---|
| 42 | * |
|---|
| 43 | */ |
|---|
| 44 | public class HttpConnectionFactoryImpl |
|---|
| 45 | implements HttpConnectionFactory |
|---|
| 46 | { |
|---|
| 47 | /** The managed connection factory in use. */ |
|---|
| 48 | private final HttpManagedConnectionFactoryImpl mManagedConnectionFactory; |
|---|
| 49 | /** The connection manager in use. */ |
|---|
| 50 | private final ConnectionManager mConnectionManager; |
|---|
| 51 | /** The reference used for JNDI. */ |
|---|
| 52 | private Reference mReference; |
|---|
| 53 | /** Human-readable description. */ |
|---|
| 54 | private String mDescription; |
|---|
| 55 | |
|---|
| 56 | /** |
|---|
| 57 | * Constructor. |
|---|
| 58 | * |
|---|
| 59 | * @param mcf the used ManagedConnectionFactory |
|---|
| 60 | * @param cm the used ConnectionManager |
|---|
| 61 | */ |
|---|
| 62 | public HttpConnectionFactoryImpl (HttpManagedConnectionFactoryImpl mcf, |
|---|
| 63 | ConnectionManager cm) |
|---|
| 64 | { |
|---|
| 65 | mManagedConnectionFactory = mcf; |
|---|
| 66 | mConnectionManager = cm; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | /** {@inheritDoc} */ |
|---|
| 70 | public HttpConnection getConnection (HttpConnectionSpec connectionSpec) |
|---|
| 71 | throws ResourceException |
|---|
| 72 | { |
|---|
| 73 | return new HttpConnectionHelper(this, connectionSpec); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | /** |
|---|
| 77 | * Gets a HttpConnection implementation |
|---|
| 78 | * (here: HttpConnectionImpl - see deployment descriptor) as |
|---|
| 79 | * counterpart of the HttpManagedConnectionImpl. |
|---|
| 80 | * This connection does not support multiple retries and is used |
|---|
| 81 | * within the HttpConnectionHelper to provide retries. |
|---|
| 82 | * |
|---|
| 83 | * @param connectionSpec specifies the target system |
|---|
| 84 | * @return HttpConnection an implementation of the HttpConnection |
|---|
| 85 | * interface |
|---|
| 86 | * @throws ResourceException |
|---|
| 87 | */ |
|---|
| 88 | protected HttpConnection getConnectionHandle ( |
|---|
| 89 | HttpConnectionSpec connectionSpec) |
|---|
| 90 | throws ResourceException |
|---|
| 91 | { |
|---|
| 92 | final HttpConnectionRequestInfo cri = new HttpConnectionRequestInfo( |
|---|
| 93 | mManagedConnectionFactory, connectionSpec); |
|---|
| 94 | final HttpConnection connectionHandle |
|---|
| 95 | = (HttpConnection) mConnectionManager |
|---|
| 96 | .allocateConnection(mManagedConnectionFactory, cri); |
|---|
| 97 | return connectionHandle; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /** {@inheritDoc} */ |
|---|
| 101 | public void setReference (Reference reference) |
|---|
| 102 | { |
|---|
| 103 | mReference = reference; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | /** {@inheritDoc} */ |
|---|
| 107 | public Reference getReference () |
|---|
| 108 | { |
|---|
| 109 | return mReference; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /** |
|---|
| 113 | * Get the human-readable description. |
|---|
| 114 | * |
|---|
| 115 | * @return String - the description of the connector as part of the |
|---|
| 116 | * deployment descriptor |
|---|
| 117 | */ |
|---|
| 118 | public String getDescription () |
|---|
| 119 | { |
|---|
| 120 | return mDescription; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /** |
|---|
| 124 | * Set the human-readable description. |
|---|
| 125 | * |
|---|
| 126 | * @param desc the description of the connector as part of the deployment |
|---|
| 127 | * descriptor |
|---|
| 128 | */ |
|---|
| 129 | public void setDescription (String desc) |
|---|
| 130 | { |
|---|
| 131 | mDescription = desc; |
|---|
| 132 | } |
|---|
| 133 | } |
|---|