| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.commons.connector.file; |
| 34 | | | |
| 35 | | | import java.util.Properties; |
| 36 | | | import java.util.logging.Level; |
| 37 | | | import java.util.logging.Logger; |
| 38 | | | |
| 39 | | | import javax.naming.NamingException; |
| 40 | | | import javax.naming.Reference; |
| 41 | | | import javax.resource.ResourceException; |
| 42 | | | import javax.resource.spi.ConnectionManager; |
| 43 | | | |
| 44 | | | import org.jcoderz.commons.connector.ManagedConnectionFactoryBase; |
| 45 | | | |
| 46 | | | |
| 47 | | | |
| 48 | | | {@link } |
| 49 | | | |
| 50 | | | |
| 51 | | (1) | public class FsConnectionFactoryImpl |
| 52 | | | implements FsConnectionFactory |
| 53 | | | { |
| 54 | | | private static final String METHOD_GET_CONNECTION = "getConnection"; |
| 55 | | | |
| 56 | | | |
| 57 | 75 | | private static final transient String CLASSNAME |
| 58 | | | = FsConnectionFactoryImpl.class.getName(); |
| 59 | | | |
| 60 | 100 | | private static final transient Logger logger = Logger.getLogger(CLASSNAME); |
| 61 | | | |
| 62 | | | <code></code> |
| 63 | | | private static final long serialVersionUID = 1L; |
| 64 | | | |
| 65 | | | |
| 66 | | | private final Properties mDdProps; |
| 67 | | | |
| 68 | | | |
| 69 | | | private Reference mReference; |
| 70 | | | |
| 71 | | | |
| 72 | | | |
| 73 | | | <b></b> |
| 74 | | | |
| 75 | | | <b></b> |
| 76 | | | |
| 77 | | | |
| 78 | | | private final ConnectionManager mConnectionManager; |
| 79 | | | |
| 80 | | | |
| 81 | | | private final ManagedConnectionFactoryBase mMcf; |
| 82 | | | |
| 83 | | | |
| 84 | | | |
| 85 | | | |
| 86 | | | @param |
| 87 | | | @param |
| 88 | | | @param |
| 89 | | | |
| 90 | | | |
| 91 | | | |
| 92 | | | public FsConnectionFactoryImpl (final ConnectionManager cm, |
| 93 | | | final ManagedConnectionFactoryBase mcf, Properties props) |
| 94 | 100 | | { |
| 95 | 100 | | final boolean finer = logger.isLoggable(Level.FINER); |
| 96 | 100 | | if (finer) |
| 97 | | | { |
| 98 | 100 | | logger.entering(CLASSNAME, "FsConnectionFactoryImpl", |
| 99 | | | new Object [] {cm, mcf, props}); |
| 100 | | | } |
| 101 | 100 | | mConnectionManager = cm; |
| 102 | 100 | | mMcf = mcf; |
| 103 | 100 | | mDdProps = props; |
| 104 | | | |
| 105 | 100 | | if (finer) |
| 106 | | | { |
| 107 | 100 | | logger.exiting(CLASSNAME, "FsConnectionFactoryImpl"); |
| 108 | | | } |
| 109 | 100 | | } |
| 110 | | | |
| 111 | | | {@inheritDoc} |
| 112 | | | public FsConnection getConnection () |
| 113 | | | throws ResourceException |
| 114 | | | { |
| 115 | 0 | | logger.entering(CLASSNAME, METHOD_GET_CONNECTION); |
| 116 | | | |
| 117 | 0 | | final FsConnectionRequestInfo fsCri = new FsConnectionRequestInfo( |
| 118 | | | mDdProps); |
| 119 | 0 | | final FsConnection result = allocateConnection(fsCri); |
| 120 | | | |
| 121 | 0 | | logger.exiting(CLASSNAME, METHOD_GET_CONNECTION, result); |
| 122 | 0 | | return result; |
| 123 | | | } |
| 124 | | | |
| 125 | | | {@inheritDoc} |
| 126 | | | public FsConnection getConnection (Properties props) |
| 127 | | | throws ResourceException |
| 128 | | | { |
| 129 | 100 | | logger.entering(CLASSNAME, METHOD_GET_CONNECTION, props); |
| 130 | | | |
| 131 | | | |
| 132 | | | |
| 133 | 100 | | final Properties p = new Properties(); |
| 134 | 100 | | p.putAll(mDdProps); |
| 135 | 100 | | if (props != null) |
| 136 | | | { |
| 137 | 100 | | p.putAll(props); |
| 138 | | | } |
| 139 | | | |
| 140 | 100 | | if (logger.isLoggable(Level.FINER)) |
| 141 | | | { |
| 142 | 100 | | logger.finer("Using properties " + p.toString()); |
| 143 | | | } |
| 144 | 100 | | final FsConnectionRequestInfo fsCri = new FsConnectionRequestInfo(p); |
| 145 | 100 | | final FsConnection result = allocateConnection(fsCri); |
| 146 | | | |
| 147 | 100 | | logger.exiting(CLASSNAME, METHOD_GET_CONNECTION, result); |
| 148 | 100 | | return result; |
| 149 | | | } |
| 150 | | | |
| 151 | | | |
| 152 | | | @param |
| 153 | | | @return |
| 154 | | | @throws |
| 155 | | | |
| 156 | | | private FsConnection allocateConnection (final FsConnectionRequestInfo fsCri) |
| 157 | | | throws ResourceException |
| 158 | | | { |
| 159 | 100 | | fsCri.setUserPassword(mMcf.getUserPassword()); |
| 160 | 100 | | final FsConnection result = (FsConnection) mConnectionManager |
| 161 | | | .allocateConnection(mMcf, fsCri); |
| 162 | 100 | (2) | return result; |
| 163 | | | } |
| 164 | | | |
| 165 | | | {@inheritDoc} |
| 166 | | | public void setReference (Reference reference) |
| 167 | | | { |
| 168 | 0 | | mReference = reference; |
| 169 | 0 | | } |
| 170 | | | |
| 171 | | | {@inheritDoc} |
| 172 | | | public Reference getReference () |
| 173 | | | throws NamingException |
| 174 | | | { |
| 175 | 0 | | return mReference; |
| 176 | | | } |
| 177 | | | |
| 178 | | | |
| 179 | | | @return |
| 180 | | | |
| 181 | | | public ConnectionManager getConnectionManager () |
| 182 | | | { |
| 183 | 100 | | return mConnectionManager; |
| 184 | | | } |
| 185 | | | } |