Project Report: fawkez

Packagesummary org.jcoderz.commons.connector.file

org.jcoderz.commons.connector.file.FsManagedConnectionFactoryImpl

LineHitsNoteSource
1  /*
2   * $Id: FsManagedConnectionFactoryImpl.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.resource.ResourceException;
40  import javax.resource.spi.ConnectionManager;
41  import javax.resource.spi.ConnectionRequestInfo;
42  import javax.resource.spi.ManagedConnection;
43   
44  import org.jcoderz.commons.connector.ManagedConnectionFactoryBase;
45  import org.jcoderz.commons.connector.UserPassword;
46   
47   
48  /**
49   * Implements the {@link javax.resource.spi.ManagedConnectionFactory} interface.
50   *
51   */
52 (1)public class FsManagedConnectionFactoryImpl
53        extends ManagedConnectionFactoryBase
54  {
55     /** Min value for chunk size, just 1KByte. */
56     public static final long FILE_TRANSFER_CHUNK_SIZE_MIN_VALUE = 1000L;
57     /** Max value for chunk size, just {@link Integer#MAX_VALUE}. */
58     public static final long FILE_TRANSFER_CHUNK_SIZE_MAX_VALUE
59           = Integer.MAX_VALUE;
60   
61     /** The full qualified name of this class. */
62     private static final String CLASSNAME
63           = FsManagedConnectionFactoryImpl.class.getName();
64   
65     /** The logger to use. */
66     private static final Logger logger = Logger.getLogger(CLASSNAME);
67   
68     /** Generated <code>serialVersionUID</code>. */
69     private static final long serialVersionUID = 3258409517263172660L;
70   
71     private final Properties mProps = new Properties();
72   
73     protected ManagedConnection createManagedConnectionImpl (UserPassword up,
74           ConnectionRequestInfo cri)
75     {
76        final boolean finer = logger.isLoggable(Level.FINER);
77        if (finer)
78        {
79           logger.entering(CLASSNAME, "createManagedConnectionImpl",
80                 new Object [] {up, cri});
81        }
82        final ConnectionRequestInfo info;
83   
84        if (cri == null)
85        {
86           final FsConnectionRequestInfo fsCri = new FsConnectionRequestInfo();
87           fsCri.setUserPassword(up);
88 (2)         info = fsCri;
89        }
90        else
91        {
92           info = cri;
93        }
94   
95        final ManagedConnection result = new FsManagedConnectionImpl(this, up,
96 (3)            cri); // CHECKME: use info variable?
97   
98        if (finer)
99        {
100           logger.exiting(CLASSNAME, "createManagedConnectionImpl", result);
101        }
102        return result;
103     }
104   
105   
106     protected boolean isMatchingManagedConnection (ManagedConnection mc,
107           UserPassword up, ConnectionRequestInfo cri)
108           throws ResourceException
109     {
110        final boolean finer = logger.isLoggable(Level.FINER);
111        if (finer)
112        {
113           logger.entering(CLASSNAME, "isMatchingManagedConnection",
114                 new Object [] {mc, up, cri});
115        }
116        boolean result = false;
117   
118        if ((mc instanceof FsManagedConnectionImpl)
119              && (cri instanceof FsConnectionRequestInfo))
120        {
121           final FsManagedConnectionImpl mci = (FsManagedConnectionImpl) mc;
122   
123           if (mci.getUserPassword().equals(up))
124           {
125              result = true;
126           }
127        }
128   
129        if (finer)
130        {
131           logger.exiting(CLASSNAME, "isMatchingManagedConnection",
132                 Boolean.valueOf(result));
133        }
134   
135        return result;
136     }
137   
138   
139     /**
140      * Creates a new FsConnectionFactoryImpl instance.
141      * @param cm The ConectionManager to use.
142      * @throws ResourceException thrown in error cases.
143      *
144      * @see org.jcoderz.commons.connector.ManagedConnectionFactoryBase#createConnectionFactoryImpl(javax.resource.spi.ConnectionManager)
145      */
146     protected Object createConnectionFactoryImpl (ConnectionManager cm)
147           throws ResourceException
148     {
149        final boolean finer = logger.isLoggable(Level.FINER);
150        if (finer)
151        {
152           logger.entering(CLASSNAME, "createConnectionFactoryImpl", cm);
153        }
154   
155        checkProps();
156        final FsConnectionFactoryImpl result = new FsConnectionFactoryImpl(cm,
157              this, mProps);
158        if (finer)
159        {
160           logger.exiting(CLASSNAME, "createConnectionFactoryImpl", result);
161        }
162        return result;
163     }
164   
165     private void checkProps ()
166     {
167        if (!mProps.containsKey(
168              FsConnectionFactory.PROP_FILE_TRANSFER_CHUNK_SIZE))
169        {
170           mProps.setProperty(FsConnectionFactory.PROP_FILE_TRANSFER_CHUNK_SIZE,
171                 String.valueOf(
172                       FsConnectionFactory.FILE_TRANSFER_CHUNK_SIZE_DEF_VALUE));
173        }
174     }
175   
176     /**
177      * Sets the chunk size used while file transfering.
178      * If a file size exceeds the chunk size, the file will be transfered chunk
179      * by chunk until all bytes will have been transfered. The Min value for this
180      * property is
181      * {@link FsManagedConnectionFactoryImpl#FILE_TRANSFER_CHUNK_SIZE_MIN_VALUE},
182      * the Max value is
183      * {@link FsManagedConnectionFactoryImpl#FILE_TRANSFER_CHUNK_SIZE_MAX_VALUE}.
184      * If this property is not defined in the deployment descriptor the file
185      * connector will use the default value
186      * {@linkplain FsConnectionFactory#FILE_TRANSFER_CHUNK_SIZE_DEF_VALUE}.
187      * Too small value will probably slow the performance down, and too large
188      * value may cause a resource's allocation problem. The value of this
189      * property should be adjusted to the underlying os, file system and
190      * available memory.
191      * A connection client can overwrite this value by passing a property
192      * object while retrieving a connection by calling the method
193      * {@link FsConnectionFactory#getConnection(Properties)}.
194      *
195      * @param size the new chunk size to set.
196      */
197     public void setFileTransferChunkSize (Long size)
198     {
199        final String method = "setFileTransferChunkSize";
200        logger.entering(CLASSNAME, method, size);
201   
202        final String usedSize;
203        if (size.longValue() < FILE_TRANSFER_CHUNK_SIZE_MIN_VALUE
204              || size.longValue() > FILE_TRANSFER_CHUNK_SIZE_MAX_VALUE)
205        {
206           if (logger.isLoggable(Level.FINE))
207           {
208              logger.fine("The given file transfer chunk " + size
209                    + " could not be set. The chunk size should be between "
210                    + FILE_TRANSFER_CHUNK_SIZE_MIN_VALUE + " and "
211                    + FILE_TRANSFER_CHUNK_SIZE_MAX_VALUE
212                    + ". The file connector wiil use the default chunk size "
213                    + FsConnectionFactory.FILE_TRANSFER_CHUNK_SIZE_DEF_VALUE);
214           }
215           usedSize = String.valueOf(
216                 FsConnectionFactory.FILE_TRANSFER_CHUNK_SIZE_DEF_VALUE);
217        }
218        else
219        {
220           usedSize = size.toString();
221        }
222   
223        mProps.setProperty(FsConnectionFactory.PROP_FILE_TRANSFER_CHUNK_SIZE,
224              String.valueOf(usedSize));
225   
226        logger.exiting(CLASSNAME, method);
227     }
228   
229     /**
230      * Defines the temporary directory to be used by this connector. The default
231      * value will be retrieved from the system property 'java.io.tmpdir'.
232      * A connection client can overwrite this value by passing the property
233      * {@linkplain FsConnectionFactory#PROP_TEMP_DIR} while retrieving a
234      * connection by calling the method
235      * {@link FsConnectionFactory#getConnection(Properties)}.
236      *
237      * @param dir temp dir to set.
238      */
239     public void setTempDir (String dir)
240     {
241        logger.entering(CLASSNAME, "setTempDir", dir);
242        mProps.setProperty(FsConnectionFactory.PROP_TEMP_DIR, dir);
243        logger.exiting(CLASSNAME, "setTempDir");
244     }
245  }
246   

Findings in this File

c (1) 52 : 0 Type Javadoc comment is missing an @author tag.
w (2) 88 : 0 Dead store to info in org.jcoderz.commons.connector.file.FsManagedConnectionFactoryImpl.createManagedConnectionImpl(UserPassword, ConnectionRequestInfo)
i (3) 96 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.