001: /*
002: * Copyright ? 2006 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Sun Microsystems, Inc. has intellectual property rights relating to
005: * technology embodied in the product that is described in this document.
006: * In particular, and without limitation, these intellectual property
007: * rights may include one or more of the U.S. patents listed at
008: * http://www.sun.com/patents and one or more additional patents or
009: * pending patent applications in the U.S. and in other countries.
010: *
011: * U.S. Government Rights - Commercial software. Government users are subject
012: * to the Sun Microsystems, Inc. standard license agreement and applicable
013: * provisions of the FAR and its supplements. Use is subject to license terms.
014: * This distribution may include materials developed by third parties.
015: * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
016: * trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
017: */
018: package com.sun.portal.app.blog.env;
019:
020: import com.sun.portal.app.blog.BlogPortletException;
021: import javax.servlet.ServletContextEvent;
022: import javax.servlet.ServletContextListener;
023: import javax.servlet.http.HttpServletRequest;
024: import javax.portlet.PortletRequest;
025:
026: /**
027: * Abstract base class for search integration.
028: *
029: * Implementations of this class define the implementation of search
030: * for different runtime application environments.
031: */
032: public abstract class AbstractSearch implements Search,
033: ServletContextListener {
034: private static AbstractSearch search = null;
035:
036: private Prefs prefs;
037: private HttpServletRequest httpRequest;
038: private PortletRequest portletRequest;
039:
040: public static AbstractSearch getInstance() {
041: // may be null
042: return search;
043: }
044:
045: public AbstractSearch getNewInstance(Prefs p)
046: throws BlogPortletException {
047: try {
048: AbstractSearch as = (AbstractSearch) this .getClass()
049: .newInstance();
050: as.setPrefs(p);
051:
052: return as;
053: } catch (InstantiationException ie) {
054: throw new BlogPortletException(ie);
055: } catch (IllegalAccessException iae) {
056: throw new BlogPortletException(iae);
057: }
058: }
059:
060: public AbstractSearch getNewInstance() throws BlogPortletException {
061: return getNewInstance(prefs);
062: }
063:
064: public static void setInstance(AbstractSearch search) {
065: AbstractSearch.search = search;
066: AbstractSearch.search.setPrefs(AbstractPrefs.getInstance());
067: }
068:
069: public void contextInitialized(ServletContextEvent event) {
070: setInstance(this );
071: }
072:
073: public void contextDestroyed(ServletContextEvent event) {
074: //nothing
075: }
076:
077: private void setPrefs(Prefs prefs) {
078: this .prefs = prefs;
079: }
080:
081: protected Prefs getPrefs() {
082: return prefs;
083: }
084:
085: public abstract void insert(String id, String title, String content)
086: throws BlogPortletException;
087:
088: public abstract void update(String id, String title, String content)
089: throws BlogPortletException;
090:
091: public abstract void delete(String id) throws BlogPortletException;
092:
093: protected HttpServletRequest getHttpRequest() {
094: return httpRequest;
095: }
096:
097: public void setHttpRequest(HttpServletRequest httpRequest) {
098: this .httpRequest = httpRequest;
099: }
100:
101: protected PortletRequest getPortletRequest() {
102: return portletRequest;
103: }
104:
105: public void setPortletRequest(PortletRequest portletRequest) {
106: this.portletRequest = portletRequest;
107: }
108: }
|