001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/search/tags/sakai_2-4-1/search-tool/tool/src/java/org/sakaiproject/search/tool/SearchBeanFactoryImpl.java $
003: * $Id: SearchBeanFactoryImpl.java 22723 2007-03-16 01:35:32Z ian@caret.cam.ac.uk $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.search.tool;
021:
022: import javax.servlet.ServletContext;
023: import javax.servlet.http.HttpServletRequest;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.sakaiproject.component.api.ComponentManager;
028: import org.sakaiproject.exception.IdUnusedException;
029: import org.sakaiproject.exception.PermissionException;
030: import org.sakaiproject.search.api.SearchService;
031: import org.sakaiproject.search.tool.api.OpenSearchBean;
032: import org.sakaiproject.search.tool.api.SearchAdminBean;
033: import org.sakaiproject.search.tool.api.SearchBean;
034: import org.sakaiproject.search.tool.api.SearchBeanFactory;
035: import org.sakaiproject.search.tool.api.SherlockSearchBean;
036: import org.sakaiproject.site.api.SiteService;
037: import org.sakaiproject.tool.api.SessionManager;
038: import org.sakaiproject.tool.api.ToolManager;
039:
040: /**
041: * @author ieb
042: */
043: public class SearchBeanFactoryImpl implements SearchBeanFactory {
044:
045: private static Log log = LogFactory
046: .getLog(SearchBeanFactoryImpl.class);
047:
048: private SearchService searchService;
049:
050: private SiteService siteService;
051:
052: private ToolManager toolManager;
053:
054: private SessionManager sessionManager;
055:
056: private ServletContext context;
057:
058: public void init() {
059: ComponentManager cm = org.sakaiproject.component.cover.ComponentManager
060: .getInstance();
061: sessionManager = (SessionManager) load(cm, SessionManager.class
062: .getName());
063: searchService = (SearchService) load(cm, SearchService.class
064: .getName());
065: siteService = (SiteService) load(cm, SiteService.class
066: .getName());
067: toolManager = (ToolManager) load(cm, ToolManager.class
068: .getName());
069: }
070:
071: private Object load(ComponentManager cm, String name) {
072: Object o = cm.get(name);
073: if (o == null) {
074: log.error("Cant find Spring component named " + name);
075: }
076: return o;
077: }
078:
079: /**
080: * {@inheritDoc}
081: *
082: * @throws PermissionException
083: */
084: public SearchBean newSearchBean(HttpServletRequest request) {
085: try {
086: SearchBeanImpl searchBean = new SearchBeanImpl(request,
087: searchService, siteService, toolManager);
088:
089: return searchBean;
090: } catch (IdUnusedException e) {
091: throw new RuntimeException(Messages
092: .getString("searchbeanfact_siteerror"));
093: }
094: }
095:
096: /**
097: * {@inheritDoc}
098: *
099: * @throws PermissionException
100: */
101: public SearchAdminBean newSearchAdminBean(HttpServletRequest request)
102: throws PermissionException {
103: try {
104: SearchAdminBeanImpl searchAdminBean = new SearchAdminBeanImpl(
105: request, searchService, siteService, toolManager,
106: sessionManager);
107: return searchAdminBean;
108: } catch (IdUnusedException e) {
109: throw new RuntimeException(Messages
110: .getString("searchbeanfact_siteerror"));
111: }
112: }
113:
114: public SearchBean newSearchBean(HttpServletRequest request,
115: String sortName, String filterName)
116: throws PermissionException {
117: try {
118: SearchBeanImpl searchBean = new SearchBeanImpl(request,
119: sortName, filterName, searchService, siteService,
120: toolManager);
121:
122: return searchBean;
123: } catch (IdUnusedException e) {
124: throw new RuntimeException(Messages
125: .getString("searchbeanfact_siteerror"));
126: }
127: }
128:
129: public OpenSearchBean newOpenSearchBean(HttpServletRequest request)
130: throws PermissionException {
131: try {
132: OpenSearchBean openSearchBean = new OpenSearchBeanImpl(
133: request, searchService, siteService, toolManager);
134:
135: return openSearchBean;
136: } catch (IdUnusedException e) {
137: throw new RuntimeException(Messages
138: .getString("searchbeanfact_siteerror"));
139: }
140: }
141:
142: public SherlockSearchBean newSherlockSearchBean(
143: HttpServletRequest request) throws PermissionException {
144: try {
145: SherlockSearchBean sherlockSearchBean = new SherlockSearchBeanImpl(
146: request, context, searchService, siteService,
147: toolManager);
148:
149: return sherlockSearchBean;
150: } catch (IdUnusedException e) {
151: throw new RuntimeException(Messages
152: .getString("searchbeanfact_siteerror"));
153: }
154: }
155:
156: /**
157: * @return the context
158: */
159: public ServletContext getContext() {
160: return context;
161: }
162:
163: /**
164: * @param context the context to set
165: */
166: public void setContext(ServletContext context) {
167: this.context = context;
168: }
169:
170: }
|