KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > data > NameSpace


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: NameSpace.java,v 1.2 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.data;
21
22 import java.util.*;
23
24 /**
25  * This class defines a NameSpace entity (like a key) that can be used to
26  * set/retrieve objects from the ObjectRepository
27  */

28 public class NameSpace {
29
30     protected String JavaDoc name;
31     protected static NameSpace globalNameSpace;
32     protected static long lastTime = 0;
33
34     /**
35      * protected no args constructor (use the factory methods)
36      */

37     protected NameSpace() {
38         this(null);
39     }
40
41     protected NameSpace(String JavaDoc iname) {
42         if (iname==null) name = "Global";
43         else name = iname;
44     }
45
46     /**
47      * get the name of this NameSpace
48      *
49      * @return the name of this NameSpace
50      */

51     public String JavaDoc getName() {
52         return name;
53     }
54
55     /**
56      * return the String represenation of the NameSpace
57      *
58      * @return the String represenation of the NameSpace
59      */

60     public String JavaDoc toString() {
61         return "NameSpace:"+name;
62     }
63
64     /**
65      * get the global NameSpace instance
66      *
67      * @return the global NameSpace instance
68      */

69     public synchronized static NameSpace globalInstance() {
70         if (globalNameSpace==null) globalNameSpace = new NameSpace();
71         return globalNameSpace;
72     }
73
74     /**
75      * get a new NameSpace instance using the default name
76      *
77      * @return new NameSpace instance using the default name
78      */

79     public synchronized static NameSpace newInstance() {
80         return newInstance("NS");
81     }
82
83     /**
84      * get a new NameSpace instance using the specified name
85      *
86      * @param key the namespace key
87      * @return the corresponding NameSpace
88      */

89     public synchronized static NameSpace newInstance(String JavaDoc key) {
90         long newTime = 0;
91         do {newTime = new java.util.Date JavaDoc().getTime();}
92         while (newTime<=lastTime);
93         lastTime = newTime;
94         NameSpace ns = new NameSpace(key+"_"+newTime);
95         return ns;
96     }
97
98
99 }
Popular Tags