1 /*
2 * Copyright (c) 2003-2005, Henri Yandell, Robert Zigweid
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or
6 * without modification, are permitted provided that the
7 * following conditions are met:
8 *
9 * + Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * + Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * + Neither the name of Simple-JNDI nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*
33 * org.osjava.threads.ThreadNameParser
34 *
35 * $URL: https://osjava.googlecode.com/svn/releases/simple-jndi-0.11.4.1/src/java/org/osjava/sj/jndi/SimpleNameParser.java $
36 * $Id: SimpleNameParser.java 2587 2007-06-25 02:01:53Z flamefew $
37 * $Rev: 2587 $
38 * $Date: 2007-06-24 19:01:53 -0700 (Sun, 24 Jun 2007) $
39 * $Author: flamefew $
40 *
41 * Created on Mar 24, 2004 by Robert M. Zigweid
42 */
43 package org.osjava.sj.jndi;
44
45 import java.util.Properties;
46
47 import javax.naming.CompoundName;
48 import javax.naming.Context;
49 import javax.naming.InvalidNameException;
50 import javax.naming.Name;
51 import javax.naming.NameParser;
52 import javax.naming.NamingException;
53
54 /***
55 * The NameParser for the Simple-JNDI.
56 *
57 * @author Robert M. Zigweid
58 * @version $LastChangedRevision $ $LastChangedDate: 2007-06-24 19:01:53 -0700 (Sun, 24 Jun 2007) $
59 * @since OSJava Threads 2.0
60 */
61 public class SimpleNameParser implements NameParser {
62
63 /*
64 * The parent Context. This is necessary for aquiring relevant data, like
65 * Properties that are used.
66 */
67 private Context parent = null;
68
69 /*
70 * The properties utilized by the SimpleNameParser when constructing new
71 * names.
72 */
73 private Properties props = new Properties();
74
75 /***
76 * Creates a ThreadNameParser. Any relevant information that is needed,
77 * such as the environment that is passed to {@link CompoundName CompundName}
78 * objects that are created.
79 *
80 * @param parent ThreadContext that utilizes the name parser.
81 * @throws NamingException if a naming exception is found.
82 */
83 public SimpleNameParser(Context parent) throws NamingException {
84 this.parent = parent;
85 /* Properties from the parent context are in a HashTable. */
86 props.putAll(this.parent.getEnvironment());
87 }
88
89 /***
90 * Parses a name into its components.<br/>
91 * (Copied from {@link javax.naming.NameParser#parse(java.lang.String)}
92 *
93 * @param name The non-null string name to parse.
94 * @return A non-null parsed form of the name using the naming convention
95 * of this parser.
96 * @throws InvalidNameException If the name does not conform to syntax
97 * defined for the namespace.
98 * @throws NamingException If a naming exception was encountered.
99 */
100 public Name parse(String name)
101 throws InvalidNameException, NamingException {
102 if(name == null) {
103 name = "";
104 }
105 Name ret = new CompoundName(name, props);
106 return ret;
107 }
108
109 /* *
110 * Determine whether or not <code>ob</code> is equal to this object.
111 * If the ob is an instance of ThreadNameParser, it is considered to be
112 * equal.
113 * <br/><br/>
114 * <b>NOTE:</b> The above assumption may actually be false under two
115 * circomstances. Firstly, if the properties utilized by the contexts
116 * are different. Secondly, if the ThreadNameParser is subclassed.
117 *
118 * @param ob the objct which is being compared to this one.
119 * @see java.lang.Object#equals(java.lang.Object)
120 */
121 /* HEN: No hashCode() method, and I'm rather concerned with the
122 implementation of equals below.
123 public boolean equals(Object ob) {
124 if(ob instanceof SimpleNameParser) {
125 return true;
126 }
127 return false;
128 }
129 */
130 }