Project Report: fawkez

Packagesummary org.jcoderz.commons.connector.file

org.jcoderz.commons.connector.file.FsConnectionFactoryImpl

LineHitsNoteSource
1  /*
2   * $Id: FsConnectionFactoryImpl.java 1011 2008-06-16 17:57:36Z amandel $
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.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   * Implements the {@link FsConnectionFactory} interface.
49   *
50   */
51 (1)public class FsConnectionFactoryImpl
52        implements FsConnectionFactory
53  {
54     private static final String METHOD_GET_CONNECTION = "getConnection";
55  
56     /** The full qualified name of this class. */
5775    private static final transient String CLASSNAME
58           = FsConnectionFactoryImpl.class.getName();
59     /** The logger to use. */
60100    private static final transient Logger logger = Logger.getLogger(CLASSNAME);
61  
62     /** The <code>serialVersionUID</code>. */
63     private static final long serialVersionUID = 1L;
64  
65     /** Properties from the deployment descriptor, or default. */
66     private final Properties mDdProps;
67  
68     /** Reference to this ConnectionFactory. */
69     private Reference mReference;
70  
71     /**
72      * The ConnectionManager to use.
73      * In case of <b>two tier scenario</b> the ConnectionManager is an instance
74      * of the DefaultConnectionManager.
75      * In case of <b>three tier scenario</b> this Manager is provided by
76      * the Application Server.
77      */
78     private final ConnectionManager mConnectionManager;
79  
80     /** The underlying ManagedConnectionFactory. */
81     private final ManagedConnectionFactoryBase mMcf;
82  
83     /**
84      * Constructs a new FsConnectionFactoryImpl.
85      *
86      * @param cm The ConnectionManager to use.
87      * @param mcf The underlying ManagedConnectionFactory.
88      * @param props The properties to use. These properties come from the
89      * deployment descriptor if ones defined; otherwise these the default
90      * properties.
91      */
92     public FsConnectionFactoryImpl (final ConnectionManager cm,
93           final ManagedConnectionFactoryBase mcf, Properties props)
94100    {
95100       final boolean finer = logger.isLoggable(Level.FINER);
96100       if (finer)
97        {
98100          logger.entering(CLASSNAME, "FsConnectionFactoryImpl",
99                 new Object [] {cm, mcf, props});
100        }
101100       mConnectionManager = cm;
102100       mMcf = mcf;
103100       mDdProps = props;
104  
105100       if (finer)
106        {
107100          logger.exiting(CLASSNAME, "FsConnectionFactoryImpl");
108        }
109100    }
110  
111     /** {@inheritDoc} */
112     public FsConnection getConnection ()
113           throws ResourceException
114     {
1150       logger.entering(CLASSNAME, METHOD_GET_CONNECTION);
116  
1170       final FsConnectionRequestInfo fsCri = new FsConnectionRequestInfo(
118              mDdProps);
1190       final FsConnection result = allocateConnection(fsCri);
120  
1210       logger.exiting(CLASSNAME, METHOD_GET_CONNECTION, result);
1220       return result;
123     }
124  
125     /** {@inheritDoc} */
126     public FsConnection getConnection (Properties props)
127           throws ResourceException
128     {
129100       logger.entering(CLASSNAME, METHOD_GET_CONNECTION, props);
130  
131        // Merge the properties:
132        // DdProps --> Client Props
133100       final Properties p = new Properties();
134100       p.putAll(mDdProps);
135100       if (props != null)
136        {
137100          p.putAll(props);
138        }
139  
140100       if (logger.isLoggable(Level.FINER))
141        {
142100          logger.finer("Using properties " + p.toString());
143        }
144100       final FsConnectionRequestInfo fsCri = new FsConnectionRequestInfo(p);
145100       final FsConnection result = allocateConnection(fsCri);
146  
147100       logger.exiting(CLASSNAME, METHOD_GET_CONNECTION, result);
148100       return result;
149     }
150  
151     /**
152      * @param fsCri
153    * @return
154      * @throws ResourceException
155    */
156     private FsConnection allocateConnection (final FsConnectionRequestInfo fsCri)
157           throws ResourceException
158     {
159100       fsCri.setUserPassword(mMcf.getUserPassword());
160100       final FsConnection result = (FsConnection) mConnectionManager
161              .allocateConnection(mMcf, fsCri);
162100(2)      return result;
163     }
164  
165     /** {@inheritDoc} */
166     public void setReference (Reference reference)
167     {
1680       mReference = reference;
1690    }
170  
171     /** {@inheritDoc} */
172     public Reference getReference ()
173           throws NamingException
174     {
1750       return mReference;
176     }
177  
178     /**
179      * @return ConnectionManager.
180      */
181     public ConnectionManager getConnectionManager ()
182     {
183100       return mConnectionManager;
184     }
185  }

Findings in this File

i (3) The field org.jcoderz.commons.connector.file.FsConnectionFactoryImpl.CLASSNAME is transient but isn't set by deserialization
c (1) 51 : 0 Type Javadoc comment is missing an @author tag.
w (2) 162 : 0 method org.jcoderz.commons.connector.file.FsConnectionFactoryImpl.allocateConnection(FsConnectionRequestInfo) stores return result in local before immediately returning it