1 20 package org.enhydra.barracuda.plankton.data; 21 22 import java.util.*; 23 24 28 public class NameSpace { 29 30 protected String name; 31 protected static NameSpace globalNameSpace; 32 protected static long lastTime = 0; 33 34 37 protected NameSpace() { 38 this(null); 39 } 40 41 protected NameSpace(String iname) { 42 if (iname==null) name = "Global"; 43 else name = iname; 44 } 45 46 51 public String getName() { 52 return name; 53 } 54 55 60 public String toString() { 61 return "NameSpace:"+name; 62 } 63 64 69 public synchronized static NameSpace globalInstance() { 70 if (globalNameSpace==null) globalNameSpace = new NameSpace(); 71 return globalNameSpace; 72 } 73 74 79 public synchronized static NameSpace newInstance() { 80 return newInstance("NS"); 81 } 82 83 89 public synchronized static NameSpace newInstance(String key) { 90 long newTime = 0; 91 do {newTime = new java.util.Date ().getTime();} 92 while (newTime<=lastTime); 93 lastTime = newTime; 94 NameSpace ns = new NameSpace(key+"_"+newTime); 95 return ns; 96 } 97 98 99 } | Popular Tags |