1 23 package com.sun.enterprise.repository; 24 25 import java.util.*; 26 import javax.naming.*; 27 import java.util.logging.*; 29 import com.sun.logging.*; 30 32 35 class Repository { 36 37 private static Logger _logger=null; 39 static{ 40 _logger=LogDomains.getLogger(LogDomains.ROOT_LOGGER); 41 } 42 49 public String find(String name) { 50 try { 51 String value = (String ) ctx.lookup(name); 52 return value; 57 } catch (Exception e) { 58 return null; 63 } 64 } 65 66 71 public boolean add(String name, String value) { 72 try { 73 ctx.rebind(name, value); 74 return true; 80 } catch (NamingException ne) { 81 _logger.log(Level.SEVERE,"enterprise.addinrepository_exception",ne); 84 return false; 86 } 87 } 88 89 public boolean remove(String name){ 90 try { 91 ctx.unbind(name); 92 return true; 98 } catch (NamingException ne) { 99 _logger.log(Level.SEVERE,"enterprise.delinrepository_exception",ne); 102 return false; 104 } 105 } 106 107 public String [] keys() 108 { 109 Vector v = new Vector(10); 110 Enumeration e = null; 111 try { 112 e = ctx.listBindings(""); 113 } catch (NamingException ne) { 114 _logger.log(Level.SEVERE,"enterprise.naming_exception",ne); 117 } 119 120 while((e != null) && e.hasMoreElements()) 121 { 122 Binding b = (Binding) e.nextElement(); 123 v.add(b.getName()); 124 } 125 126 String [] keynames = new String [v.size()]; 127 v.copyInto(keynames); 128 129 return keynames; 130 } 131 132 public String getName() 133 { 134 return RepositoryContext.getRepositoryName(name); 135 } 136 137 140 public Repository(String repositoryName) { 141 Properties env = new Properties(); 142 env.put("java.naming.factory.initial", 143 "com.sun.enterprise.repository.RepositoryInitContextFactory"); 144 env.put("com.sun.enterprise.repository.name", repositoryName); 145 name = repositoryName; 146 init(env); 147 } 148 149 150 153 public Repository(String repositoryName, String repositoryDir) { 154 Properties env = new Properties(); 155 env.put("java.naming.factory.initial", 156 "com.sun.enterprise.repository.RepositoryInitContextFactory"); 157 env.put("com.sun.enterprise.repository.name", repositoryName); 158 env.put("com.sun.enterprise.repository.dir", repositoryDir); 159 name = repositoryName; 160 init(env); 161 } 162 163 164 167 private void init(Properties env) { 168 try { 169 ctx = new InitialContext(env); 170 } catch (NamingException ne) { 171 _logger.log(Level.SEVERE,"enterprise.naming_exception",ne); 174 ctx = null; 176 } 177 } 178 179 180 private Context ctx = null; 181 private String name = null; 182 } 183 | Popular Tags |