1 15 package org.apache.tapestry.resolver; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.hivemind.ApplicationRuntimeException; 19 import org.apache.hivemind.Location; 20 import org.apache.hivemind.Resource; 21 import org.apache.tapestry.INamespace; 22 import org.apache.tapestry.IRequestCycle; 23 import org.apache.tapestry.spec.IComponentSpecification; 24 25 52 53 public class ComponentSpecificationResolverImpl extends AbstractSpecificationResolver implements 54 ComponentSpecificationResolver 55 { 56 57 private Log _log; 58 59 60 private String _type; 61 62 protected void reset() 63 { 64 _type = null; 65 66 super.reset(); 67 } 68 69 84 85 public void resolve(IRequestCycle cycle, INamespace containerNamespace, String type, 86 Location location) 87 { 88 int colonx = type.indexOf(':'); 89 90 if (colonx > 0) 91 { 92 String libraryId = type.substring(0, colonx); 93 String simpleType = type.substring(colonx + 1); 94 95 resolve(cycle, containerNamespace, libraryId, simpleType, location); 96 } 97 else 98 resolve(cycle, containerNamespace, null, type, location); 99 100 IComponentSpecification spec = getSpecification(); 101 102 if (spec.isDeprecated()) 103 _log.error(ResolverMessages.componentIsDeprecated(type, location)); 104 } 105 106 124 125 public void resolve(IRequestCycle cycle, INamespace containerNamespace, String libraryId, 126 String type, Location location) 127 { 128 reset(); 129 _type = type; 130 131 INamespace namespace = null; 132 133 if (libraryId != null) 134 namespace = containerNamespace.getChildNamespace(libraryId); 135 else 136 namespace = containerNamespace; 137 138 setNamespace(namespace); 139 140 if (namespace.containsComponentType(type)) 141 setSpecification(namespace.getComponentSpecification(type)); 142 else 143 searchForComponent(cycle); 144 145 148 if (getSpecification() == null) 149 { 150 151 throw new ApplicationRuntimeException(ResolverMessages.noSuchComponentType( 152 type, 153 namespace), location, null); 154 155 } 156 } 157 158 160 private void searchForComponent(IRequestCycle cycle) 161 { 162 INamespace namespace = getNamespace(); 163 164 if (_log.isDebugEnabled()) 165 _log.debug(ResolverMessages.resolvingComponent(_type, namespace)); 166 167 String expectedName = _type + ".jwc"; 168 Resource namespaceLocation = namespace.getSpecificationLocation(); 169 170 173 if (found(namespaceLocation.getRelativeResource(expectedName))) 174 return; 175 176 if (namespace.isApplicationNamespace()) 177 { 178 179 181 if (found(getWebInfAppLocation().getRelativeResource(expectedName))) 182 return; 183 184 if (found(getWebInfLocation().getRelativeResource(expectedName))) 185 return; 186 187 if (found(getContextRoot().getRelativeResource(expectedName))) 188 return; 189 } 190 191 194 INamespace framework = getSpecificationSource().getFrameworkNamespace(); 195 196 if (framework.containsComponentType(_type)) 197 { 198 setSpecification(framework.getComponentSpecification(_type)); 199 200 install(); 201 202 return; 203 } 204 205 IComponentSpecification specification = getDelegate().findComponentSpecification( 206 cycle, 207 namespace, 208 _type); 209 210 if (specification != null) 211 { 212 setSpecification(specification); 213 install(); 214 return; 215 } 216 } 217 218 private boolean found(Resource resource) 219 { 220 if (_log.isDebugEnabled()) 221 _log.debug("Checking: " + resource); 222 223 if (resource.getResourceURL() == null) 224 return false; 225 226 setSpecification(getSpecificationSource().getComponentSpecification(resource)); 227 228 install(); 229 230 return true; 231 } 232 233 private void install() 234 { 235 INamespace namespace = getNamespace(); 236 IComponentSpecification specification = getSpecification(); 237 238 if (_log.isDebugEnabled()) 239 _log.debug(ResolverMessages.installingComponent(_type, namespace, specification)); 240 241 namespace.installComponentSpecification(_type, specification); 242 } 243 244 public String getType() 245 { 246 return _type; 247 } 248 249 public void setLog(Log log) 250 { 251 _log = log; 252 } 253 254 } | Popular Tags |