KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > rtti > MetaItemDelegate


1 /*
2   Copyright (C) 2001 Renaud Pawlak, Laurent Martelli
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.core.rtti;
19
20 import java.lang.reflect.*;
21
22 /**
23  * This class defines the super class for all the meta items whithin
24  * the rtti aspect.<p>
25  *
26  * A meta item encapsulates a <code>java.lang.reflect</code> item so
27  * that the user of this item can add extra informations
28  * (attributes). Typically this feature can be used by an aspect to
29  * tag an element of the model to react to this tag later on.<p>
30  *
31  * Examples:<p> <ul>
32  *
33  * <li>A persistence aspect can tag some field persistent, add methods
34  * that change the object states even if they do not fit naming
35  * conventions...<p>
36  *
37  * <li>A GUI can tag a given field to be invisible or a class to be
38  * displayed by a special view (eg a given Swing component)...
39  *
40  * </ul>
41  *
42  * @author Renaud Pawlak
43  * @author Laurent Martelli
44  */

45
46 public abstract class MetaItemDelegate extends MetaItem {
47
48     /** Stores the corresponding <code>jav.lang.reflect</code>
49         meta item. */

50     protected Object JavaDoc delegate;
51
52     /** Stores the parent of this meta item */
53     protected MetaItemDelegate parent = null;
54
55     public Object JavaDoc getDelegate() {
56         return delegate;
57     }
58
59     /**
60      * Sets the parent.<p>
61      *
62      * For any type of meta item, the only possible type of the parent
63      * is a class item. For a class item, the parent is
64      * <code>null</code> in most cases (except in the case of
65      * inner-classes).
66      *
67      * @param parent the new parent
68      */

69     public final void setParent(MetaItemDelegate parent)
70         throws InvalidParentException
71     {
72         if ( ! (parent.getClass() == ClassItem.class) ) {
73             throw new InvalidParentException();
74         }
75         this.parent = parent;
76     }
77
78     /**
79      * Gets the parent class item of this meta item.<p>
80      *
81      * @return the parent
82      */

83     public final MetaItemDelegate getParent() {
84         return parent;
85     }
86    
87     /**
88      * Default contructor to create a new meta item object.<p>
89      *
90      * @param delegate the <code>java.lang.reflect</code> actual
91      * meta item
92      */

93     public MetaItemDelegate(Object JavaDoc delegate) throws InvalidDelegateException {
94         if (! (delegate instanceof Member) && ! (delegate instanceof Class JavaDoc)) {
95             throw new InvalidDelegateException(delegate, "must be a Member or a Class");
96         }
97         this.delegate = delegate;
98     }
99
100     public MetaItemDelegate() {
101         delegate = null;
102     }
103
104     /**
105      * Get the modifiers (see java.lang.reflect) of the meta item.
106      *
107      * @return an int representing the modifiers
108      * @see java.lang.reflect.Modifier
109      */

110     public int getModifiers() {
111         return ((Member)delegate).getModifiers();
112     }
113
114     /**
115      * This method gets the type of the meta item by delegating to the
116      * actual <code>java.lang.reflect</code> meta item.<p>
117      *
118      * @return the item type
119      */

120     public abstract Class JavaDoc getType();
121
122     /**
123      * Overloads the default method to call the delegate one.
124      *
125      * @return a textual representation of the object
126      */

127     public String JavaDoc toString() {
128         return getName();
129     }
130
131 }
132
133 class InvalidParentException extends Exception JavaDoc {
134 }
135
136
Popular Tags