001 package railo.transformer.library.function; 002 003 import java.io.IOException; 004 005 import railo.commons.lang.CFTypes; 006 import railo.commons.lang.Md5; 007 import railo.transformer.library.tag.TagLib; 008 009 010 011 /** 012 * Eine FunctionLibFunctionArg repraesentiert ein einzelnes Argument einer Funktion. 013 */ 014 public final class FunctionLibFunctionArg { 015 016 017 private static final short UNDEFINED = -12553; 018 019 020 /** 021 * @return the hidden 022 */ 023 public boolean isHidden() { 024 return hidden; 025 } 026 private String strType; 027 private boolean required; 028 private FunctionLibFunction function; 029 private String name; 030 private String description=""; 031 private String alias=null; 032 private String defaultValue=null; 033 private boolean hidden; 034 private short status=TagLib.STATUS_IMPLEMENTED; 035 private short type=UNDEFINED; 036 037 038 /** 039 * Geschuetzer Konstruktor ohne Argumente. 040 */ 041 public FunctionLibFunctionArg() {} 042 public FunctionLibFunctionArg(FunctionLibFunction function) { 043 this.function=function; 044 } 045 046 /** 047 * Gibt den Typ des Argument als String zurueck (query, struct, string usw.) 048 * @return Typ des Argument 049 */ 050 public String getTypeAsString() { 051 return this.strType; 052 } 053 054 /** 055 * Gibt den Typ des Argument zurueck (query, struct, string usw.) 056 * @return Typ des Argument 057 */ 058 public short getType() { 059 if(type==UNDEFINED) { 060 type=CFTypes.toShort(strType,false,CFTypes.TYPE_UNKNOW); 061 } 062 return type; 063 } 064 065 /** 066 * @return the status (TagLib.,TagLib.STATUS_IMPLEMENTED,TagLib.STATUS_DEPRECATED,TagLib.STATUS_UNIMPLEMENTED) 067 */ 068 public short getStatus() { 069 return status; 070 } 071 072 073 /** 074 * @param status the status to set (TagLib.,TagLib.STATUS_IMPLEMENTED,TagLib.STATUS_DEPRECATED,TagLib.STATUS_UNIMPLEMENTED) 075 */ 076 public void setStatus(short status) { 077 this.status = status; 078 } 079 080 /** 081 * Gibt zurueck, ob das Argument Pflicht ist oder nicht, alias fuer isRequired. 082 * @return Ist das Argument Pflicht. 083 */ 084 public boolean isRequired() { 085 return required; 086 } 087 088 /** 089 * Gibt zurueck, ob das Argument Pflicht ist oder nicht. 090 * @return Ist das Argument Pflicht. 091 */ 092 public boolean getRequired() { 093 return required; 094 } 095 096 /** 097 * Gibt die Funktion zurueck zu der das Argument gehoert. 098 * @return Zugehoerige Funktion. 099 */ 100 public FunctionLibFunction getFunction() { 101 return function; 102 } 103 104 /** 105 * Setzt die Funktion zu der das Argument gehoert. 106 * @param function Zugehoerige Funktion. 107 */ 108 protected void setFunction(FunctionLibFunction function) { 109 this.function = function; 110 } 111 112 /** 113 * Setzt, den Typ des Argument (query, struct, string usw.) 114 * @param type Typ des Argument. 115 */ 116 public void setType(String type) { 117 this.strType = type; 118 } 119 120 /** 121 * Setzt, ob das Argument Pflicht ist oder nicht. 122 * @param value Ist das Argument Pflicht. 123 */ 124 public void setRequired(String value) { 125 value=value.toLowerCase().trim(); 126 required=(value.equals("yes") || value.equals("true")); 127 } 128 public void setRequired(boolean value) { 129 required=value; 130 } 131 132 /** 133 * @return the name 134 */ 135 public String getName() { 136 return name; 137 } 138 139 /** 140 * @param name the name to set 141 */ 142 public void setName(String name) { 143 this.name = name; 144 } 145 146 public Object getDescription() { 147 return description; 148 } 149 150 /** 151 * @param description the description to set 152 */ 153 public void setDescription(String description) { 154 this.description = description; 155 } 156 157 158 /** 159 * @return the defaultValue 160 */ 161 public String getDefaultValue() { 162 return defaultValue; 163 } 164 165 166 /** 167 * @param defaultValue the defaultValue to set 168 */ 169 public void setDefaultValue(String defaultValue) { 170 this.defaultValue = defaultValue; 171 } 172 173 public String getHash() { 174 StringBuffer sb=new StringBuffer(); 175 sb.append(this.getDefaultValue()); 176 sb.append(this.getName()); 177 sb.append(this.getRequired()); 178 sb.append(this.getTypeAsString()); 179 sb.append(this.getTypeAsString()); 180 sb.append(this.getAlias()); 181 182 try { 183 return Md5.getDigestAsString(sb.toString()); 184 } catch (IOException e) { 185 return ""; 186 } 187 } 188 /** 189 * @return the alias 190 */ 191 public String getAlias() { 192 return alias; 193 } 194 /** 195 * @param alias the alias to set 196 */ 197 public void setAlias(String alias) { 198 this.alias = alias; 199 } 200 public void setHidden(boolean hidden) { 201 this.hidden=hidden; 202 } 203 }