KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > Config4Abstract


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o;
22
23 import com.db4o.foundation.KeySpec;
24 import com.db4o.foundation.KeySpecHashtable4;
25
26 /**
27  * @exclude
28  */

29 public abstract class Config4Abstract {
30     protected KeySpecHashtable4 _config;
31
32     private final static KeySpec CASCADE_ON_ACTIVATE=new KeySpec(YapConst.DEFAULT);
33     
34     private final static KeySpec CASCADE_ON_DELETE=new KeySpec(YapConst.DEFAULT);
35     
36     private final static KeySpec CASCADE_ON_UPDATE=new KeySpec(YapConst.DEFAULT);
37
38     private final static KeySpec NAME=new KeySpec(null);
39
40     public Config4Abstract() {
41         this(new KeySpecHashtable4(10));
42     }
43     
44     protected Config4Abstract(KeySpecHashtable4 config) {
45         _config=(KeySpecHashtable4)config.deepClone(this);
46     }
47     
48     public void cascadeOnActivate(boolean flag){
49         putThreeValued(CASCADE_ON_ACTIVATE,flag);
50     }
51     
52     public void cascadeOnDelete(boolean flag){
53         putThreeValued(CASCADE_ON_DELETE,flag);
54     }
55     
56     public void cascadeOnUpdate(boolean flag){
57         putThreeValued(CASCADE_ON_UPDATE,flag);
58     }
59
60     protected void putThreeValued(KeySpec spec,boolean flag) {
61         _config.put(spec, flag ? YapConst.YES : YapConst.NO);
62     }
63     
64     public int cascadeOnActivate(){
65         return cascade(CASCADE_ON_ACTIVATE);
66     }
67     
68     public int cascadeOnDelete(){
69         return cascade(CASCADE_ON_DELETE);
70     }
71     
72     public int cascadeOnUpdate(){
73         return cascade(CASCADE_ON_UPDATE);
74     }
75
76     private int cascade(KeySpec spec) {
77         return _config.getAsInt(spec);
78     }
79     
80     abstract String JavaDoc className();
81     
82     public boolean equals(Object JavaDoc obj){
83         return getName().equals(((Config4Abstract)obj).getName());
84     }
85
86     public String JavaDoc getName(){
87         return _config.getAsString(NAME);
88     }
89     
90     protected void setName(String JavaDoc name) {
91         _config.put(NAME,name);
92     }
93 }
94
Popular Tags