Source Code Cross Referenced for CoadunationContext.java in  » Net » Coadunation_1.0.1 » com » rift » coad » client » 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 » Net » Coadunation_1.0.1 » com.rift.coad.client.naming 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <Add library description here>
003:         * Copyright (C) 2006  Rift IT Contracting
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
018:         *
019:         * CoadunationContext.java
020:         *
021:         * The implementation of the Coadunation client context. Used to lookup RMI
022:         * information.
023:         *
024:         * Revision: $ID
025:         */
026:
027:        // package path
028:        package com.rift.coad.client.naming;
029:
030:        // java imports
031:        import java.io.Serializable;
032:        import java.util.Hashtable;
033:        import java.util.Properties;
034:        import javax.naming.CompoundName;
035:        import javax.naming.Context;
036:        import javax.naming.Name;
037:        import javax.naming.NameParser;
038:        import javax.naming.NamingEnumeration;
039:        import javax.naming.NamingException;
040:        import javax.naming.InitialContext;
041:        import org.omg.CORBA.ORB;
042:
043:        // logging import
044:        import org.apache.log4j.Logger;
045:
046:        import com.rift.coad.lib.interceptor.credentials.Login;
047:
048:        /**
049:         * The implementation of the Coadunation client context. Used to lookup RMI
050:         * information.
051:         *
052:         * @author Brett Chaldecott
053:         */
054:        public class CoadunationContext implements  Context {
055:
056:            /**
057:             * This object is responsible for parsing the string value passed in. Valid
058:             * names must be formated as "this/is/valid".
059:             *
060:             * @author Brett Chaldecott
061:             */
062:            public class NamingParser implements  NameParser, Serializable {
063:
064:                /**
065:                 * Creates a new instance of NamingParser
066:                 */
067:                public NamingParser() {
068:                }
069:
070:                /**
071:                 * The method responsible for parsing the string value into a name value.
072:                 *
073:                 * @return The parse name object.
074:                 * @param name The name to parse.
075:                 * @exception NamingException
076:                 */
077:                public Name parse(String name) throws NamingException {
078:                    return new CompoundName(name, syntax);
079:                }
080:            }
081:
082:            // The classes static variables
083:            private static Properties syntax = new Properties();
084:            static {
085:                syntax.setProperty("jndi.syntax.direction", "left_to_right");
086:                syntax.setProperty("jndi.syntax.separator", "/");
087:                syntax.setProperty("jndi.syntax.ignorecase", "false");
088:                syntax.setProperty("jndi.syntax.escape", "\\");
089:            }
090:            protected static Logger log = Logger
091:                    .getLogger(CoadunationContext.class.getName());
092:
093:            // class private member variables
094:            private ORB orb = null;
095:            private Hashtable env = null;
096:            private Context primaryContext = null;
097:            private Name prefix = null;
098:
099:            /** 
100:             * Creates a new instance of CoadunationContext 
101:             *
102:             * @param env The environment.
103:             * @param orb The orb reference.
104:             */
105:            public CoadunationContext(ORB orb, Hashtable env) {
106:                this .orb = orb;
107:                this .env = env;
108:                try {
109:                    prefix = new NamingParser().parse("");
110:                } catch (Exception ex) {
111:                    log.error("Failed to parse the name : " + ex.getMessage(),
112:                            ex);
113:                }
114:            }
115:
116:            /** 
117:             * Creates a new instance of CoadunationContext 
118:             */
119:            public CoadunationContext(Hashtable env, Name prefix) {
120:                this .env = env;
121:                this .prefix = prefix;
122:            }
123:
124:            /**
125:             * Adds a new environment property to the environment of this context.
126:             *
127:             * @return The previous value of the property or null.
128:             * @param propName The property to replace or add.
129:             * @param propValue The new property value.
130:             */
131:            public Object addToEnvironment(String propName, Object propVal)
132:                    throws NamingException {
133:                throw new NamingException("Not implemented");
134:            }
135:
136:            /**
137:             * Binds a name to an object.
138:             *
139:             * @param name The name of the object to bind.
140:             * @param obj The object to bind.
141:             * @exception NamingException
142:             */
143:            public void bind(Name name, Object obj) throws NamingException {
144:                throw new NamingException("Not implemented");
145:            }
146:
147:            /**
148:             * Binds a name to an object.
149:             */
150:            public void bind(String name, Object obj) throws NamingException {
151:                throw new NamingException("Not implemented");
152:            }
153:
154:            /**
155:             * Closes this context.
156:             */
157:            public void close() throws NamingException {
158:                if (primaryContext != null) {
159:                    primaryContext.close();
160:                    primaryContext = null;
161:                }
162:            }
163:
164:            /**
165:             * Composes the name of this context with a name relative to this context.
166:             *
167:             * @return The compisit name.
168:             * @param name The name to add to the prefix.
169:             * @param prefix The prefix of the current context.
170:             * @exception NamingException
171:             */
172:            public Name composeName(Name name, Name prefix)
173:                    throws NamingException {
174:                return null;
175:            }
176:
177:            /**
178:             * Composes the name of this context with a name relative to this context.
179:             *
180:             * @return The string version of the composed name.
181:             * @param name The name to add to the preffix.
182:             * @param prefix The prefix for this context.
183:             */
184:            public String composeName(String name, String prefix)
185:                    throws NamingException {
186:                return null;
187:            }
188:
189:            /**
190:             * Creates and binds a new context to this context.
191:             *
192:             * @return The newly created context.
193:             * @param name The name of the new sub context.
194:             * @exception NamingException
195:             */
196:            public Context createSubcontext(Name name) throws NamingException {
197:                throw new NamingException("Not implemented");
198:            }
199:
200:            /**
201:             * Creates and binds a new context.
202:             *
203:             * @return The newly create sub context.
204:             * @exception name The name of the new sub context.
205:             * @exception NamingException
206:             */
207:            public Context createSubcontext(String name) throws NamingException {
208:                throw new NamingException("Not implemented");
209:            }
210:
211:            /**
212:             * Destroys the named context and removes it from the namespace.
213:             *
214:             * @param name The name of the sub context to remove.
215:             * @exception NamingException
216:             */
217:            public void destroySubcontext(Name name) throws NamingException {
218:                throw new NamingException("Not implemented");
219:            }
220:
221:            /**
222:             * Destroys the named context and removes it from the namespace.
223:             *
224:             * @param name The name of the context to destroy.
225:             */
226:            public void destroySubcontext(String name) throws NamingException {
227:                throw new NamingException("Not implemented");
228:            }
229:
230:            /**
231:             * Retrieves the environment in effect for this context.
232:             *
233:             * @return The reference to the hash table.
234:             * @exception NamingException
235:             */
236:            public Hashtable getEnvironment() throws NamingException {
237:                return null;
238:            }
239:
240:            /**
241:             * Retrieves the full name of this context within its own namespace.
242:             */
243:            public String getNameInNamespace() throws NamingException {
244:                return null;
245:            }
246:
247:            /**
248:             * Retrieves the parser associated with the named context.
249:             *
250:             * @return The reference to the name parser.
251:             * @param name The name to return the parser for.
252:             * @exception NamingException
253:             */
254:            public NameParser getNameParser(Name name) throws NamingException {
255:                return null;
256:            }
257:
258:            /**
259:             * Retrieves the parser associated with the named context.
260:             */
261:            public NameParser getNameParser(String name) throws NamingException {
262:                return null;
263:            }
264:
265:            /**
266:             * Enumerates the names bound in the named context, along with the class
267:             * names of objects bound to them.
268:             */
269:            public NamingEnumeration list(Name name) throws NamingException {
270:                throw new NamingException("Not implemented");
271:            }
272:
273:            /**
274:             * Enumerates the names bound in the named context, along with the class
275:             * names of objects bound to them.
276:             *
277:             * @return The list of names bound to this context.
278:             * @param name The list of names.
279:             * @exception NamingException
280:             */
281:            public NamingEnumeration list(String name) throws NamingException {
282:                throw new NamingException("Not implemented");
283:            }
284:
285:            /**
286:             * Enumerates the names bound in the named context, along with the objects
287:             * bound to them.
288:             *
289:             * @return The list of bindings for the name
290:             * @param name The name to perform the search below.
291:             * @exception NamingException
292:             */
293:            public NamingEnumeration listBindings(Name name)
294:                    throws NamingException {
295:                throw new NamingException("Not implemented");
296:            }
297:
298:            /**
299:             * Enumerates the names bound in the named context, along with the objects
300:             * bound to them.
301:             *
302:             * @return The list of binding for the name.
303:             * @param name The name to perform the search for.
304:             * @exception NamingException
305:             */
306:            public NamingEnumeration listBindings(String name)
307:                    throws NamingException {
308:                throw new NamingException("Not implemented");
309:            }
310:
311:            /**
312:             * Retrieves the named object.
313:             *
314:             * @return The named object.
315:             * @param name The name to retrieve the object for.
316:             * @exception NamingException
317:             */
318:            public Object lookup(Name name) throws NamingException {
319:                Context context = getContext();
320:                String currentName = null;
321:                try {
322:                    if (this .env
323:                            .containsKey(CoadunationInitialContextFactory.USERNAME)
324:                            && this .env
325:                                    .containsKey(CoadunationInitialContextFactory.PASSWORD)) {
326:                        CoadunationInitialContextFactory.userLogin
327:                                .set(new Login(
328:                                        (String) this .env
329:                                                .get(CoadunationInitialContextFactory.USERNAME),
330:                                        (String) this .env
331:                                                .get(CoadunationInitialContextFactory.PASSWORD)));
332:                    } else {
333:                        CoadunationInitialContextFactory.userLogin.set(null);
334:                    }
335:                    Name composedName = (Name) prefix.clone();
336:                    composedName.addAll(name);
337:                    for (int index = 0; index < (composedName.size() - 1); index++) {
338:                        currentName = composedName.get(index);
339:                        context = (Context) context.lookup(currentName);
340:                    }
341:                    currentName = composedName.get(composedName.size() - 1);
342:                    Object result = context.lookup(currentName);
343:                    if (result instanceof  com.sun.corba.se.impl.corba.CORBAObjectImpl) {
344:                        com.sun.corba.se.impl.corba.CORBAObjectImpl obj = (com.sun.corba.se.impl.corba.CORBAObjectImpl) result;
345:                        if (result instanceof  Context) {
346:                            return new CoadunationContext(env, composedName);
347:                        }
348:                    }
349:                    return result;
350:                } catch (NamingException ex) {
351:                    this .invalidateContext();
352:                    log.error("Failed to lookup the object [" + currentName
353:                            + "] :" + ex.getMessage(), ex);
354:                    throw ex;
355:                } catch (Exception ex) {
356:                    this .invalidateContext();
357:                    log.error("Failed to lookup the object [" + currentName
358:                            + "] :" + ex.getMessage(), ex);
359:                    throw new NamingException("Failed to lookup the object ["
360:                            + currentName + "] :" + ex.getMessage());
361:                }
362:            }
363:
364:            /**
365:             * Retrieves the named object.
366:             *
367:             * @return The object to retrieve by name.
368:             * @param name The name of the object to retrieve.
369:             * @exception NamingException
370:             */
371:            public Object lookup(String name) throws NamingException {
372:                return lookup(new NamingParser().parse(name));
373:            }
374:
375:            /**
376:             * Retrieves the named object, following links except for the terminal
377:             * atomic component of the name.
378:             *
379:             * @return The object to retrieve.
380:             * @param name The name of the object to lookup.
381:             * @exception NamingException
382:             */
383:            public Object lookupLink(Name name) throws NamingException {
384:                throw new NamingException("Not implemented");
385:            }
386:
387:            /**
388:             * Retrieves the named object, following links except for the terminal
389:             * atomic component of the name.
390:             *
391:             * @return The results of the lookup link.
392:             * @param name The name of the object to lookup.
393:             * @exception NamingException
394:             */
395:            public Object lookupLink(String name) throws NamingException {
396:                throw new NamingException("Not implemented");
397:            }
398:
399:            /**
400:             * Binds a name to an object, overwriting any existing binding.
401:             *
402:             * @param name The name to rebind.
403:             * @param obj The object to rebind.
404:             * @exception NamingException
405:             */
406:            public void rebind(Name name, Object obj) throws NamingException {
407:                throw new NamingException("Not implemented");
408:            }
409:
410:            /**
411:             * Binds a name to an object, overwriting any existing binding.
412:             *
413:             * @param name The name to rebind.
414:             * @param obj The object to rebind.
415:             * @exception NamingException
416:             */
417:            public void rebind(String name, Object obj) throws NamingException {
418:                throw new NamingException("Not implemented");
419:            }
420:
421:            /**
422:             * Removes an environment property from the environment of this context.
423:             *
424:             * @param propName The name of the entry to remove from the environment.
425:             * @exception NamingException
426:             */
427:            public Object removeFromEnvironment(String propName)
428:                    throws NamingException {
429:                throw new NamingException("Not implemented");
430:            }
431:
432:            /**
433:             * Binds a new name to the object bound to an old name, and unbinds the old
434:             * name.
435:             *
436:             * @param oldName The old name to rename.
437:             * @param newName The name to replace it with.
438:             * @exception NamingException
439:             */
440:            public void rename(Name oldName, Name newName)
441:                    throws NamingException {
442:                throw new NamingException("Not implemented");
443:            }
444:
445:            /**
446:             * Binds a new name to the object bound to an old name, and unbinds the old
447:             * name.
448:             *
449:             * @param oldName The old name to rename.
450:             * @param newName The name to replace it with.
451:             * @exception NamingException
452:             */
453:            public void rename(String oldName, String newName)
454:                    throws NamingException {
455:                throw new NamingException("Not implemented");
456:            }
457:
458:            /**
459:             * Unbinds the named object.
460:             *
461:             * @param name The name to unbind.
462:             * @exception NamingException
463:             */
464:            public void unbind(Name name) throws NamingException {
465:                throw new NamingException("Not implemented");
466:            }
467:
468:            /**
469:             * Unbinds the named objec.
470:             *
471:             * @param name The name to unbind.
472:             * @exception NamingException
473:             */
474:            public void unbind(String name) throws NamingException {
475:                throw new NamingException("Not implemented");
476:            }
477:
478:            /**
479:             * This method returns a valid context
480:             */
481:            public synchronized Context getContext() throws NamingException {
482:                if (primaryContext != null) {
483:                    return primaryContext;
484:                }
485:                return primaryContext = new InitialContext(env);
486:            }
487:
488:            /**
489:             * This method invalidates a bad context.
490:             */
491:            public synchronized void invalidateContext() {
492:                primaryContext = null;
493:            }
494:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.