001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal;
022:
023: import com.db4o.foundation.*;
024:
025: /**
026: * @exclude
027: */
028: public abstract class Config4Abstract {
029: protected KeySpecHashtable4 _config;
030:
031: private final static KeySpec CASCADE_ON_ACTIVATE = new KeySpec(
032: TernaryBool.UNSPECIFIED);
033:
034: private final static KeySpec CASCADE_ON_DELETE = new KeySpec(
035: TernaryBool.UNSPECIFIED);
036:
037: private final static KeySpec CASCADE_ON_UPDATE = new KeySpec(
038: TernaryBool.UNSPECIFIED);
039:
040: private final static KeySpec NAME = new KeySpec(null);
041:
042: public Config4Abstract() {
043: this (new KeySpecHashtable4(10));
044: }
045:
046: protected Config4Abstract(KeySpecHashtable4 config) {
047: _config = (KeySpecHashtable4) config.deepClone(this );
048: }
049:
050: public void cascadeOnActivate(boolean flag) {
051: putThreeValued(CASCADE_ON_ACTIVATE, flag);
052: }
053:
054: public void cascadeOnDelete(boolean flag) {
055: putThreeValued(CASCADE_ON_DELETE, flag);
056: }
057:
058: public void cascadeOnUpdate(boolean flag) {
059: putThreeValued(CASCADE_ON_UPDATE, flag);
060: }
061:
062: protected void putThreeValued(KeySpec spec, boolean flag) {
063: _config.put(spec, TernaryBool.forBoolean(flag));
064: }
065:
066: protected void putThreeValuedInt(KeySpec spec, boolean flag) {
067: _config.put(spec, flag ? 1 : -1);
068: }
069:
070: public TernaryBool cascadeOnActivate() {
071: return cascade(CASCADE_ON_ACTIVATE);
072: }
073:
074: public TernaryBool cascadeOnDelete() {
075: return cascade(CASCADE_ON_DELETE);
076: }
077:
078: public TernaryBool cascadeOnUpdate() {
079: return cascade(CASCADE_ON_UPDATE);
080: }
081:
082: private TernaryBool cascade(KeySpec spec) {
083: return _config.getAsTernaryBool(spec);
084: }
085:
086: abstract String className();
087:
088: /**
089: * Will raise an exception if argument class doesn't match this class - violates equals() contract in favor of failing fast.
090: */
091: public boolean equals(Object obj) {
092: if (this == obj) {
093: return true;
094: }
095: if (null == obj) {
096: return false;
097: }
098: if (getClass() != obj.getClass()) {
099: Exceptions4.shouldNeverHappen();
100: }
101: return getName().equals(((Config4Abstract) obj).getName());
102: }
103:
104: public int hashCode() {
105: return getName().hashCode();
106: }
107:
108: public String getName() {
109: return _config.getAsString(NAME);
110: }
111:
112: protected void setName(String name) {
113: _config.put(NAME, name);
114: }
115: }
|