1 /* 2 * Copyright 2009 :torweg free software group 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 */ 18 package org.torweg.pulse.bundle; 19 20 import java.io.Serializable; 21 import java.util.Collections; 22 import java.util.HashSet; 23 import java.util.Set; 24 25 import org.torweg.pulse.annotations.Action.Security; 26 27 /** 28 * contains the method configurations for an action. 29 * 30 * @author Thomas Weber 31 * @version $Revision: 1954 $ 32 */ 33 public final class ActionConfiguration implements Serializable { 34 35 /** 36 * serialVersionUID. 37 */ 38 private static final long serialVersionUID = 8694030485429710151L; 39 40 /** 41 * the action. 42 */ 43 private final String action; 44 45 /** 46 * the method configurations belonging to the action. 47 */ 48 private final Set<ControllerMethodConfiguration> methodConfigurations = new HashSet<ControllerMethodConfiguration>(); 49 50 /** 51 * indicates whether the action shall be generated. 52 */ 53 private boolean generate = false; 54 55 /** 56 * indicates whether the sitemap-id shall be stripped from generated 57 * commands. 58 */ 59 private boolean stripSitemapId = false; 60 61 /** 62 * the level of security. 63 */ 64 private Security security; 65 66 /** 67 * the uploads allowed flag. 68 */ 69 private boolean uploadAllowed; 70 71 /** 72 * the strip suffix flag. 73 */ 74 private boolean stripSuffix; 75 76 /** 77 * creates a new {@code ActionConfiguration} for the given action. 78 * 79 * @param a 80 * the action 81 */ 82 public ActionConfiguration(final String a) { 83 super(); 84 this.action = a; 85 } 86 87 /** 88 * adds a method configuration to the action configuration. 89 * 90 * @param conf 91 * the method configuration to add 92 */ 93 public void add(final ControllerMethodConfiguration conf) { 94 if (conf.getActionAnnotation().value().equals(this.action)) { 95 this.methodConfigurations.add(conf); 96 this.generate = this.generate 97 | conf.getActionAnnotation().generate(); 98 this.stripSitemapId = this.stripSitemapId 99 | conf.getActionAnnotation().stripSitemapID(); 100 this.uploadAllowed = this.uploadAllowed 101 | conf.getActionAnnotation().uploadAllowed(); 102 this.stripSuffix = this.stripSuffix 103 | conf.getActionAnnotation().stripSuffix(); 104 if ((this.security == null) 105 || (conf.getActionAnnotation().security() 106 .overrides(this.security))) { 107 this.security = conf.getActionAnnotation().security(); 108 } 109 } 110 } 111 112 /** 113 * returns the name of the action. 114 * 115 * @return the name of the action 116 */ 117 public String getAction() { 118 return this.action; 119 } 120 121 /** 122 * returns the method configurations. 123 * 124 * @return an unmodifiable view of the method configurations 125 */ 126 public Set<ControllerMethodConfiguration> getMethodConfigurations() { 127 return Collections.unmodifiableSet(this.methodConfigurations); 128 } 129 130 /** 131 * returns whether the actions is to be generated. 132 * 133 * @return whether the actions is to be generated 134 */ 135 public boolean isGenerate() { 136 return this.generate; 137 } 138 139 /** 140 * returns whether the sitemap-id shall be stripped from generated actions. 141 * 142 * @return whether the sitemap-id shall be stripped from generated actions 143 */ 144 public boolean isStripSitemapId() { 145 return this.stripSitemapId; 146 } 147 148 /** 149 * returns whether the suffix shall be stripped from generated actions. 150 * 151 * @return whether the suffix shall be stripped from generated actions 152 */ 153 public boolean isStripSuffix() { 154 return this.stripSuffix; 155 } 156 157 /** 158 * returns whether uploads are allowed for the action. 159 * 160 * @return whether uploads are allowed for the action 161 */ 162 public boolean isUploadAllowed() { 163 return this.uploadAllowed; 164 } 165 166 /** 167 * returns the required level of security. 168 * 169 * @return the level of security 170 */ 171 public Security getSecurity() { 172 return this.security; 173 } 174 175 /** 176 * returns the hash code of the {@code ActionConfiguration}, which is based 177 * upon the action's name. 178 * 179 * @return the hash code 180 * @see java.lang.Object#hashCode() 181 */ 182 @Override 183 public int hashCode() { 184 return this.action.hashCode(); 185 } 186 187 /** 188 * returns whether the given object is equal to this 189 * {@code ActionConfiguration}. 190 * <p> 191 * Two {@code ActionConfiguration}s are considered equal, if they belong to 192 * the same action. 193 * </p> 194 * 195 * @param obj 196 * the object to check against 197 * @return {@code true}, if and only if the given object is a 198 * {@code ActionConfiguration} and the action matches this action. 199 * @see java.lang.Object#equals(java.lang.Object) 200 */ 201 @Override 202 public boolean equals(final Object obj) { 203 if (obj instanceof ActionConfiguration) { 204 return this.action.equals(((ActionConfiguration) obj).action); 205 } 206 return false; 207 } 208 } 209