Source Code Cross Referenced for JndiUtils.java in  » Web-Crawler » heritrix » org » archive » util » 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 » Web Crawler » heritrix » org.archive.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JndiUtils.java
002:         *
003:         * Created Aug 11, 2005
004:         *
005:         * Copyright (C) 2005 Internet Archive.
006:         *
007:         * This file is part of the Heritrix web crawler (crawler.archive.org).
008:         *
009:         * Heritrix is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU Lesser Public License as published by
011:         * the Free Software Foundation; either version 2.1 of the License, or
012:         * any later version.
013:         *
014:         * Heritrix 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.  See the
017:         * GNU Lesser Public License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser Public License
020:         * along with Heritrix; if not, write to the Free Software
021:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
022:         */
023:        package org.archive.util;
024:
025:        import java.util.Enumeration;
026:        import java.util.Hashtable;
027:        import java.util.Properties;
028:
029:        import javax.management.MalformedObjectNameException;
030:        import javax.management.ObjectName;
031:        import javax.naming.CompoundName;
032:        import javax.naming.Context;
033:        import javax.naming.InitialContext;
034:        import javax.naming.InvalidNameException;
035:        import javax.naming.NameNotFoundException;
036:        import javax.naming.NamingException;
037:        import javax.naming.Reference;
038:        import javax.naming.StringRefAddr;
039:
040:        /**
041:         * JNDI utilities.
042:         * @author stack
043:         * @version $Date: 2005-10-27 22:20:20 +0000 (Thu, 27 Oct 2005) $ $Version$
044:         */
045:        public class JndiUtils {
046:            /**
047:             * Syntax that will work with jmx ObjectNames (i.e. will escape '.' and
048:             * will add treat ',' and '=' specially.
049:             */
050:            private static final Properties COMPOUND_NAME_SYNTAX = new Properties();
051:            static {
052:                COMPOUND_NAME_SYNTAX.put("jndi.syntax.direction",
053:                        "left_to_right");
054:                COMPOUND_NAME_SYNTAX.put("jndi.syntax.separator", "+");
055:                COMPOUND_NAME_SYNTAX.put("jndi.syntax.ignorecase", "false");
056:                COMPOUND_NAME_SYNTAX.put("jndi.syntax.escape", "\\");
057:                COMPOUND_NAME_SYNTAX.put("jndi.syntax.beginquote", "'");
058:                COMPOUND_NAME_SYNTAX.put("jndi.syntax.trimblanks", "true");
059:                COMPOUND_NAME_SYNTAX.put("jndi.syntax.separator.ava", ",");
060:                COMPOUND_NAME_SYNTAX.put("jndi.syntax.separator.typeval", "=");
061:            }
062:
063:            public static CompoundName getCompoundName(final String name)
064:                    throws InvalidNameException {
065:                return new CompoundName(name, COMPOUND_NAME_SYNTAX);
066:            }
067:
068:            /**
069:             * Return name to use as jndi name.
070:             * Used to do a subset of the ObjectName fields but not just
071:             * let all through so its easy to just use the jndi name to 
072:             * find mbean.
073:             * @param on ObjectName instance to work with.
074:             * @return Returns a compound name to use as jndi key.
075:             * @throws NullPointerException
076:             * @throws InvalidNameException
077:             */
078:            public static CompoundName getCompoundName(final ObjectName on)
079:                    throws NullPointerException, InvalidNameException {
080:                return getCompoundName(on.getCanonicalKeyPropertyListString());
081:            }
082:
083:            /**
084:             * @param on ObjectName instance to work with.
085:             * @return A simple reference based on passed <code>on</code>
086:             */
087:            public static Reference getReference(final ObjectName on) {
088:                Reference r = new Reference(String.class.getName());
089:                Hashtable ht = on.getKeyPropertyList();
090:                r.add(new StringRefAddr(JmxUtils.HOST, (String) ht
091:                        .get(JmxUtils.HOST)));
092:                r.add(new StringRefAddr(JmxUtils.NAME, (String) ht
093:                        .get(JmxUtils.NAME)));
094:                // Put in a value to serve as a unique 'key'.
095:                r.add(new StringRefAddr(JmxUtils.KEY, on
096:                        .getCanonicalKeyPropertyListString()));
097:                return r;
098:            }
099:
100:            /**
101:             * Get subcontext.  Only looks down one level.
102:             * @param subContext Name of subcontext to return.
103:             * @return Sub context.
104:             * @throws NamingException 
105:             */
106:            public static Context getSubContext(final String subContext)
107:                    throws NamingException {
108:                return getSubContext(getCompoundName(subContext));
109:            }
110:
111:            /**
112:             * Get subcontext.  Only looks down one level.
113:             * @param subContext Name of subcontext to return.
114:             * @return Sub context.
115:             * @throws NamingException 
116:             */
117:            public static Context getSubContext(final CompoundName subContext)
118:                    throws NamingException {
119:                Context context = new InitialContext();
120:                try {
121:                    context = (Context) context.lookup(subContext);
122:                } catch (NameNotFoundException e) {
123:                    context = context.createSubcontext(subContext);
124:                }
125:                return context;
126:            }
127:
128:            /**
129:             * 
130:             * @param context A subcontext named for the <code>on.getDomain()</code>
131:             * (Assumption is that caller already setup this subcontext).
132:             * @param on The ObjectName we're to base our bind name on.
133:             * @return Returns key we used binding this ObjectName.
134:             * @throws NamingException
135:             * @throws NullPointerException
136:             */
137:            public static CompoundName bindObjectName(Context context,
138:                    final ObjectName on) throws NamingException,
139:                    NullPointerException {
140:                // I can't call getNameInNamespace in tomcat. Complains about
141:                // unsupported operation -- that I can't get absolute name.
142:                // Therefore just skip this test below -- at least for now.
143:                // Check that passed context has the passed ObjectNames' name.
144:                //
145:                //        String name = getCompoundName(context.getNameInNamespace()).toString();
146:                //        if (!name.equals(on.getDomain())) {
147:                //            throw new NamingException("The current context is " + name +
148:                //                " but domain is " + on.getDomain() + " (Was expecting " +
149:                //                "them to be the same).");
150:                //        }
151:                CompoundName key = getCompoundName(on);
152:                context.rebind(key, getReference(on));
153:                return key;
154:            }
155:
156:            public static CompoundName unbindObjectName(final Context context,
157:                    final ObjectName on) throws NullPointerException,
158:                    NamingException {
159:                CompoundName key = getCompoundName(on);
160:                context.unbind(key);
161:                return key;
162:            }
163:
164:            /**
165:             * Testing code.
166:             * @param args Command line arguments.
167:             * @throws NullPointerException 
168:             * @throws MalformedObjectNameException 
169:             * @throws NamingException 
170:             * @throws InvalidNameException 
171:             */
172:            public static void main(String[] args)
173:                    throws MalformedObjectNameException, NullPointerException,
174:                    InvalidNameException, NamingException {
175:                final ObjectName on = new ObjectName(
176:                        "org.archive.crawler:"
177:                                + "type=Service,name=Heritrix00,host=debord.archive.org");
178:                Context c = getSubContext(getCompoundName(on.getDomain()));
179:                CompoundName key = bindObjectName(c, on);
180:                Reference r = (Reference) c.lookup(key);
181:                for (Enumeration e = r.getAll(); e.hasMoreElements();) {
182:                    System.out.println(e.nextElement());
183:                }
184:                unbindObjectName(c, on);
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.