KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > util > connection > ProxyConnection


1 /*
2  * CoadunationUtil: The coadunation util library.
3  * Copyright (C) 2007 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * ProxyConnection.java
20  */

21
22 // package path
23
package com.rift.coad.util.connection;
24
25 // java imports
26
import java.util.Map JavaDoc;
27 import java.util.concurrent.ConcurrentHashMap JavaDoc;
28 import javax.naming.Context JavaDoc;
29
30 // logging import
31
import org.apache.log4j.Logger;
32
33
34 /**
35  * This class manages a proxy connection.
36  *
37  * @author Brett Chaldecott
38  */

39 public class ProxyConnection implements Connection {
40     
41     // the logger reference
42
protected static Logger log =
43             Logger.getLogger(ProxyConnection.class.getName());
44     
45     // private member variables
46
private Context JavaDoc context = null;
47     private String JavaDoc jndiURL = null;
48     private Object JavaDoc ref = null;
49     
50     /**
51      * Creates a new instance of ProxyConnection
52      *
53      * @param context The context object responsible for returning information.
54      * @param jndiURL The url identifying the object.
55      */

56     public ProxyConnection(Context JavaDoc context, String JavaDoc jndiURL) {
57         this.context = context;
58         this.jndiURL = jndiURL;
59     }
60     
61     
62     /**
63      * This object returns the connection to the object.
64      *
65      * @return The retrieve connection to the object.
66      * @param type The type of object to narrow.
67      * @exception ConnectionException
68      * @exception java.lang.ClassCastException
69      */

70     public synchronized Object JavaDoc getConnection(Class JavaDoc type) throws
71             ConnectionException,java.lang.ClassCastException JavaDoc {
72         try {
73             if (ref == null) {
74                 ref = context.lookup(jndiURL);
75             }
76             return ref;
77         } catch (Exception JavaDoc ex) {
78             log.error("Failed to retrieve a connection : " + ex.getMessage(),
79                     ex);
80             throw new ConnectionException("Failed to retrieve a connection : " +
81                     ex.getMessage(),ex);
82         }
83     }
84     
85     
86     /**
87      * This method returns true if the object being passed contains a local
88      * url.
89      *
90      * @return TRUE if a local URL, FALSE if not.
91      * @param jndiURL The string url to perform the check on.
92      */

93     public static boolean isLocalURL(String JavaDoc jndiURL) {
94         if (jndiURL.trim().indexOf("java:comp") == 0) {
95             return true;
96         }
97         return false;
98     }
99 }
100
Popular Tags