KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jicengine > operation > AbstractContext


1 package org.jicengine.operation;
2
3
4 /**
5  *
6  * <p>
7  * Copyright (C) 2004 Timo Laitinen
8  * </p>
9  * @author Timo Laitinen
10  * @created 2004-09-20
11  * @since JICE-0.10
12  *
13  */

14
15 public abstract class AbstractContext implements Context {
16
17     String JavaDoc name;
18
19     protected AbstractContext()
20     {
21         name = "unknown";
22     }
23
24     protected AbstractContext(String JavaDoc name)
25     {
26         this.name = name;
27     }
28
29     public String JavaDoc getName()
30     {
31         return this.name;
32     }
33
34     public String JavaDoc toString()
35     {
36         return "{" + getName() + "}";
37     }
38
39     protected static String JavaDoc getName(Context context, String JavaDoc defaultName)
40     {
41         if( context != null && context instanceof AbstractContext ){
42             return ((AbstractContext)context).getName();
43         }
44         else {
45             return defaultName;
46         }
47     }
48
49     public Context replicate()
50     {
51         java.util.Map JavaDoc objects = new java.util.HashMap JavaDoc();
52         copyObjectsTo(objects);
53         return new SimpleContext(getName(), objects);
54     }
55
56     protected abstract void copyObjectsTo(java.util.Map JavaDoc map);
57
58 }
59
Popular Tags