From: <bri...@us...> - 2003-03-27 00:35:35
|
Update of /cvsroot/webmacro/webmacro/src/org/webmacro/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv13677/src/org/webmacro/servlet Modified Files: Servlet20Broker.java Servlet22Broker.java ServletBroker.java Log Message: Add WM(Properties), WM(Servlet, Properties), constructors and test case Index: Servlet20Broker.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/servlet/Servlet20Broker.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Servlet20Broker.java 11 Jun 2002 17:43:22 -0000 1.4 --- Servlet20Broker.java 27 Mar 2003 00:35:30 -0000 1.5 *************** *** 26,29 **** --- 26,30 ---- import java.io.*; import java.net.URL; + import java.util.*; import javax.servlet.*; *************** *** 45,57 **** protected ClassLoader _servletClassLoader; ! protected Servlet20Broker(ServletContext sc, ! ClassLoader cl) throws InitException { super(sc); _servletClassLoader = cl; ! String propertySource = WEBMACRO_DEFAULTS + ", " + WEBMACRO_PROPERTIES ! + ", " + "(System Properties)"; loadDefaultSettings(); loadSettings(WEBMACRO_PROPERTIES, true); loadSystemSettings(); initLog(_config); --- 46,63 ---- protected ClassLoader _servletClassLoader; ! private Servlet20Broker(ServletContext sc, ! ClassLoader cl, ! Properties additionalProperties) throws InitException { super(sc); _servletClassLoader = cl; ! String propertySource = WEBMACRO_DEFAULTS + ", " + WEBMACRO_PROPERTIES; loadDefaultSettings(); loadSettings(WEBMACRO_PROPERTIES, true); + if (additionalProperties != null && additionalProperties.keySet().size() > 0) { + propertySource += ", (additional Properties)"; + loadSettings(additionalProperties); + } + propertySource += ", (System Properties)"; loadSystemSettings(); initLog(_config); *************** *** 61,72 **** } ! public static Broker getBroker(Servlet s) throws InitException { ServletContext sc = s.getServletConfig().getServletContext(); ClassLoader cl = s.getClass().getClassLoader(); try { ! Broker b = findBroker(cl); if (b == null) { ! b = new Servlet20Broker(sc, cl); ! register(cl, b); } else --- 67,82 ---- } ! public static Broker getBroker(Servlet s, Properties additionalProperties) throws InitException { ServletContext sc = s.getServletConfig().getServletContext(); ClassLoader cl = s.getClass().getClassLoader(); try { ! Object key = cl; ! if (additionalProperties != null && additionalProperties.keySet().size() > 0) ! key = new PropertiesPair(cl, additionalProperties); ! ! Broker b = findBroker(key); if (b == null) { ! b = new Servlet20Broker(sc, cl, additionalProperties); ! register(key, b); } else Index: Servlet22Broker.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/servlet/Servlet22Broker.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Servlet22Broker.java 27 Dec 2002 23:36:37 -0000 1.10 --- Servlet22Broker.java 27 Mar 2003 00:35:30 -0000 1.11 *************** *** 54,59 **** * in the application root. */ ! protected Servlet22Broker(ServletContext sc, ! ClassLoader cl) throws InitException { super(sc); _servletClassLoader = cl; --- 54,60 ---- * in the application root. */ ! private Servlet22Broker(ServletContext sc, ! ClassLoader cl, ! Properties additionalProperties) throws InitException { super(sc); _servletClassLoader = cl; *************** *** 67,72 **** propertySource += ", " + WEBMACRO_PROPERTIES; } ! propertySource += ", (WAR file)" + ", " + "(System Properties)"; loadServletSettings(Broker.SETTINGS_PREFIX); loadSystemSettings(); initLog(_config); --- 68,78 ---- propertySource += ", " + WEBMACRO_PROPERTIES; } ! propertySource += ", (WAR file)"; loadServletSettings(Broker.SETTINGS_PREFIX); + if (additionalProperties != null && additionalProperties.keySet().size() > 0) { + propertySource += ", (additional Properties)"; + loadSettings(additionalProperties); + } + propertySource += ", (System Properties)"; loadSystemSettings(); initLog(_config); *************** *** 104,115 **** ! public static Broker getBroker(Servlet s) throws InitException { ServletContext sc = s.getServletConfig().getServletContext(); ClassLoader cl = s.getClass().getClassLoader(); try { ! Broker b = findBroker(sc); if (b == null) { ! b = new Servlet22Broker(sc, cl); ! register(sc, b); } else --- 110,125 ---- ! public static Broker getBroker(Servlet s, Properties additionalProperties) throws InitException { ServletContext sc = s.getServletConfig().getServletContext(); ClassLoader cl = s.getClass().getClassLoader(); try { ! Object key = sc; ! if (additionalProperties != null && additionalProperties.keySet().size() > 0) ! key = new PropertiesPair(sc, additionalProperties); ! ! Broker b = findBroker(key); if (b == null) { ! b = new Servlet22Broker(sc, cl, additionalProperties); ! register(key, b); } else *************** *** 154,158 **** u = _servletClassLoader.getResource(name); } ! if (u == null) u = super.getResource(name); return u; --- 164,168 ---- u = _servletClassLoader.getResource(name); } ! if (u == null) u = super.getResource(name); return u; Index: ServletBroker.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/servlet/ServletBroker.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ServletBroker.java 11 Jun 2002 17:43:22 -0000 1.5 --- ServletBroker.java 27 Mar 2003 00:35:30 -0000 1.6 *************** *** 32,35 **** --- 32,36 ---- package org.webmacro.servlet; + import java.util.*; import javax.servlet.*; *************** *** 56,60 **** } ! public static Broker getBroker(Servlet s) throws InitException { int minorVersion, majorVersion; --- 57,61 ---- } ! public static Broker getBroker(Servlet s, Properties additionalProperties) throws InitException { int minorVersion, majorVersion; *************** *** 72,84 **** if (majorVersion > 2 || (majorVersion == 2 && minorVersion >= 2)) ! b = Servlet22Broker.getBroker(s); else ! b = Servlet20Broker.getBroker(s); b.startClient(); return b; } public ServletContext getServletContext() { return _servletContext; } } --- 73,118 ---- if (majorVersion > 2 || (majorVersion == 2 && minorVersion >= 2)) ! b = Servlet22Broker.getBroker(s, additionalProperties); else ! b = Servlet20Broker.getBroker(s, additionalProperties); b.startClient(); return b; } + public static Broker getBroker(Servlet s) throws InitException { + return getBroker(s, null); + } + public ServletContext getServletContext() { return _servletContext; + } + + protected static final class PropertiesPair { + private final Object obj; + private final Properties p; + + public PropertiesPair(Object s, Properties p) { + this.obj = s; + this.p = p; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof PropertiesPair)) return false; + + final PropertiesPair servletPropertiesPair = (PropertiesPair) o; + + if (!p.equals(servletPropertiesPair.p)) return false; + if (!obj.equals(servletPropertiesPair.obj)) return false; + + return true; + } + + public int hashCode() { + int result; + result = obj.hashCode(); + result = 29 * result + p.hashCode(); + return result; + } } } |