/** * @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; }
/** * 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[] 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()]); }
URLRedirect redirect = null; try { redirect = new URLRedirect(incomingTemplate, outgoingTemplate); } catch (RuntimeException e) { throw new IllegalArgumentException("Failed to validate defined redirect templates for prefix ("