001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.naming.factory;
023:
024: import java.util.HashMap;
025: import java.util.Hashtable;
026:
027: import javax.naming.Context;
028: import javax.naming.Name;
029: import javax.naming.NameNotFoundException;
030: import javax.naming.NameParser;
031: import javax.naming.NamingEnumeration;
032: import javax.naming.NamingException;
033:
034: /**
035: * @author Scott.Stark@jboss.org
036: * @version $Revision:$
037: */
038: public class MockNamingContext implements Context {
039: private Hashtable env;
040: private HashMap bindings = new HashMap();
041:
042: MockNamingContext(Hashtable env) {
043: this .env = env;
044: }
045:
046: public Object addToEnvironment(String name, Object value)
047: throws NamingException {
048: return env.put(name, value);
049: }
050:
051: public void bind(Name name, Object obj) throws NamingException {
052: throw new NamingException("Unsupported op");
053: }
054:
055: public void bind(String name, Object obj) throws NamingException {
056: bindings.put(name, obj);
057: }
058:
059: public void close() throws NamingException {
060: }
061:
062: public Name composeName(Name name, Name prefix)
063: throws NamingException {
064: throw new NamingException("Unsupported op");
065: }
066:
067: public String composeName(String name, String prefix)
068: throws NamingException {
069: throw new NamingException("Unsupported op");
070: }
071:
072: public Context createSubcontext(Name name) throws NamingException {
073: throw new NamingException("Unsupported op");
074: }
075:
076: public Context createSubcontext(String name) throws NamingException {
077: throw new NamingException("Unsupported op");
078: }
079:
080: public void destroySubcontext(Name name) throws NamingException {
081: throw new NamingException("Unsupported op");
082: }
083:
084: public void destroySubcontext(String name) throws NamingException {
085: throw new NamingException("Unsupported op");
086: }
087:
088: public Hashtable getEnvironment() throws NamingException {
089: return env;
090: }
091:
092: public String getNameInNamespace() throws NamingException {
093: throw new NamingException("Unsupported op");
094: }
095:
096: public NameParser getNameParser(Name name) throws NamingException {
097: // TODO Auto-generated method stub
098: return null;
099: }
100:
101: public NameParser getNameParser(String name) throws NamingException {
102: throw new NamingException("Unsupported op");
103: }
104:
105: public NamingEnumeration list(Name name) throws NamingException {
106: throw new NamingException("Unsupported op");
107: }
108:
109: public NamingEnumeration list(String name) throws NamingException {
110: return new MockNamingEnumeration(bindings.values().iterator());
111: }
112:
113: public NamingEnumeration listBindings(Name name)
114: throws NamingException {
115: throw new NamingException("Unsupported op");
116: }
117:
118: public NamingEnumeration listBindings(String name)
119: throws NamingException {
120: throw new NamingException("Unsupported op");
121: }
122:
123: public Object lookup(Name name) throws NamingException {
124: throw new NamingException("Unsupported op");
125: }
126:
127: public Object lookup(String name) throws NamingException {
128: Object value = bindings.get(name);
129: if (value == null)
130: throw new NameNotFoundException(name);
131: return value;
132: }
133:
134: public Object lookupLink(Name name) throws NamingException {
135: throw new NamingException("Unsupported op");
136: }
137:
138: public Object lookupLink(String name) throws NamingException {
139: throw new NamingException("Unsupported op");
140: }
141:
142: public void rebind(Name name, Object obj) throws NamingException {
143: throw new NamingException("Unsupported op");
144: }
145:
146: public void rebind(String name, Object obj) throws NamingException {
147: bindings.put(name, obj);
148: }
149:
150: public Object removeFromEnvironment(String name)
151: throws NamingException {
152: return env.remove(name);
153: }
154:
155: public void rename(Name oldName, Name newName)
156: throws NamingException {
157: throw new NamingException("Unsupported op");
158: }
159:
160: public void rename(String oldName, String newName)
161: throws NamingException {
162: Object value = bindings.remove(oldName);
163: if (value == null)
164: throw new NameNotFoundException(oldName);
165: bindings.put(newName, value);
166: }
167:
168: public void unbind(Name name) throws NamingException {
169: throw new NamingException("Unsupported op");
170: }
171:
172: public void unbind(String name) throws NamingException {
173: if (bindings.containsKey(name) == false)
174: throw new NameNotFoundException(name);
175: bindings.remove(name);
176: }
177:
178: }
|