📄 applicationcontext.java
字号:
/* * Copyright (c) 2005, John Mettraux, OpenWFE.org * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * . Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * . Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * . Neither the name of the "OpenWFE" nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: ApplicationContext.java,v 1.31 2005/07/04 09:07:48 jmettraux Exp $ *///// ApplicationContext.java//// jmettraux@openwfe.org//// generated with // jtmpl 1.0.04 20.11.2001 John Mettraux (jmettraux@openwfe.org)//package openwfe.org;import openwfe.org.state.PausedState;import openwfe.org.state.RunningState;import openwfe.org.state.StoppedState;import openwfe.org.state.ServiceState;/** * Something that keeps track of 1 expression pool and its associated * workflow instance builder * * <p><font size=2>CVS Info : * <br>$Author: jmettraux $ * <br>$Date: 2005/07/04 09:07:48 $ * <br>$Id: ApplicationContext.java,v 1.31 2005/07/04 09:07:48 jmettraux Exp $ </font> * * @author jmettraux@openwfe.org */public class ApplicationContext implements OwfeRunnable{ private final static org.apache.log4j.Logger log = org.apache.log4j.Logger .getLogger(ApplicationContext.class.getName()); // // CONSTANTS & co protected final static String SHARED = "shared"; // identifier for a global scratch application context // (maybe useful for passing stuff inside an application) /** * If a service uses this parameter and gives it a value, this value * should be the name of a ServiceIterator instance. * As of this writing, this system will only be used to order * WorkitemStores. */ public final static String P_SERVICE_ITERATOR = "serviceIterator"; // // global parameters public static final String P_APPLICATION_DIRECTORY = "applicationDirectory"; // // a singleton allowing to retrieve any application context in the JVM public static final java.util.Map contextMap = new java.util.HashMap(); // // FIELDS private ApplicationContext parentContext = null; private String applicationName = null; private java.util.Map map = new java.util.HashMap(); private java.util.Map serviceIterators = new java.util.HashMap(); private ServiceState contextState = new RunningState(); // // CONSTRUCTORS // // METHODS public void setApplicationName (final String s) { this.applicationName = s; } /** * Removes a service or a variable from this context. */ public Object remove (final String key) { return this.map.remove(key); } /** * Adds a service, a sub application context or just a variable to * this application context. */ public void put (final String key, final Object o) { this.map.put(key, o); } /** * Adds a service to this application context. */ public void add (final Service s) { this.put(s.getName(), s); } /** * Feeding a param map into this application context. */ public void putAll (final java.util.Map m) { this.map.putAll(m); } /** * Returns an entry in the application context. * Almost deprecated as of OpenWFE 1.4.2 */ public Object get (final String key) { return lookup(key); } // // lookup() and friends protected ApplicationContext getRootContext () { if (this.parentContext == null) return this; return this.parentContext.getRootContext(); } /** * This method should supplant get() in the middle term, it allows for * lookup among nested application context (a new concept since OpenWFE * 1.4.2). */ public Object lookup (final String key) { //log.debug("lookup() '"+key+"' in '"+getApplicationName()+"'"); if (key == null) return null; final int i = key.indexOf("/"); if (i < 0) return this.map.get(key); if (key.startsWith("./")) return lookup(key.substring(2)); if (key.startsWith("../")) return getParentContext().lookup(key.substring(3)); if (key.startsWith("/")) return getRootContext().lookup(key.substring(1)); final String subContextName = key.substring(0, i); log.debug("lookup() subContextName is '"+subContextName+"'"); final ApplicationContext subContext = (ApplicationContext)this.map.get(subContextName); if (subContext == null) return null; return subContext.lookup(key.substring(i+1)); } // // serviceIterator /* public ServiceIterator serviceIterator (final String serviceIteratorName) { return (ServiceIterator)this.serviceIterators.get(serviceIteratorName); } */ // // various getX methods public long getTime (String key) throws NumberFormatException { return MapUtils.getAsTime(this.map, key); } public long getLong (String key) throws NumberFormatException { return MapUtils.getAsLong(this.map, key); } public long getLong (String key, long defaultValue) { return MapUtils.getAsLong(this.map, key, defaultValue); } public int getInt (String key, int defaultValue) { return MapUtils.getAsInt(this.map, key, defaultValue); } public boolean getBoolean (String key, boolean defaultValue) { return MapUtils.getAsBoolean(this.map, key, defaultValue); } /** * Returns the set of keys found in the context */ public java.util.Set keySet () { return this.map.keySet(); } /** * Returns all the items of a certain class that are bound in this * application context. */ public java.util.List itemsOfClass (final Class theClass) { final java.util.List result = new java.util.ArrayList(this.map.size()); final java.util.Iterator it = this.map.values().iterator(); while (it.hasNext()) { final Object item = it.next(); if (theClass.isAssignableFrom(item.getClass())) result.add(item); } return result; } /** * A shortcut that ensures that the returned value always ends with '/' */ public String getApplicationDirectory () { String applicationDirectory = (String)this.map .get(P_APPLICATION_DIRECTORY); if (applicationDirectory == null) { applicationDirectory = "./"; this.map.put(P_APPLICATION_DIRECTORY, applicationDirectory); } else if ( ! applicationDirectory.endsWith(java.io.File.separator))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -