View Javadoc

1   /*
2    * Copyright 2000-2004 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  
17  package org.apache.jetspeed.om.profile;
18  
19  import org.apache.jetspeed.portal.PortletSet;
20  import org.apache.jetspeed.services.PortalToolkit;
21  import org.apache.jetspeed.services.PsmlManager;
22  
23  /***
24  Provides base functionality within a Registry.
25  
26  @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
27  @version $Id: BaseProfile.java,v 1.19 2004/02/23 03:05:01 jford Exp $
28  */
29  
30  public class BaseProfile  extends BaseProfileLocator implements Profile
31  {
32  
33      protected PSMLDocument document = null;
34  
35      public BaseProfile()
36      {}
37  
38      public BaseProfile(ProfileLocator locator)
39      {
40          init(locator);
41      }
42  
43      public void init(ProfileLocator locator)
44      {
45          this.setAnonymous(locator.getAnonymous());
46          this.setCountry(locator.getCountry());
47          this.setGroup(locator.getGroup());
48          this.setLanguage(locator.getLanguage());
49          this.setMediaType(locator.getMediaType());
50          this.setName(locator.getName());
51          this.setRole(locator.getRole());
52          this.setUser(locator.getUser());        
53      }
54      
55      /***
56       * @see Object#clone
57       * @return an instance copy of this object
58       */
59      public Object clone() throws java.lang.CloneNotSupportedException
60      {
61          Object cloned = super.clone();
62  
63          // clone the document
64          ((BaseProfile)cloned).document = ((this.document == null) ? null : (PSMLDocument) this.document.clone());
65  
66          return cloned;
67      }
68  
69      /***
70         Gets the root set of portlets for this profile object.
71  
72         @return The root portlet set for this profile.
73       */
74      public PortletSet getRootSet()
75      {
76          return PortalToolkit.getSet( getDocument().getPortlets() );
77      }
78  
79      /***
80         Gets the root set of portlets for this profile object.
81  
82         @return The root portlet set for this profile.
83       */
84      public PSMLDocument getDocument()
85      {
86          synchronized (this)
87          {
88              if ((this.document == null) || (this.document.getPortlets() == null))
89              {
90                  this.document = PsmlManager.getDocument(this);
91              }
92          }
93  
94          return this.document;
95      }
96  
97      /*
98       * Sets the psml document attached to this profile
99       *
100      * @param The PSML document for this profile.
101      */
102     public void setDocument(PSMLDocument document)
103     {
104         this.document = document;
105     }
106 
107     /***
108        stores the resource by merging and rewriting the psml file
109 
110        @throws ProfileException if an error occurs storing the profile
111     */
112     public void store() throws ProfileException
113     {
114         if (document != null)
115         {
116             PsmlManager.store(this);
117         }
118     }
119 
120     /***
121      provide useful info for ease of debugging
122     */
123     public String toString()
124     {
125         return "BaseProfile["+ getId() + "]"; /*
126                getUser().getUserName()+","+
127                getGroup().getName()+","+
128                getRole().getName()+","+
129                (getAnonymous() ? "anon,":"")+
130                getMediaType()+","+
131                getCountry()+","+
132                getLanguage()+","+
133                getName()+"]"; */
134     }
135 
136 
137 }