001package jmri.server.web.spi; 002 003import java.util.Objects; 004import javax.annotation.CheckForNull; 005import javax.annotation.Nonnull; 006 007/** 008 * 009 * @author Randall Wood (C) 2017 010 */ 011public final class AngularRoute { 012 013 private final String when; 014 private final String template; 015 private final String redirection; 016 private final String controller; 017 018 /** 019 * Create an AngularJS route. 020 * 021 * @param when the trigger for the route 022 * @param template the template loaded for the route; must be non-null if 023 * controller is non-null 024 * @param controller the controller loaded for the route; must be non-null 025 * if template is non-null 026 * @param redirection the path to redirect the route to; must be non-null if 027 * template and controller is null; must be null if 028 * template and controller is non-null 029 * @throws NullPointerException if when is null 030 * @throws IllegalArgumentException if any of the rules concerning when 031 * template, controller, and redirection 032 * must be non-null are violated 033 */ 034 public AngularRoute(@Nonnull String when, @CheckForNull String template, @CheckForNull String controller, @CheckForNull String redirection) { 035 Objects.requireNonNull(when, "Unable to create AngularRoute with null when property."); 036 if ((template == null && controller != null) || (template != null && controller == null)) { 037 throw new IllegalArgumentException("template and controller must both be non-null or null"); 038 } 039 if ((redirection != null && template != null) 040 || (redirection == null && template == null)) { 041 throw new IllegalArgumentException("redirection must be null if template or controller is non-null"); 042 } 043 this.when = when; 044 this.template = template; 045 this.redirection = redirection; 046 this.controller = controller; 047 } 048 049 @CheckForNull 050 public String getRedirection() { 051 return this.redirection; 052 } 053 054 @Nonnull 055 public String getWhen() { 056 return this.when; 057 } 058 059 /** 060 * Get the HTML template for the route. 061 * 062 * @return the template or null 063 */ 064 @CheckForNull 065 public String getTemplate() { 066 return this.template; 067 } 068 069 /** 070 * Get the AngularJS controller for the route. 071 * 072 * @return the controller or null 073 */ 074 @CheckForNull 075 public String getController() { 076 return this.controller; 077 } 078 079}