001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013:
014: package com.sun.portal.providers.context;
015:
016: import com.sun.portal.log.common.PortalLogger;
017:
018: import java.util.Map;
019: import java.util.HashMap;
020: import java.util.logging.Logger;
021: import java.util.logging.Level;
022:
023: public class PropertiesFilterFactory {
024:
025: public static final String LOCALE_PROPERTIESFILTER_CLASSNAME = "com.sun.portal.providers.context.LocalePropertiesFilter";
026: public static final String CLIENT_PROPERTIESFILTER_CLASSNAME = "com.sun.portal.providers.context.ClientPropertiesFilter";
027: //
028: // CACHING IS DISABLED FOR NOW
029: //
030: //private static Map pfTable = new HashMap();
031: private static Logger logger = PortalLogger
032: .getLogger(PropertiesFilterFactory.class);
033:
034: /**
035: * Get an instance of optional PropertiesFilter. The filter class is
036: * dynamically loaded and initialized with the value specified.
037: * Note that this creates an optional (non-required) filter.
038: *
039: * @param className The class name of the PropertiesFilter object
040: * to be dynamically loaded and instantiated.
041: * @param value The value that gets associated with the filter.
042: * @return an optional PropertiesFilter object that has been initialized
043: * with the value specified.
044: * @exception PropertiesFilterException if there was an error in
045: * instantiating the PropertiesFilter.
046: *
047: * @see PropertiesFilter
048: */
049: public static PropertiesFilter get(String className, String value)
050: throws PropertiesFilterException {
051:
052: return get(className, value, false);
053: }
054:
055: /**
056: * Get an instance of PropertiesFilter. The filter class is dynamically
057: * loaded and initialized with the value and the required flag specified.
058: *
059: * @param className The class name of the PropertiesFilter object
060: * to instantiate.
061: * @param value The value that gets associated with the filter.
062: * @param required Flag indicating whether this filter criteria
063: * is required or optional.
064: * @return a PropertiesFilter object that has been initialized
065: * with the value.
066: * @exception PropertiesFilterException if there was an error in
067: * instantiating the PropertiesFilter.
068: *
069: * @see PropertiesFilter
070: */
071: public static PropertiesFilter get(String className, String value,
072: boolean required) throws PropertiesFilterException {
073:
074: //
075: // CACHING IS DISABLED FOR NOW
076: //
077: //return getCached(className, value, required);
078:
079: PropertiesFilter pf = null;
080:
081: try {
082: pf = (PropertiesFilter) Class.forName(className)
083: .newInstance();
084: } catch (ClassNotFoundException cnfe) {
085: logger.log(Level.WARNING, "PSDT_CSPPCT0003", cnfe);
086: throw new PropertiesFilterException(
087: "PropertiesFilterFactory.getPropertiesFilter(): ",
088: cnfe);
089: } catch (InstantiationException ie) {
090: logger.log(Level.WARNING, "PSDT_CSPPCT0003", ie);
091: throw new PropertiesFilterException(
092: "PropertiesFilterFactory.getPropertiesFilter(): ",
093: ie);
094: } catch (IllegalAccessException iae) {
095: logger.log(Level.WARNING, "PSDT_CSPPCT0003", iae);
096: throw new PropertiesFilterException(
097: "PropertiesFilterFactory.getPropertiesFilter(): ",
098: iae);
099: }
100:
101: pf.init(value, required);
102:
103: return pf;
104: }
105:
106: /**
107: * CACHING iS DISABLED FOR NOW
108: *
109: protected static PropertiesFilter getCached(String className, String value,
110: boolean required)
111: throws PropertiesFilterException {
112:
113: Map perPF = (Map)pfTable.get(className);
114: Map perValue = null;
115: Boolean e = required ? Boolean.TRUE : Boolean.FALSE;
116: PropertiesFilter pf = null;
117: if (perPF != null) {
118: perValue = (Map)perPF.get(value);
119: if (perValue != null) {
120: pf = (PropertiesFilter)perValue.get(e);
121: //com.sun.portal.desktop.context.DesktopContextThreadLocalizer.get().debugError("PropertiesFilterFactory.getPropertiesFilter(): got from cache. pf=" + pf);
122: }
123: }
124:
125: if (pf == null) {
126: try {
127: pf = (PropertiesFilter)Class.forName(className).newInstance();
128: } catch (ClassNotFoundException cnfe) {
129: throw new PropertiesFilterException("PropertiesFilterFactory.getPropertiesFilter(): ", cnfe);
130: } catch (InstantiationException ie) {
131: throw new PropertiesFilterException("PropertiesFilterFactory.getPropertiesFilter(): ", ie);
132: } catch (IllegalAccessException iae) {
133: throw new PropertiesFilterException("PropertiesFilterFactory.getPropertiesFilter(): ", iae);
134: }
135:
136: ((BasePropertiesFilter)pf).init(value, required);
137:
138: if (pf.isCachable()) {
139: if (perPF == null) {
140: perPF = new HashMap();
141: pfTable.put(className, perPF);
142: }
143: if (perValue == null) {
144: perValue = new HashMap();
145: perPF.put(value, perValue);
146: }
147: perValue.put(e, pf);
148:
149: //com.sun.portal.desktop.context.DesktopContextThreadLocalizer.get().debugError("PropertiesFilterFactory.getPropertiesFilter(): putting filter=" + className + ", value=" + value + ", required=" + e + ", cache=" + pfTable);
150: }
151:
152: }
153:
154: return pf;
155: }
156: */
157: }
|