KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > wsrp > consumer > UserContextProviderImpl


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.wsrp.consumer;
17
18 import org.apache.avalon.framework.thread.ThreadSafe;
19 import org.apache.wsrp4j.consumer.util.ConsumerConstants;
20 import org.apache.wsrp4j.util.Constants;
21
22 import oasis.names.tc.wsrp.v1.types.Contact;
23 import oasis.names.tc.wsrp.v1.types.EmployerInfo;
24 import oasis.names.tc.wsrp.v1.types.PersonName;
25 import oasis.names.tc.wsrp.v1.types.UserProfile;
26
27 /**
28  * This is the default implementation just returning an empty
29  * user context.<br/>
30  *
31  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
32  * @author <a HREF="mailto:malessandrini@s-und-n.de">Michel Alessandrini</a>
33  *
34  * @version $Id: UserContextProviderImpl.java 264755 2005-08-30 10:29:21Z cziegeler $
35  */

36 public class UserContextProviderImpl implements UserContextProvider, ThreadSafe {
37
38     /**
39      * @see org.apache.cocoon.portal.wsrp.consumer.UserContextProvider#createUserContext(java.lang.String)
40      */

41     public UserContextExtension createUserContext(String JavaDoc userId) {
42         final UserContextExtension userContext = new UserContextExtension();
43
44         userContext.setUserContextKey(userId);
45
46         UserProfile userProfile = new UserProfile();
47         this.fill(userProfile, userContext);
48
49         PersonName personName = new PersonName();
50         this.fill(personName, userContext);
51
52         userProfile.setName(personName);
53         userContext.setProfile(userProfile);
54
55         userContext.setUserAuthentication(ConsumerConstants.PASSWORD);
56         this.setSupportedLocales(userContext);
57         return userContext;
58     }
59     
60     /**
61      * Sets the supportedLocales out of an individual location
62      * This method can be overwritten in sub classes.<br/>
63      *
64      * @param userContext
65      */

66     protected void setSupportedLocales(UserContextExtension userContext) {
67         String JavaDoc[] supportedLocales = new String JavaDoc[2];
68         supportedLocales[0] = Constants.LOCALE_EN_US;
69         supportedLocales[1] = Constants.LOCALE_DE_DE;
70         userContext.setSupportedLocales(supportedLocales);
71     }
72     
73     /**
74      * Fill the user profile.<br/>
75      * This method can be overwritten in sub classes.<br/
76      *
77      * @param profile
78      * @param context
79      */

80     protected void fill(UserProfile profile, UserContextExtension context) {
81         profile.setEmployerInfo(new EmployerInfo());
82         profile.setHomeInfo(new Contact());
83         profile.setBusinessInfo(new Contact());
84     }
85
86     /**
87      * Fill the name.<br/>
88      * This method can be overwritten in sub classes.<br/>
89      *
90      * @param name
91      * @param context
92      */

93     protected void fill(PersonName name, UserContextExtension context) {
94         name.setNickname(context.getUserContextKey());
95     }
96 }
97
Popular Tags