001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.workflow;
021:
022: import java.util.HashMap;
023:
024: import org.apache.log4j.Logger;
025:
026: import de.schlund.pfixxml.Variant;
027: import de.schlund.pfixxml.config.ContextConfig;
028:
029: /**
030: * VariantManager.java
031: *
032: *
033: * Created: Sun Oct 7 13:28:11 2001
034: *
035: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
036: *
037: */
038:
039: public class VariantManager {
040: private ContextConfig contextConfig;
041: private HashMap<String, String> variantpagecache = new HashMap<String, String>();
042: private Logger LOG = Logger.getLogger(this .getClass());
043:
044: public VariantManager(ContextConfig config) {
045: contextConfig = config;
046: }
047:
048: public String getVariantMatchingPageRequestName(String name,
049: Variant variant) {
050: String variant_id = variant.getVariantId();
051: String fullname = (String) variantpagecache.get(variant_id
052: + "@" + name);
053:
054: if (fullname == null) {
055: synchronized (variantpagecache) {
056: fullname = (String) variantpagecache.get(variant_id
057: + "@" + name);
058: if (fullname == null) {
059: // CAT.debug("------ Cache miss " + variant_id + "@" + name);
060: String[] variant_arr = variant
061: .getVariantFallbackArray();
062: for (int i = 0; i < variant_arr.length; i++) {
063: String tmp = name + "::" + variant_arr[i];
064: if (contextConfig.getPageRequestConfig(tmp) != null) {
065: LOG.debug("=== Found PR for '" + tmp
066: + "' ===");
067: fullname = tmp;
068: break;
069: } else {
070: LOG.debug("=== PR NOT FOUND for '" + tmp
071: + "' ===");
072: }
073: }
074: if (fullname == null) {
075: fullname = name;
076: }
077: variantpagecache.put(variant_id + "@" + name,
078: fullname);
079: }
080: } // Yes, DCL doesn't work, but if we hit the race, it doesn't matter here.
081: }
082: return fullname;
083: }
084:
085: public String getVariantMatchingPageFlowName(String name,
086: Variant variant) {
087: LOG.debug("=== Requesting FLOW " + name);
088:
089: if (variant != null
090: && variant.getVariantFallbackArray() != null) {
091: String[] variant_arr = variant.getVariantFallbackArray();
092: for (int i = 0; i < variant_arr.length; i++) {
093: String fullname = name + "::" + variant_arr[i];
094: if (contextConfig.getPageFlowConfig(fullname) != null) {
095: LOG.debug("=== Found FLOW for '" + fullname
096: + "' ===");
097: return fullname;
098: }
099: LOG.debug("=== FLOW NOT FOUND for '" + fullname
100: + "' ===");
101: }
102: }
103: return name;
104: }
105:
106: } // VariantManager (was: PageRequestProperties)
|