/** * @param redirect * @return a copy of the supplied object */ public static URLRedirect copy(URLRedirect redirect) { if (redirect == null) { throw new IllegalArgumentException("redirect to copy must not be null"); } URLRedirect togo = new URLRedirect(redirect.template, redirect.outgoingTemplate); togo.preProcessedTemplate = redirect.preProcessedTemplate; togo.outgoingPreProcessedTemplate = redirect.outgoingPreProcessedTemplate; togo.methodName = redirect.methodName; togo.methodArgTypes = redirect.methodArgTypes; return togo; }
/** * @return a copy of this object */ public URLRedirect copy() { return copy(this); }
/** * Use this for controllable template matches only * @param template */ public URLRedirect(String template) { setTemplate(template); controllable = true; }
public URLRedirect[] findURLRedirectMethods(EntityProvider entityProvider) { ArrayList<URLRedirect> redirects = new ArrayList<URLRedirect>(); Method[] methods = entityProvider.getClass().getMethods(); for (Method method : methods) { if (method.isAnnotationPresent(EntityURLRedirect.class)) { EntityURLRedirect eurAnnote = method.getAnnotation(EntityURLRedirect.class); String template = eurAnnote.value(); if (null == template || "".equals(template)) { throw new IllegalArgumentException("there is no template set for the annotation: " + EntityURLRedirect.class); } URLRedirect redirect = null; try { redirect = new URLRedirect(template, method.getName(), validateRedirectParamTypes(method.getParameterTypes(), method.getName())); } catch (RuntimeException e) { throw new IllegalArgumentException("Failed to validate redirect templates from methods for prefix (" +entityProvider.getEntityPrefix() + "): " + e.getMessage(), e); } redirect.setMethod(method); // cache to reduce lookup cost redirects.add(redirect); } } Collections.sort(redirects); return redirects.toArray(new URLRedirect[redirects.size()]); }
/** * Execute this validate and get the templates so they can be registered * @param configControllable the entity provider * @return the array of URL redirects */ public static URLRedirect[] validateControllableTemplates(RedirectControllable configControllable) { List<URLRedirect> redirects = new ArrayList<URLRedirect>(); String[] templates = configControllable.defineHandledTemplatePatterns(); if (templates == null || templates.length == 0) { throw new IllegalArgumentException("RedirectControllable: invalid defineHandledTemplatePatterns: " + "this should return a non-empty array of templates or the capability should not be used"); } else { for (String template : templates) { URLRedirect redirect = null; try { redirect = new URLRedirect(template); } catch (RuntimeException e) { throw new IllegalArgumentException("Failed to validate redirect templates from handled template patterns for prefix (" +configControllable.getEntityPrefix() + "): " + e.getMessage(), e); } redirects.add(redirect); } } return redirects.toArray(new URLRedirect[redirects.size()]); }
public URLRedirect(String template, String methodName, Class<?>[] methodArgTypes) { setTemplate(template); if (methodName == null || "".equals(methodName)) { throw new IllegalArgumentException("URLRedirect construction failed: methodName must not be null or empty string"); } if (methodArgTypes == null) { throw new IllegalArgumentException("URLRedirect construction failed: methodArgTypes must not be null"); } this.methodName = methodName; this.methodArgTypes = methodArgTypes; }
URLRedirect redirect = null; try { redirect = new URLRedirect(incomingTemplate, outgoingTemplate); } catch (RuntimeException e) { throw new IllegalArgumentException("Failed to validate defined redirect templates for prefix ("
public URLRedirect(String template, String outgoingTemplate) { setTemplate(template); if (outgoingTemplate == null || "".equals(outgoingTemplate)) { throw new IllegalArgumentException("URLRedirect construction failed: outgoingTemplate must not be null or empty string"); } this.outgoingPreProcessedTemplate = TemplateParseUtil.preprocessTemplate( new TemplateParseUtil.Template(null, outgoingTemplate, false) ); this.outgoingTemplate = this.outgoingPreProcessedTemplate.template; }