1 28 package net.sf.jguard.ext.database; 29 30 import java.util.Hashtable ; 31 import java.util.Map ; 32 33 import javax.naming.Context ; 34 import javax.naming.Name ; 35 import javax.naming.NameParser ; 36 import javax.naming.NamingEnumeration ; 37 import javax.naming.NamingException ; 38 import javax.sql.DataSource ; 39 40 import net.sf.jguard.ext.database.ConnectionFactory; 41 42 public class MockContext implements Context { 43 44 private static ConnectionFactory connFactory = null; 45 private static DataSource mockDataSource = null; 46 47 public MockContext(){ 48 System.out.println("mockContext"); 49 } 50 51 public MockContext(Hashtable env){ 52 System.out.println("mockContext(env)"); 53 if(connFactory==null){ 54 Map options = DatabaseTestCase.getOptions(); 55 options.remove("JNDI"); 56 DatabaseTestCase.setOptions(options); 57 connFactory = DatabaseTestCase.getConnectionFactory(); 58 mockDataSource = new MockdataSource(connFactory); 59 } 60 } 61 62 public Object lookup(Name name) throws NamingException { 63 return connFactory.getConnection(); 64 } 65 66 public Object lookup(String name) throws NamingException { 67 return mockDataSource; 68 } 69 70 public void bind(Name name, Object obj) throws NamingException { 71 System.out.println("into bind method(Name name, Object obj) "); 72 73 } 74 75 public void bind(String name, Object obj) throws NamingException { 76 System.out.println("into bind(String name, Object obj)"); 77 78 } 79 80 public void rebind(Name name, Object obj) throws NamingException { 81 System.out.println(" into rebind(Name name, Object obj)"); 82 83 } 84 85 public void rebind(String name, Object obj) throws NamingException { 86 System.out.println("into rebind(String name, Object obj) "); 87 88 } 89 90 public void unbind(Name name) throws NamingException { 91 System.out.println("into unbind(Name name)"); 92 93 } 94 95 public void unbind(String name) throws NamingException { 96 System.out.println("into unbind(String name)"); 97 98 } 99 100 public void rename(Name oldName, Name newName) throws NamingException { 101 System.out.println("into rename(Name oldName, Name newName)"); 102 103 } 104 105 public void rename(String oldName, String newName) throws NamingException { 106 System.out.println("into rename(String oldName, String newName)"); 107 108 } 109 110 public NamingEnumeration list(Name name) throws NamingException { 111 System.out.println("into NamingEnumeration list(Name name)"); 112 return null; 113 } 114 115 public NamingEnumeration list(String name) throws NamingException { 116 System.out.println("into list(String name) "); 117 return null; 118 } 119 120 public NamingEnumeration listBindings(Name name) throws NamingException { 121 System.out.println("into listBindings(Name name)"); 122 return null; 123 } 124 125 public NamingEnumeration listBindings(String name) throws NamingException { 126 System.out.println("listBindings"); 127 return null; 128 } 129 130 public void destroySubcontext(Name name) throws NamingException { 131 System.out.println("destroySubcontext"); 132 133 } 134 135 public void destroySubcontext(String name) throws NamingException { 136 System.out.println("destroySubcontext"); 137 138 } 139 140 public Context createSubcontext(Name name) throws NamingException { 141 System.out.println("createSubcontext"); 142 return null; 143 } 144 145 public Context createSubcontext(String name) throws NamingException { 146 System.out.println("createSubcontext"); 147 return null; 148 } 149 150 public Object lookupLink(Name name) throws NamingException { 151 return null; 152 } 153 154 public Object lookupLink(String name) throws NamingException { 155 return null; 156 } 157 158 public NameParser getNameParser(Name name) throws NamingException { 159 System.out.println("getNameParser"); 160 return null; 161 } 162 163 public NameParser getNameParser(String name) throws NamingException { 164 System.out.println("getNameParser2"); 165 return null; 166 } 167 168 public Name composeName(Name name, Name prefix) throws NamingException { 169 System.out.println("composeName"); 170 return null; 171 } 172 173 public String composeName(String name, String prefix) 174 throws NamingException { 175 System.out.println("composeName"); 176 return null; 177 } 178 179 public Object addToEnvironment(String propName, Object propVal) 180 throws NamingException { 181 System.out.println("addToEnvironment"); 182 return null; 183 } 184 185 public Object removeFromEnvironment(String propName) throws NamingException { 186 System.out.println("removeFromEnvironment"); 187 return null; 188 } 189 190 public Hashtable getEnvironment() throws NamingException { 191 System.out.println("getEnvironment"); 192 return null; 193 } 194 195 public void close() throws NamingException { 196 System.out.println("close"); 197 198 } 199 200 public String getNameInNamespace() throws NamingException { 201 System.out.println("getNameInNamespace"); 202 return null; 203 } 204 205 } 206 | Popular Tags |