1 23 package com.sun.enterprise.deployment; 24 25 import java.io.*; 26 import java.util.*; 27 import com.sun.enterprise.deployment.web.ServletFilterMapping; 28 29 33 public class ServletFilterMappingDescriptor 34 extends Descriptor 35 implements com.sun.enterprise.deployment.web.ServletFilterMapping 36 { 37 38 public static final String TARGET_TYPE_URLPATTERN = 39 ServletFilterMapping.TARGET_TYPE_URLPATTERN; 40 public static final String TARGET_TYPE_SERVLET = 41 ServletFilterMapping.TARGET_TYPE_SERVLET; 42 43 public static String INCLUDE = ServletFilterMapping.INCLUDE; 44 public static String REQUEST = ServletFilterMapping.REQUEST; 45 public static String FORWARD = ServletFilterMapping.FORWARD; 46 47 private static Set allowed_dispatchers; 48 49 50 private String targetType = TARGET_TYPE_URLPATTERN; 51 52 53 private String target = ""; 54 55 private Set dispatchers; 56 private List<String > servletNames; 57 private List<String > urlPatterns; 58 59 60 public ServletFilterMappingDescriptor() { 61 super("", ""); 62 } 63 64 65 public ServletFilterMappingDescriptor(ServletFilterMappingDescriptor other) { 66 super(other); 67 targetType = other.targetType; 68 target = other.target; 69 dispatchers = (other.dispatchers != null)? new HashSet(other.dispatchers) : null; 70 } 71 72 73 public ServletFilterMappingDescriptor(String dispName, 74 String targetType, String target) { 75 super(dispName, ""); 76 this.setTargetType(targetType); 77 this.setTarget(target); 78 } 79 80 81 public void setTargetType(String type) { 82 if (TARGET_TYPE_SERVLET.equals(type)) { 83 this.targetType = TARGET_TYPE_SERVLET; 84 } else { 85 this.targetType = TARGET_TYPE_URLPATTERN; 86 } 87 } 88 89 90 public String getTargetType() { 91 if (! getServletNames().isEmpty()) { 92 return TARGET_TYPE_SERVLET; 93 } else { 94 return TARGET_TYPE_URLPATTERN; 95 } 96 } 97 98 99 public boolean isURLPatternTarget() { 100 return TARGET_TYPE_URLPATTERN.equals(getTargetType()); 101 } 102 103 104 public boolean isServletNameTarget() { 105 return TARGET_TYPE_SERVLET.equals(getTargetType()); 106 } 107 108 109 public void setTarget(String target) { 110 this.target = target; 111 } 112 113 114 public String getTarget() { 115 if (! getServletNames().isEmpty()) { 116 Iterator i = servletNames.iterator(); 117 return (String ) i.next(); 118 } else { 119 Iterator i = urlPatterns.iterator(); 120 return (String ) i.next(); 121 } 122 } 123 124 public void addServletName(String servletName) { 125 getServletNames().add(servletName); 126 } 127 128 public List<String > getServletNames() { 129 if (servletNames == null) { 130 servletNames = new LinkedList<String >(); 131 } 132 return servletNames; 133 } 134 135 public void addURLPattern(String urlPattern) { 136 getURLPatterns().add(urlPattern); 137 } 138 139 public List<String > getURLPatterns() { 140 if (urlPatterns == null) { 141 urlPatterns = new LinkedList<String >(); 142 } 143 return urlPatterns; 144 } 145 146 public void addDispatcher(String dispatcher) { 147 if (dispatchers == null) { 148 dispatchers = new HashSet(); 149 } 150 dispatchers.add(dispatcher); 151 } 152 153 public void removeDispatcher(String dispatcher) { 154 if (dispatchers == null) { 155 return; 156 } 157 dispatchers.remove(dispatcher); 158 } 159 160 public Set getDispatchers() { 161 if (dispatchers == null) { 162 dispatchers = new HashSet(); 163 } 164 return dispatchers; 165 } 166 167 public static Set getAllowedDispatchers() { 168 if (allowed_dispatchers == null) { 169 allowed_dispatchers = new HashSet(); 170 allowed_dispatchers.add(INCLUDE); 171 allowed_dispatchers.add(REQUEST); 172 allowed_dispatchers.add(FORWARD); 173 } 174 return allowed_dispatchers; 175 } 176 177 178 public boolean equals(Object obj) { 179 if (obj instanceof ServletFilterMapping) { 180 ServletFilterMapping o = (ServletFilterMapping) obj; 181 if ( this.getName().equals(o.getName()) 182 && this.getServletNames().equals(o.getServletNames()) 183 && this.getURLPatterns().equals(o.getURLPatterns()) ) { 184 return true; 185 } 186 } 187 188 return false; 189 } 190 } 191 | Popular Tags |