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.events;
022:
023: import com.db4o.events.*;
024: import com.db4o.internal.*;
025: import com.db4o.internal.callbacks.Callbacks;
026: import com.db4o.query.Query;
027:
028: /**
029: * @exclude
030: */
031: public class EventRegistryImpl implements Callbacks, EventRegistry {
032:
033: private final InternalObjectContainer _container;
034:
035: protected final Event4Impl _queryStarted = new Event4Impl();
036: protected final Event4Impl _queryFinished = new Event4Impl();
037: protected final Event4Impl _creating = new Event4Impl();
038: protected final Event4Impl _activating = new Event4Impl();
039: protected final Event4Impl _updating = new Event4Impl();
040: protected final Event4Impl _deleting = new Event4Impl();
041: protected final Event4Impl _deactivating = new Event4Impl();
042: protected final Event4Impl _created = new Event4Impl();
043: protected final Event4Impl _activated = new Event4Impl();
044: protected final Event4Impl _updated = new Event4Impl();
045: protected final Event4Impl _deleted = new Event4Impl();
046: protected final Event4Impl _deactivated = new Event4Impl();
047: protected final Event4Impl _committing = new Event4Impl();
048: protected final Event4Impl _committed = new CommittedEvent();
049: protected final Event4Impl _instantiated = new Event4Impl();
050: protected final Event4Impl _classRegistered = new Event4Impl();
051:
052: /**
053: * @sharpen.ignore
054: */
055: protected class CommittedEvent extends Event4Impl {
056: protected void onListenerAdded() {
057: onCommittedListener();
058: }
059: }
060:
061: public EventRegistryImpl(InternalObjectContainer container) {
062: _container = container;
063: }
064:
065: // Callbacks implementation
066: public void queryOnFinished(Transaction transaction, Query query) {
067: EventPlatform.triggerQueryEvent(transaction, _queryFinished,
068: query);
069: }
070:
071: public void queryOnStarted(Transaction transaction, Query query) {
072: EventPlatform.triggerQueryEvent(transaction, _queryStarted,
073: query);
074: }
075:
076: public boolean objectCanNew(Transaction transaction, Object obj) {
077: return EventPlatform.triggerCancellableObjectEventArgs(
078: transaction, _creating, obj);
079: }
080:
081: public boolean objectCanActivate(Transaction transaction, Object obj) {
082: return EventPlatform.triggerCancellableObjectEventArgs(
083: transaction, _activating, obj);
084: }
085:
086: public boolean objectCanUpdate(Transaction transaction, Object obj) {
087: return EventPlatform.triggerCancellableObjectEventArgs(
088: transaction, _updating, obj);
089: }
090:
091: public boolean objectCanDelete(Transaction transaction, Object obj) {
092: return EventPlatform.triggerCancellableObjectEventArgs(
093: transaction, _deleting, obj);
094: }
095:
096: public boolean objectCanDeactivate(Transaction transaction,
097: Object obj) {
098: return EventPlatform.triggerCancellableObjectEventArgs(
099: transaction, _deactivating, obj);
100: }
101:
102: public void objectOnActivate(Transaction transaction, Object obj) {
103: EventPlatform.triggerObjectEvent(transaction, _activated, obj);
104: }
105:
106: public void objectOnNew(Transaction transaction, Object obj) {
107: EventPlatform.triggerObjectEvent(transaction, _created, obj);
108: }
109:
110: public void objectOnUpdate(Transaction transaction, Object obj) {
111: EventPlatform.triggerObjectEvent(transaction, _updated, obj);
112: }
113:
114: public void objectOnDelete(Transaction transaction, Object obj) {
115: EventPlatform.triggerObjectEvent(transaction, _deleted, obj);
116: }
117:
118: public void classOnRegistered(ClassMetadata clazz) {
119: EventPlatform.triggerClassEvent(_classRegistered, clazz);
120: }
121:
122: public void objectOnDeactivate(Transaction transaction, Object obj) {
123: EventPlatform
124: .triggerObjectEvent(transaction, _deactivated, obj);
125: }
126:
127: public void objectOnInstantiate(Transaction transaction, Object obj) {
128: EventPlatform.triggerObjectEvent(transaction, _instantiated,
129: obj);
130: }
131:
132: public void commitOnStarted(Transaction transaction,
133: CallbackObjectInfoCollections objectInfoCollections) {
134: EventPlatform.triggerCommitEvent(transaction, _committing,
135: objectInfoCollections);
136: }
137:
138: public void commitOnCompleted(Transaction transaction,
139: CallbackObjectInfoCollections objectInfoCollections) {
140: EventPlatform.triggerCommitEvent(transaction, _committed,
141: objectInfoCollections);
142: }
143:
144: public Event4 queryFinished() {
145: return _queryFinished;
146: }
147:
148: public Event4 queryStarted() {
149: return _queryStarted;
150: }
151:
152: public Event4 creating() {
153: return _creating;
154: }
155:
156: public Event4 activating() {
157: return _activating;
158: }
159:
160: public Event4 updating() {
161: return _updating;
162: }
163:
164: public Event4 deleting() {
165: return _deleting;
166: }
167:
168: public Event4 deactivating() {
169: return _deactivating;
170: }
171:
172: public Event4 created() {
173: return _created;
174: }
175:
176: public Event4 activated() {
177: return _activated;
178: }
179:
180: public Event4 updated() {
181: return _updated;
182: }
183:
184: public Event4 deleted() {
185: return _deleted;
186: }
187:
188: public Event4 deactivated() {
189: return _deactivated;
190: }
191:
192: public Event4 committing() {
193: return _committing;
194: }
195:
196: /**
197: * @sharpen.event.onAdd onCommittedListener
198: */
199: public Event4 committed() {
200: return _committed;
201: }
202:
203: public Event4 classRegistered() {
204: return _classRegistered;
205: }
206:
207: public Event4 instantiated() {
208: return _instantiated;
209: }
210:
211: protected void onCommittedListener() {
212: // TODO: notify the server that we are interested in
213: // committed callbacks
214: _container.onCommittedListener();
215: }
216:
217: public boolean caresAboutCommitting() {
218: return EventPlatform.hasListeners(_committing);
219: }
220:
221: public boolean caresAboutCommitted() {
222: return EventPlatform.hasListeners(_committed);
223: }
224:
225: public boolean caresAboutDeleting() {
226: return EventPlatform.hasListeners(_deleting);
227: }
228:
229: public boolean caresAboutDeleted() {
230: return EventPlatform.hasListeners(_deleted);
231: }
232: }
|