001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.transformer.library.function; 020 021import java.io.IOException; 022 023import lucee.commons.lang.CFTypes; 024import lucee.commons.lang.Md5; 025import lucee.transformer.library.tag.TagLib; 026 027 028 029/** 030 * Eine FunctionLibFunctionArg repraesentiert ein einzelnes Argument einer Funktion. 031 */ 032public final class FunctionLibFunctionArg { 033 034 035 private static final short UNDEFINED = -12553; 036 037 038 /** 039 * @return the hidden 040 */ 041 public boolean isHidden() { 042 return hidden; 043 } 044 private String strType; 045 private boolean required; 046 private FunctionLibFunction function; 047 private String name; 048 private String description=""; 049 private String alias=null; 050 private String defaultValue=null; 051 private boolean hidden; 052 private short status=TagLib.STATUS_IMPLEMENTED; 053 private short type=UNDEFINED; 054 055 056 /** 057 * Geschuetzer Konstruktor ohne Argumente. 058 */ 059 public FunctionLibFunctionArg() {} 060 public FunctionLibFunctionArg(FunctionLibFunction function) { 061 this.function=function; 062 } 063 064 /** 065 * Gibt den Typ des Argument als String zurueck (query, struct, string usw.) 066 * @return Typ des Argument 067 */ 068 public String getTypeAsString() { 069 return this.strType; 070 } 071 072 /** 073 * Gibt den Typ des Argument zurueck (query, struct, string usw.) 074 * @return Typ des Argument 075 */ 076 public short getType() { 077 if(type==UNDEFINED) { 078 type=CFTypes.toShort(strType,false,CFTypes.TYPE_UNKNOW); 079 } 080 return type; 081 } 082 083 /** 084 * @return the status (TagLib.,TagLib.STATUS_IMPLEMENTED,TagLib.STATUS_DEPRECATED,TagLib.STATUS_UNIMPLEMENTED) 085 */ 086 public short getStatus() { 087 return status; 088 } 089 090 091 /** 092 * @param status the status to set (TagLib.,TagLib.STATUS_IMPLEMENTED,TagLib.STATUS_DEPRECATED,TagLib.STATUS_UNIMPLEMENTED) 093 */ 094 public void setStatus(short status) { 095 this.status = status; 096 } 097 098 /** 099 * Gibt zurueck, ob das Argument Pflicht ist oder nicht, alias fuer isRequired. 100 * @return Ist das Argument Pflicht. 101 */ 102 public boolean isRequired() { 103 return required; 104 } 105 106 /** 107 * Gibt zurueck, ob das Argument Pflicht ist oder nicht. 108 * @return Ist das Argument Pflicht. 109 */ 110 public boolean getRequired() { 111 return required; 112 } 113 114 /** 115 * Gibt die Funktion zurueck zu der das Argument gehoert. 116 * @return Zugehoerige Funktion. 117 */ 118 public FunctionLibFunction getFunction() { 119 return function; 120 } 121 122 /** 123 * Setzt die Funktion zu der das Argument gehoert. 124 * @param function Zugehoerige Funktion. 125 */ 126 protected void setFunction(FunctionLibFunction function) { 127 this.function = function; 128 } 129 130 /** 131 * Setzt, den Typ des Argument (query, struct, string usw.) 132 * @param type Typ des Argument. 133 */ 134 public void setType(String type) { 135 this.strType = type; 136 } 137 138 /** 139 * Setzt, ob das Argument Pflicht ist oder nicht. 140 * @param value Ist das Argument Pflicht. 141 */ 142 public void setRequired(String value) { 143 value=value.toLowerCase().trim(); 144 required=(value.equals("yes") || value.equals("true")); 145 } 146 public void setRequired(boolean value) { 147 required=value; 148 } 149 150 /** 151 * @return the name 152 */ 153 public String getName() { 154 return name; 155 } 156 157 /** 158 * @param name the name to set 159 */ 160 public void setName(String name) { 161 this.name = name; 162 } 163 164 public String getDescription() { 165 return description; 166 } 167 168 /** 169 * @param description the description to set 170 */ 171 public void setDescription(String description) { 172 this.description = description; 173 } 174 175 176 /** 177 * @return the defaultValue 178 */ 179 public String getDefaultValue() { 180 return defaultValue; 181 } 182 183 184 /** 185 * @param defaultValue the defaultValue to set 186 */ 187 public void setDefaultValue(String defaultValue) { 188 this.defaultValue = defaultValue; 189 } 190 191 public String getHash() { 192 StringBuffer sb=new StringBuffer(); 193 sb.append(this.getDefaultValue()); 194 sb.append(this.getName()); 195 sb.append(this.getRequired()); 196 sb.append(this.getTypeAsString()); 197 sb.append(this.getTypeAsString()); 198 sb.append(this.getAlias()); 199 200 try { 201 return Md5.getDigestAsString(sb.toString()); 202 } catch (IOException e) { 203 return ""; 204 } 205 } 206 /** 207 * @return the alias 208 */ 209 public String getAlias() { 210 return alias; 211 } 212 /** 213 * @param alias the alias to set 214 */ 215 public void setAlias(String alias) { 216 this.alias = alias; 217 } 218 public void setHidden(boolean hidden) { 219 this.hidden=hidden; 220 } 221}