KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > ref > lib > ReferencableBase


1 /*====================================================================
2
3 ObjectWeb Util Ref Package.
4 Copyright (C) 2004 INRIA & USTL - LIFL - GOAL
5 Contact: architecture@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 --------------------------------------------------------------------
26 $Id: ReferencableBase.java,v 1.1 2004/02/13 17:46:08 rouvoy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.ref.lib;
30
31 import java.util.Vector JavaDoc;
32
33 import org.objectweb.util.ref.api.Referencable;
34
35 /**
36  * Abstract base implementation of Referencable objects.
37  *
38  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
39  * @version 0.1
40  */

41 abstract public class ReferencableBase
42            implements Referencable
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50     /** List of Referencable objects. */
51     private Vector JavaDoc referenced_by_;
52
53     // ==================================================================
54
//
55
// Constructor.
56
//
57
// ==================================================================
58

59     /** The default constructor. */
60     public ReferencableBase() {
61         // Inits internal state.
62
referenced_by_ = new Vector JavaDoc();
63     }
64
65     // ==================================================================
66
//
67
// Internal methods.
68
//
69
// ==================================================================
70

71     // ==================================================================
72
//
73
// Public methods for interface org.objectweb.util.api.Identifiable
74
//
75
// ==================================================================
76

77     /**
78      * Obtains its identity.
79      *
80      * Must be defined in subclasses.
81      *
82      * @return Its identity.
83      */

84     public abstract String JavaDoc getIdentity();
85
86     // ==================================================================
87
//
88
// Public methods for interface org.objectweb.util.ref.api.Referencable
89
//
90
// ==================================================================
91

92     /**
93      * Obtains the reference counter,
94      * i.e. the number of Referencable objects that reference it.
95      *
96      * @return The number of references.
97      */

98     public int getReferencedByCounter() {
99         return referenced_by_.size();
100     }
101
102     /**
103      * Obtains all its added Referencable objects.
104      *
105      * @return All added Referencable objects.
106      */

107     public Referencable[] getReferencedBy() {
108        return (Referencable[])referenced_by_.toArray(new Referencable[0]);
109     }
110
111     /**
112      * Adds a reference.
113      *
114      * @param ref The Referencable object to add.
115      *
116      * @postcondition getReferencedByCounter() == old.getReferencedByCounter() + 1
117      */

118     public void addReferencedBy(Referencable ref) {
119         referenced_by_.addElement(ref);
120     }
121
122     /**
123      * Removes a reference.
124      *
125      * @param ref The Referencable object to remove.
126      *
127      * @postcondition if ref was previously added then
128      * getReferencedByCounter() == old.getReferencedByCounter() - 1
129      */

130     public void removeReferencedBy(Referencable ref) {
131         referenced_by_.removeElement(ref);
132     }
133 }
134
Popular Tags