1 17 package org.alfresco.repo.action; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 22 import java.util.HashSet ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.alfresco.i18n.I18NUtil; 27 import org.alfresco.service.cmr.action.ParameterDefinition; 28 import org.alfresco.service.cmr.action.ParameterizedItemDefinition; 29 import org.alfresco.service.cmr.rule.RuleServiceException; 30 31 36 public abstract class ParameterizedItemDefinitionImpl implements ParameterizedItemDefinition, Serializable 37 { 38 41 private String name; 42 43 46 private String titleKey; 47 48 51 private String descriptionKey; 52 53 56 private boolean adhocPropertiesAllowed = false; 57 58 61 private List <ParameterDefinition> parameterDefinitions = new ArrayList <ParameterDefinition>(); 62 63 66 private Map <String , ParameterDefinition> paramDefinitionsByName; 67 68 71 private static final String ERR_NAME_DUPLICATION = "The names " + 72 "given to parameter definitions must be unique within the " + 73 "scope of the rule item definition."; 74 75 80 public ParameterizedItemDefinitionImpl(String name) 81 { 82 this.name = name; 83 } 84 85 88 public String getName() 89 { 90 return this.name; 91 } 92 93 98 public void setTitleKey(String title) 99 { 100 this.titleKey = title; 101 } 102 103 106 public String getTitle() 107 { 108 return I18NUtil.getMessage(this.titleKey); 109 } 110 111 116 public void setDescriptionKey(String descriptionKey) 117 { 118 this.descriptionKey = descriptionKey; 119 } 120 121 124 public String getDescription() 125 { 126 return I18NUtil.getMessage(this.descriptionKey); 127 } 128 129 132 public boolean getAdhocPropertiesAllowed() 133 { 134 return this.adhocPropertiesAllowed; 135 } 136 137 142 public void setAdhocPropertiesAllowed(boolean adhocPropertiesAllowed) 143 { 144 this.adhocPropertiesAllowed = adhocPropertiesAllowed; 145 } 146 147 152 public void setParameterDefinitions( 153 List <ParameterDefinition> parameterDefinitions) 154 { 155 if (hasDuplicateNames(parameterDefinitions) == true) 156 { 157 throw new RuleServiceException(ERR_NAME_DUPLICATION); 158 } 159 160 this.parameterDefinitions = parameterDefinitions; 161 162 this.paramDefinitionsByName = new HashMap <String , ParameterDefinition>(this.parameterDefinitions.size()); 164 for (ParameterDefinition definition : this.parameterDefinitions) 165 { 166 this.paramDefinitionsByName.put(definition.getName(), definition); 167 } 168 } 169 170 178 private boolean hasDuplicateNames(List <ParameterDefinition> parameterDefinitions) 179 { 180 boolean result = false; 181 if (parameterDefinitions != null) 182 { 183 HashSet <String > temp = new HashSet <String >(parameterDefinitions.size()); 184 for (ParameterDefinition definition : parameterDefinitions) 185 { 186 temp.add(definition.getName()); 187 } 188 result = (parameterDefinitions.size() != temp.size()); 189 } 190 return result; 191 } 192 193 196 public List <ParameterDefinition> getParameterDefinitions() 197 { 198 return this.parameterDefinitions; 199 } 200 201 204 public ParameterDefinition getParameterDefintion(String name) 205 { 206 ParameterDefinition result = null; 207 if (paramDefinitionsByName != null) 208 { 209 result = this.paramDefinitionsByName.get(name); 210 } 211 return result; 212 } 213 } 214 | Popular Tags |