KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > samples > photos > CompUserAC


1 /*
2   Copyright (C) 2003 Renaud Pawlak
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   General Public License for more details.
13
14   You should have received a copy of the GNU 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
17   USA */

18
19 package org.objectweb.jac.samples.photos;
20
21 import org.objectweb.jac.util.Log;
22 import org.objectweb.jac.core.CompositeAspectComponent;
23 import org.objectweb.jac.core.rtti.ClassItem;
24 import org.objectweb.jac.core.rtti.ClassRepository;
25 import org.objectweb.jac.core.rtti.MethodItem;
26 import org.objectweb.jac.aspects.authentication.AuthenticationAC;
27 import org.objectweb.jac.aspects.user.UserAC;
28
29 /**
30  * This aspect is an example on how to use the composite aspects of JAC.
31  *
32  * <p>A composite aspect is a kind of facade that factorizes and
33  * simplifies the use of a set of sub-aspects (called chidren
34  * aspects).
35  *
36  * <p>Here, we give the example of the composition of two core aspects
37  * of the JAC framework: user and authentication. Note that a
38  * composite aspect must extend the class CompositeAspectComponent
39  * that itself extends the AspectComponent class.
40  */

41 public class CompUserAC extends CompositeAspectComponent {
42
43     /**
44      * In the constructor, the composite aspect will declare its
45      * children. */

46     public CompUserAC() {
47         super();
48         // keywords must be declared again even if declared in the
49
// children
50
blockKeywords = new String JavaDoc[] {"profile"};
51         // we compose two aspects (user and authentication)
52
// note that order is important
53
addChild("user",UserAC.class);
54         addChild("authentication",AuthenticationAC.class);
55     }
56
57     boolean authenticator=false;
58
59     void setAuthenticator() {
60         if(!authenticator) {
61             // (declare a default controller which works in 99% of the
62
// cases)
63
((AuthenticationAC)getChild("authentication"))
64                 .setDisplayController(
65                     ClassRepository.get()
66                     .getClass("org.objectweb.jac.aspects.user.UserAC")
67                     .getMethod("userController"));
68             authenticator=true;
69         }
70         
71     }
72
73     /**
74      * This methods groups three dependent configuration methods of
75      * the child aspects. It simplifies the use of the aspects by
76      * allowing only one kind of authentication (the user-class based
77      * one), which is on of the more often used. */

78     public void setUserClass(ClassItem userClass,
79                              String JavaDoc loginField,
80                              String JavaDoc passwordField,
81                              String JavaDoc profileField) {
82         Log.trace("compuser",
83                   "setUserClass("+userClass+","+loginField+","+
84                   passwordField+","+profileField+")");
85         setAuthenticator();
86         // delegate the user class
87
((UserAC)getChild("user")).setUserClass(userClass,
88                                                 loginField,
89                                                 passwordField,
90                                                 profileField);
91        
92         // automatically makes the link with the user aspect (declare a
93
// default authenticator which works in 99% of the cases)
94
((AuthenticationAC)getChild("authentication"))
95             .setAuthenticator
96             (ClassRepository.get()
97              .getClass("org.objectweb.jac.aspects.authentication.UserPasswordAuthenticator"),
98              new String JavaDoc[] { getChildActualName("user") });
99
100     }
101     
102     /** UserAC delegation. */
103     public void autoInitClasses(String JavaDoc classExpr) {
104         Log.trace("compuser",
105                   "autoInitClass("+classExpr+")");
106         ((UserAC)getChild("user")).autoInitClasses(classExpr);
107     }
108
109     /** UserAC delegation. */
110     public void autoInitClasses(ClassItem cl,
111                                 String JavaDoc triggerClassExpr,
112                                 String JavaDoc triggerMethodExpr) {
113         Log.trace("compuser",
114                   "autoInitClass("+cl+","+triggerClassExpr+","+triggerMethodExpr+")");
115         ((UserAC)getChild("user")).autoInitClasses
116             (cl,triggerClassExpr,triggerMethodExpr);
117     }
118     
119     /** UserAC delegation. */
120     public void declareProfile(String JavaDoc name) {
121         Log.trace("compuser",
122                   "declareProfile("+name+")");
123         ((UserAC)getChild("user")).declareProfile(name);
124     }
125
126     /** UserAC delegation. */
127     public void declareProfile(String JavaDoc name,String JavaDoc parent) {
128         Log.trace("compuser",
129                   "declareProfile("+name+","+parent+")");
130         ((UserAC)getChild("user")).declareProfile(name,parent);
131     }
132
133     /** UserAC delegation. */
134     public void addReadable(String JavaDoc profile,String JavaDoc resourceExpr) {
135         Log.trace("compuser",
136                   "addReadable("+profile+","+resourceExpr+")");
137         ((UserAC)getChild("user")).addReadable(profile,resourceExpr);
138     }
139
140     /** UserAC delegation. */
141     public void addUnreadable(String JavaDoc profile,String JavaDoc resourceExpr) {
142         Log.trace("compuser",
143                   "addUnreadable("+profile+","+resourceExpr+")");
144         ((UserAC)getChild("user")).addUnreadable(profile,resourceExpr);
145     }
146
147     /** UserAC delegation. */
148     public void addWritable(String JavaDoc profile,String JavaDoc resourceExpr) {
149         Log.trace("compuser",
150                   "addWritable("+profile+","+resourceExpr+")");
151         ((UserAC)getChild("user")).addWritable(profile,resourceExpr);
152     }
153
154     /** UserAC delegation. */
155     public void addUnwritable(String JavaDoc profile,String JavaDoc resourceExpr) {
156         Log.trace("compuser",
157                   "addUnwritable("+profile+","+resourceExpr+")");
158         ((UserAC)getChild("user")).addUnwritable(profile,resourceExpr);
159     }
160
161     /** UserAC delegation. */
162     public void addRemovable(String JavaDoc profile,String JavaDoc resourceExpr) {
163         Log.trace("compuser",
164                   "addRemovable("+profile+","+resourceExpr+")");
165         ((UserAC)getChild("user")).addRemovable(profile,resourceExpr);
166     }
167
168     /** UserAC delegation. */
169     public void addUnremovable(String JavaDoc profile,String JavaDoc resourceExpr) {
170         Log.trace("compuser",
171                   "addUnremovable("+profile+","+resourceExpr+")");
172         ((UserAC)getChild("user")).addUnremovable(profile,resourceExpr);
173     }
174
175     /** UserAC delegation. */
176     public void addAddable(String JavaDoc profile,String JavaDoc resourceExpr) {
177         Log.trace("compuser",
178                   "addAddable("+profile+","+resourceExpr+")");
179         ((UserAC)getChild("user")).addAddable(profile,resourceExpr);
180     }
181
182     /** UserAC delegation. */
183     public void addCreatable(String JavaDoc profile,String JavaDoc resourceExpr) {
184         Log.trace("compuser",
185                   "addCreatable("+profile+","+resourceExpr+")");
186         ((UserAC)getChild("user")).addCreatable(profile,resourceExpr);
187     }
188
189     /** UserAC delegation. */
190     public void addUnaddable(String JavaDoc profile,String JavaDoc resourceExpr) {
191         Log.trace("compuser",
192                   "addUnaddable("+profile+","+resourceExpr+")");
193         ((UserAC)getChild("user")).addUnaddable(profile,resourceExpr);
194     }
195
196     /** UserAC delegation. */
197     public void defineAdministrator(String JavaDoc login,String JavaDoc password) {
198         Log.trace("compuser",
199                   "defineAdministrator("+login+","+password+")");
200         ((UserAC)getChild("user")).defineAdministrator(login,password);
201     }
202
203     /** AuthenticationAC delegation. */
204     public void setDisplayController(MethodItem controller) {
205         setAuthenticator();
206         Log.trace("compuser",
207                   "setDisplayController("+controller+")");
208         ((AuthenticationAC)getChild("authentication"))
209             .setDisplayController(controller);
210     }
211
212     /** AuthenticationAC delegation. */
213     public void setAccessDeniedMessage(String JavaDoc message) {
214         setAuthenticator();
215         Log.trace("compuser",
216                   "setAccessDeniedMessage("+message+")");
217         ((AuthenticationAC)getChild("authentication"))
218             .setAccessDeniedMessage(message);
219     }
220
221    
222     //public String[] getDefaultConfigs() {
223
// return new String[] {"org/objectweb/jac/aspects/user/user.acc"};
224
//}
225

226 }
227
Popular Tags