001: /*
002: * RetrievalFactory.java
003: *
004: * $Author: ss150821 $
005: *
006: * $Date: 2005/11/30 11:27:22 $ $Revision: 1.5 $
007: *
008: * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
009: *
010: * Developed by SunPS and SunIR
011: */
012:
013: package com.sun.portal.rproxy.connectionhandler;
014:
015: import java.util.HashMap;
016: import java.util.Map;
017: import java.util.logging.Level;
018: import java.util.logging.Logger;
019:
020: import com.sun.portal.log.common.PortalLogger;
021:
022: /**
023: * This class manages the mapping of Retrievers and protocols.
024: *
025: * @author Gabriel Lawrence
026: */
027: // JP_Declaration RetrievalFactory 200
028: public class RetrievalFactory {
029: // private static Logger logger =
030: // Logger.getLogger("com.sun.portal.sra.rproxy");
031: private static Logger logger = PortalLogger
032: .getLogger(RetrievalFactory.class);
033:
034: private static Map _retrievers = new HashMap();
035:
036: // JP_Operation "getRetriver(String protocol)" 132
037: public static Retriever getRetriever(String protocol) {
038:
039: String _protocol = protocol.toLowerCase();
040: Retriever result = (Retriever) _retrievers.get(_protocol);
041:
042: if (result != null) {
043: return result;
044: }
045:
046: synchronized (_retrievers) {
047:
048: // double check to be thread-safe
049: result = (Retriever) _retrievers.get(_protocol);
050: if (result != null) {
051: return result;
052: }
053:
054: if (_protocol.equals("http"))
055: result = new HTTPRetriever();
056: else if (_protocol.equals("https"))
057: result = new HTTPSRetriever();
058: else {
059: // logger.severe("RetrievalFactory: can not find protocol " +
060: // _protocol);
061: Object[] params0 = { _protocol };
062: logger.log(Level.SEVERE, "PSSRRPROXY_CSPRCONHNDLR113",
063: params0);
064: return null;
065: }
066:
067: _retrievers.put(_protocol, result);
068: }
069: return result;
070: }
071:
072: // Currently JSS is not supported on the iWS, so the server
073: // components (eg. urlscraper) who want to get a retriever will
074: // need to call this method to get the proper version.
075: // 5/23/2001 huacui
076:
077: public static Retriever getRetriever2(String protocol) {
078:
079: String _protocol = protocol.toLowerCase();
080: Retriever result = (Retriever) _retrievers.get(_protocol);
081:
082: if (result != null) {
083: return result;
084: }
085:
086: synchronized (_retrievers) {
087: // double check to be thread-safe
088: result = (Retriever) _retrievers.get(_protocol);
089: if (result != null) {
090: return result;
091: }
092: if (_protocol.equals("http"))
093: result = new HTTPRetriever();
094: else if (_protocol.equals("https"))
095: result = new SSLHTTPSRetriever();
096: else {
097: // logger.severe("RetrievalFactory: can not find protocol " +
098: // _protocol);
099: Object[] params1 = { _protocol };
100: logger.log(Level.SEVERE, "PSSRRPROXY_CSPRCONHNDLR114",
101: params1);
102: return null;
103: }
104:
105: _retrievers.put(_protocol, result);
106: }
107: return result;
108: }
109: }
|