1 /* Copyright (C) 2004 - 2009  Versant Inc.  http://www.db4o.com */
2 
3 using System;
4 using Db4objects.Db4o.Activation;
5 using Db4objects.Db4o.TA;
6 
7 namespace Db4objects.Db4o.Internal.Activation
8 {
9 	public abstract class ActivatableBase : IActivatable
10 	{
11 		[System.NonSerialized]
12 		private IActivator _activator;
13 
Bind(IActivator activator)14 		public virtual void Bind(IActivator activator)
15 		{
16 			if (_activator == activator)
17 			{
18 				return;
19 			}
20 			if (activator != null && _activator != null)
21 			{
22 				throw new InvalidOperationException();
23 			}
24 			_activator = activator;
25 		}
26 
Activate(ActivationPurpose purpose)27 		public virtual void Activate(ActivationPurpose purpose)
28 		{
29 			if (_activator == null)
30 			{
31 				return;
32 			}
33 			_activator.Activate(purpose);
34 		}
35 
ActivateForRead()36 		protected virtual void ActivateForRead()
37 		{
38 			Activate(ActivationPurpose.Read);
39 		}
40 
ActivateForWrite()41 		protected virtual void ActivateForWrite()
42 		{
43 			Activate(ActivationPurpose.Write);
44 		}
45 	}
46 }
47