Source Code Cross Referenced for LinkProxy.java in  » EJB-Server-resin-3.1.5 » resin » com » caucho » naming » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server resin 3.1.5 » resin » com.caucho.naming 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003:         *
004:         * This file is part of Resin(R) Open Source
005:         *
006:         * Each copy or derived work must preserve the copyright notice and this
007:         * notice unmodified.
008:         *
009:         * Resin Open Source is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU General Public License as published by
011:         * the Free Software Foundation; either version 2 of the License, or
012:         * (at your option) any later version.
013:         *
014:         * Resin Open Source is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017:         * of NON-INFRINGEMENT.  See the GNU General Public License for more
018:         * details.
019:         *
020:         * You should have received a copy of the GNU General Public License
021:         * along with Resin Open Source; if not, write to the
022:         *   Free SoftwareFoundation, Inc.
023:         *   59 Temple Place, Suite 330
024:         *   Boston, MA 02111-1307  USA
025:         *
026:         * @author Scott Ferguson
027:         */
028:
029:        package com.caucho.naming;
030:
031:        import com.caucho.config.ConfigException;
032:        import com.caucho.config.types.InitParam;
033:        import com.caucho.util.L10N;
034:
035:        import javax.annotation.PostConstruct;
036:        import javax.naming.Context;
037:        import javax.naming.InitialContext;
038:        import javax.naming.NamingException;
039:        import javax.naming.spi.InitialContextFactory;
040:        import java.util.Hashtable;
041:        import java.util.logging.Level;
042:        import java.util.logging.Logger;
043:
044:        /**
045:         * An object proxy for a foreign JNDI factory.
046:         */
047:        public class LinkProxy implements  ObjectProxy, java.io.Serializable {
048:            private static Logger log = Logger.getLogger(LinkProxy.class
049:                    .getName());
050:            private static L10N L = new L10N(LinkProxy.class);
051:
052:            // The foreign factory
053:            protected InitialContextFactory _factory;
054:            // The foreign factory
055:            protected Class _factoryClass;
056:            // Properties for the object
057:            protected Hashtable<String, String> _props = new Hashtable<String, String>();
058:            // The jndi-link path
059:            protected String _jndiName;
060:            // The jndi-link path
061:            protected String _jndiLocalName;
062:            // The foreign name
063:            protected String _foreignName;
064:
065:            /**
066:             * Creates a new LinkProxy.
067:             */
068:            public LinkProxy() throws NamingException {
069:            }
070:
071:            /**
072:             * Creates a new LinkProxy.
073:             *
074:             * @param factory the foreign factory
075:             * @param props the properties for the object
076:             * @param name the jndi-link path in the foreign namespace
077:             */
078:            public LinkProxy(InitialContextFactory factory,
079:                    Hashtable<String, String> props, String name)
080:                    throws NamingException {
081:                if (factory == null)
082:                    throw new NullPointerException();
083:
084:                _factory = factory;
085:                _props = props;
086:                _foreignName = name;
087:            }
088:
089:            /**
090:             * Creates a new LinkProxy.
091:             *
092:             * @param name the jndi-link path in the foreign namespace
093:             */
094:            public LinkProxy(String name) throws NamingException {
095:                _foreignName = name;
096:            }
097:
098:            /**
099:             * Sets the jndi name.
100:             */
101:            public void setJndiName(String name) {
102:                _jndiName = name;
103:            }
104:
105:            /**
106:             * Sets the jndi name.
107:             */
108:            public void setJndiLocalName(String name) {
109:                _jndiLocalName = name;
110:            }
111:
112:            /**
113:             * @deprecated Use {@link #setJndiName}
114:             */
115:            public void setName(String name) {
116:                setJndiName(name);
117:            }
118:
119:            /**
120:             * Sets the factory
121:             */
122:            public void setFactory(Class factoryClass) {
123:                _factoryClass = factoryClass;
124:            }
125:
126:            /**
127:             * @deprecated Use {@link #setFactory}
128:             */
129:            public void setJndiFactory(Class factoryClass) {
130:                setFactory(factoryClass);
131:            }
132:
133:            /**
134:             * Sets the foreign-name
135:             */
136:            public void setForeignName(String name) {
137:                _foreignName = name;
138:            }
139:
140:            /**
141:             * Adds init param.
142:             */
143:            public void addInitParam(InitParam initParam) {
144:                if (_props == null)
145:                    _props = new Hashtable<String, String>();
146:
147:                _props.putAll(initParam.getParameters());
148:            }
149:
150:            /**
151:             * Creates the object from the proxy.
152:             *
153:             * @param env the calling environment
154:             *
155:             * @return the object named by the proxy.
156:             */
157:            public Object createObject(Hashtable env) throws NamingException {
158:                Context context;
159:                Hashtable<String, String> mergeEnv;
160:
161:                mergeEnv = new Hashtable<String, String>();
162:
163:                if (env != null && env.size() > 0)
164:                    mergeEnv.putAll(env);
165:                if (_props != null && _props.size() > 0)
166:                    mergeEnv.putAll(_props);
167:
168:                context = new InitialContext(mergeEnv);
169:
170:                if (_foreignName != null) {
171:                    String foreignName;
172:
173:                    if (_factoryClass != null)
174:                        foreignName = _foreignName;
175:                    else
176:                        foreignName = Jndi.getFullName(_foreignName);
177:
178:                    try {
179:                        Object value = context.lookup(foreignName);
180:
181:                        return value;
182:                    } catch (RuntimeException e) {
183:                        throw e;
184:                    } catch (NamingException e) {
185:                        throw e;
186:                    }
187:                } else
188:                    return context;
189:            }
190:
191:            /**
192:             * Initialize the resource.
193:             */
194:            @PostConstruct
195:            public void init() throws Exception {
196:                if (_jndiName == null && _jndiLocalName == null)
197:                    throw new ConfigException(
198:                            L
199:                                    .l("<jndi-link> configuration needs a <jndi-name>.  The <jndi-name> is the JNDI name where the context will be linked."));
200:
201:                Class factoryClass = _factoryClass;
202:
203:                if (factoryClass != null) {
204:                    if (_props == null)
205:                        _props = new Hashtable<String, String>();
206:
207:                    _props.put("java.naming.factory.initial", factoryClass
208:                            .getName());
209:                }
210:
211:                if (log.isLoggable(Level.CONFIG)) {
212:                    if (_foreignName != null)
213:                        log.config("jndi-link[jndi-name=" + _jndiName
214:                                + ", foreign-name=" + _foreignName
215:                                + "] configured");
216:                    else if (_factoryClass != null)
217:                        log.config("jndi-link[jndi-name=" + _jndiName
218:                                + ", factory=" + _factoryClass.getName()
219:                                + "] configured");
220:                }
221:
222:                if (_foreignName != null
223:                        && Jndi.getFullName(_jndiName).equals(
224:                                Jndi.getFullName(_foreignName)))
225:                    return;
226:
227:                // server/155a - not a short link since it needs to be able to bind
228:                // the jndi root
229:                if (_jndiLocalName != null)
230:                    Jndi.rebindDeep(_jndiLocalName, this );
231:                else
232:                    Jndi.rebindDeepShort(_jndiName, this );
233:            }
234:
235:            public String toString() {
236:                if (_factoryClass != null)
237:                    return "LinkProxy[name=" + _jndiName + ",factory="
238:                            + _factoryClass.getName() + "]";
239:                else
240:                    return "LinkProxy[name=" + _jndiName + ",foreign="
241:                            + _foreignName + "]";
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.