001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.xbean.naming.context; 018 019 import javax.naming.Context; 020 import javax.naming.NamingException; 021 import javax.naming.Name; 022 import javax.naming.NamingEnumeration; 023 import javax.naming.NameParser; 024 import javax.naming.NameClassPair; 025 import javax.naming.Binding; 026 027 import java.util.Hashtable; 028 029 /** 030 * @version $Rev$ $Date$ 031 */ 032 public abstract class ContextFlyweight implements Context { 033 protected abstract Context getContext() throws NamingException; 034 035 protected Name getName(Name name) throws NamingException { 036 return name; 037 } 038 039 protected String getName(String name) throws NamingException { 040 return name; 041 } 042 043 public void close() throws NamingException { 044 } 045 046 public String getNameInNamespace() throws NamingException { 047 return getContext().getNameInNamespace(); 048 } 049 050 public Object lookup(Name name) throws NamingException { 051 return getContext().lookup(getName(name)); 052 } 053 054 public Object lookup(String name) throws NamingException { 055 return getContext().lookup(getName(name)); 056 } 057 058 public void bind(Name name, Object obj) throws NamingException { 059 getContext().bind(getName(name), obj); 060 } 061 062 public void bind(String name, Object obj) throws NamingException { 063 getContext().bind(getName(name), obj); 064 } 065 066 public void rebind(Name name, Object obj) throws NamingException { 067 getContext().rebind(getName(name), obj); 068 } 069 070 public void rebind(String name, Object obj) throws NamingException { 071 getContext().rebind(getName(name), obj); 072 } 073 074 public void unbind(Name name) throws NamingException { 075 getContext().unbind(getName(name)); 076 } 077 078 public void unbind(String name) throws NamingException { 079 getContext().unbind(getName(name)); 080 } 081 082 public void rename(Name oldName, Name newName) throws NamingException { 083 getContext().rename(getName(oldName), getName(newName)); 084 } 085 086 public void rename(String oldName, String newName) throws NamingException { 087 getContext().rename(getName(oldName), getName(newName)); 088 } 089 090 public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { 091 return getContext().list(getName(name)); 092 } 093 094 public NamingEnumeration<NameClassPair> list(String name) throws NamingException { 095 return getContext().list(getName(name)); 096 } 097 098 public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { 099 return getContext().listBindings(getName(name)); 100 } 101 102 public NamingEnumeration<Binding> listBindings(String name) throws NamingException { 103 return getContext().listBindings(getName(name)); 104 } 105 106 public void destroySubcontext(Name name) throws NamingException { 107 getContext().destroySubcontext(getName(name)); 108 } 109 110 public void destroySubcontext(String name) throws NamingException { 111 getContext().destroySubcontext(getName(name)); 112 } 113 114 public Context createSubcontext(Name name) throws NamingException { 115 return getContext().createSubcontext(getName(name)); 116 } 117 118 public Context createSubcontext(String name) throws NamingException { 119 return getContext().createSubcontext(getName(name)); 120 } 121 122 public Object lookupLink(Name name) throws NamingException { 123 return getContext().lookupLink(getName(name)); 124 } 125 126 public Object lookupLink(String name) throws NamingException { 127 return getContext().lookupLink(getName(name)); 128 } 129 130 public NameParser getNameParser(Name name) throws NamingException { 131 return getContext().getNameParser(getName(name)); 132 } 133 134 public NameParser getNameParser(String name) throws NamingException { 135 return getContext().getNameParser(getName(name)); 136 } 137 138 public Name composeName(Name name, Name prefix) throws NamingException { 139 return getContext().composeName(name, prefix); 140 } 141 142 public String composeName(String name, String prefix) throws NamingException { 143 return getContext().composeName(name, prefix); 144 } 145 146 public Object addToEnvironment(String propName, Object propVal) throws NamingException { 147 return getContext().addToEnvironment(propName, propVal); 148 } 149 150 public Object removeFromEnvironment(String propName) throws NamingException { 151 return getContext().removeFromEnvironment(propName); 152 } 153 154 public Hashtable getEnvironment() throws NamingException { 155 return getContext().getEnvironment(); 156 } 157 }