| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
package org.webmacro.servlet; |
| 33 | |
|
| 34 | |
import org.slf4j.Logger; |
| 35 | |
import org.slf4j.LoggerFactory; |
| 36 | |
import org.webmacro.Broker; |
| 37 | |
import org.webmacro.InitException; |
| 38 | |
|
| 39 | |
import javax.servlet.Servlet; |
| 40 | |
import javax.servlet.ServletContext; |
| 41 | |
import java.util.Map; |
| 42 | |
import java.util.Properties; |
| 43 | |
import java.util.WeakHashMap; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
abstract public class ServletBroker extends Broker |
| 54 | |
{ |
| 55 | |
|
| 56 | |
protected ServletContext _servletContext; |
| 57 | 4 | protected Logger _log = LoggerFactory.getLogger(ServletBroker.class); |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | 2 | private static Map servletContextsWithLogTargets = new WeakHashMap(); |
| 67 | |
|
| 68 | |
protected ServletBroker (ServletContext sc) throws InitException |
| 69 | |
{ |
| 70 | 4 | super((Broker) null, sc.toString()); |
| 71 | 4 | _servletContext = sc; |
| 72 | 4 | } |
| 73 | |
|
| 74 | |
|
| 75 | |
public static Broker getBroker (Servlet s, Properties additionalProperties) |
| 76 | |
throws InitException |
| 77 | |
{ |
| 78 | |
int minorVersion, majorVersion; |
| 79 | |
|
| 80 | 32 | ServletContext sc = s.getServletConfig().getServletContext(); |
| 81 | |
try |
| 82 | |
{ |
| 83 | 32 | majorVersion = sc.getMajorVersion(); |
| 84 | 32 | minorVersion = sc.getMinorVersion(); |
| 85 | |
} |
| 86 | 0 | catch (NoSuchMethodError e) |
| 87 | |
{ |
| 88 | 0 | majorVersion = 2; |
| 89 | 0 | minorVersion = 0; |
| 90 | 32 | } |
| 91 | |
|
| 92 | |
Broker b; |
| 93 | 32 | if (majorVersion > 2 |
| 94 | |
|| (majorVersion == 2 && minorVersion >= 2)) |
| 95 | 22 | b = Servlet22Broker.getBroker(s, additionalProperties); |
| 96 | |
else |
| 97 | 10 | b = Servlet20Broker.getBroker(s, additionalProperties); |
| 98 | 32 | return b; |
| 99 | |
} |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
public static Broker getBroker (ServletContext sc, ClassLoader cl, |
| 113 | |
Properties additionalProperties) throws InitException |
| 114 | |
{ |
| 115 | |
int minorVersion, majorVersion; |
| 116 | |
|
| 117 | |
try |
| 118 | |
{ |
| 119 | 0 | majorVersion = sc.getMajorVersion(); |
| 120 | 0 | minorVersion = sc.getMinorVersion(); |
| 121 | |
} |
| 122 | 0 | catch (NoSuchMethodError e) |
| 123 | |
{ |
| 124 | 0 | majorVersion = 2; |
| 125 | 0 | minorVersion = 0; |
| 126 | 0 | } |
| 127 | |
|
| 128 | |
Broker b; |
| 129 | 0 | if (majorVersion > 2 |
| 130 | |
|| (majorVersion == 2 && minorVersion >= 2)) |
| 131 | 0 | b = Servlet22Broker.getBroker(sc, cl, additionalProperties); |
| 132 | |
else |
| 133 | 0 | b = Servlet20Broker.getBroker(sc, cl, additionalProperties); |
| 134 | 0 | return b; |
| 135 | |
} |
| 136 | |
|
| 137 | |
public static Broker getBroker (Servlet s) throws InitException |
| 138 | |
{ |
| 139 | 32 | return getBroker(s, null); |
| 140 | |
} |
| 141 | |
|
| 142 | |
public ServletContext getServletContext () |
| 143 | |
{ |
| 144 | 2 | return _servletContext; |
| 145 | |
} |
| 146 | |
|
| 147 | |
protected static final class PropertiesPair |
| 148 | |
{ |
| 149 | |
private final Object obj; |
| 150 | |
private final Properties p; |
| 151 | |
|
| 152 | |
public PropertiesPair (Object s, Properties p) |
| 153 | 0 | { |
| 154 | 0 | this.obj = s; |
| 155 | 0 | this.p = p; |
| 156 | 0 | } |
| 157 | |
|
| 158 | |
public boolean equals (Object o) |
| 159 | |
{ |
| 160 | 0 | if (this == o) return true; |
| 161 | 0 | if (!(o instanceof PropertiesPair)) return false; |
| 162 | |
|
| 163 | 0 | final PropertiesPair servletPropertiesPair = (PropertiesPair) o; |
| 164 | |
|
| 165 | 0 | if (!p.equals(servletPropertiesPair.p)) return false; |
| 166 | 0 | if (!obj.equals(servletPropertiesPair.obj)) return false; |
| 167 | |
|
| 168 | 0 | return true; |
| 169 | |
} |
| 170 | |
|
| 171 | |
public int hashCode () |
| 172 | |
{ |
| 173 | |
int result; |
| 174 | 0 | result = obj.hashCode(); |
| 175 | 0 | result = 29 * result + p.hashCode(); |
| 176 | 0 | return result; |
| 177 | |
} |
| 178 | |
} |
| 179 | |
} |