View Javadoc

1   /**
2    * Copyright 2007 Björn Voß
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * 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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package net.sf.oxclient.service;
17  
18  import java.util.List;
19  import java.util.Map;
20  
21  import net.sf.oval.constraint.NotNull;
22  import net.sf.oval.guard.Guarded;
23  import net.sf.oxclient.ICommunicationManager;
24  import net.sf.oxclient.IFolderModule;
25  import net.sf.oxclient.IGroupwareModule;
26  import net.sf.oxclient.IGroupwareSession;
27  import net.sf.oxclient.IQuery;
28  import net.sf.oxclient.IUser;
29  
30  import org.springframework.beans.factory.annotation.Required;
31  
32  /**
33   * @author Björn Voß
34   *
35   */
36  @Guarded
37  public abstract class AbsGroupwareSession<FolderBean> implements IGroupwareSession<FolderBean> {
38  
39  	private ICommunicationManager communicationManager = null;
40  
41  	private String sessionId = null;
42  
43  	private Map<String, AbsGroupwareModule<?, FolderBean>> moduleMap = null;
44  
45  	/**
46  	 * @param moduleMap the moduleMap to set
47  	 */
48  	@Required
49  	public void setModuleMap(
50  			@NotNull final Map<String, AbsGroupwareModule<?, FolderBean>> moduleMap) {
51  		this.moduleMap = moduleMap;
52  	}
53  
54  	/**
55  	 * @return the communicationManager
56  	 */
57  	public ICommunicationManager getCommunicationManager() {
58  		return this.communicationManager;
59  	}
60  
61  	/**
62  	 * @param communicationManager the communicationManager to set
63  	 */
64  	@Required
65  	public void setCommunicationManager(@NotNull final ICommunicationManager communicationManager) {
66  		this.communicationManager = communicationManager;
67  	}
68  
69  	/* (non-Javadoc)
70  	 * @see net.sf.oxclient.IGroupwareSession#createQuery(java.lang.String)
71  	 */
72  	public IQuery createQuery(@NotNull final String module) {
73  		return this.communicationManager.createQuery(module);
74  	}
75  
76  	/* (non-Javadoc)
77  	 * @see net.sf.oxclient.IGroupwareSession#getModule(java.lang.String)
78  	 */
79  	public IGroupwareModule<?, FolderBean> getModule(@NotNull final String modulename) {
80  		final IGroupwareModule<?, FolderBean> result = this.moduleMap.get(modulename);
81  		if (result == null) {
82  			throw new IllegalArgumentException("unknowen module '" + modulename + "'");
83  		}
84  		return result;
85  	}
86  
87  	/* (non-Javadoc)
88  	 * @see net.sf.oxclient.IGroupwareSession#getRootFolders()
89  	 */
90  	@SuppressWarnings("unchecked")
91  	public List<FolderBean> getRootFolders() {
92  		final IFolderModule<FolderBean> folderModule =
93  			(IFolderModule<FolderBean>) getModule("folder");
94  		return folderModule.getRootFolders();
95  	}
96  
97  	/* (non-Javadoc)
98  	 * @see net.sf.oxclient.IGroupwareSession#getSessionId()
99  	 */
100 	public String getSessionId() {
101 		return this.sessionId;
102 	}
103 
104 	/**
105 	 * will only called at creation time by the corresponding
106 	 * <code>GroupwareService</code>
107 	 *
108 	 * @param sessionId the sessionId to set
109 	 */
110 	public void setSessionId(final String sessionId) {
111 		this.sessionId = sessionId;
112 	}
113 
114 	/* (non-Javadoc)
115 	 * @see net.sf.oxclient.IGroupwareSession#getUser()
116 	 */
117 	public IUser getUser() {
118 		return this.communicationManager.getUser();
119 	}
120 
121 }