1 18 19 package org.objectweb.jac.core; 20 21 import gnu.regexp.RE; 22 import java.util.Collection ; 23 import java.util.Vector ; 24 import org.apache.log4j.Logger; 25 import org.objectweb.jac.util.*; 26 27 34 35 public class NameRepository extends WeakRepository { 36 static Logger logger = Logger.getLogger("repository"); 37 38 42 43 public static Repository get() { 44 if (nameRepository == null) 45 return new NameRepository(); 46 return nameRepository; 47 } 48 49 51 protected static NameRepository nameRepository = null; 52 53 56 57 public NameRepository() { 58 nameRepository = this; 59 register("JAC_name_repository", this); 60 68 register("JAC_ac_manager",ACManager.get()); 69 register("JAC_application_repository", ApplicationRepository.get()); 70 } 71 72 public Object getObject(String logicalName) { 73 if (logicalName == null) 74 return null; 75 Object ret = objects.get(logicalName); 76 if (ret == null) { 77 ((ACManager)ACManager.get()).whenObjectMiss(logicalName); 78 ret = Collaboration.get().getAttribute(BaseProgramListener.FOUND_OBJECT); 79 } 80 logger.debug("getObject("+logicalName+") -> "+ 81 (ret==null?"null":ret.getClass().getName())); 82 return ret; 83 } 84 85 91 public static Collection getObjects(String expr) { 92 NameRepository nr = (NameRepository)get(); 93 String [] names = nr.getNames(); 94 Collection res = new Vector (); 95 RE re; 96 try { 97 re = new RE(expr); 98 } catch (Exception e) { 99 logger.error("Bad regular expression '"+expr+"'",e); 100 return null; 101 } 102 for (int i=0; i<names.length; i++) { 103 String name = names[i]; 104 if (name==null) continue; 105 if (re.isMatch(name)) { 106 res.add(nr.getObject(name)); 107 } 108 } 109 logger.debug("getObjects("+expr+") -> "+res); 110 return res; 111 } 112 113 114 public static Collection getObjects(String [] exprs) { 115 return getObjects(Strings.join(exprs,"|")); 116 } 117 118 public static Collection getObjects(Collection exprs) { 119 return getObjects(Strings.join(exprs,"|")); 120 } 121 } 122 | Popular Tags |