001 package railo.runtime.type; 002 003 import java.io.Externalizable; 004 import java.io.IOException; 005 import java.io.ObjectInput; 006 import java.io.ObjectOutput; 007 import java.io.Serializable; 008 import java.util.HashSet; 009 import java.util.Set; 010 011 import railo.commons.lang.CFTypes; 012 import railo.commons.lang.ExceptionUtil; 013 import railo.commons.lang.ExternalizableUtil; 014 import railo.commons.lang.SizeOf; 015 import railo.runtime.Page; 016 import railo.runtime.PageContextImpl; 017 import railo.runtime.PageSource; 018 import railo.runtime.PageSourceImpl; 019 import railo.runtime.config.ConfigWebImpl; 020 import railo.runtime.engine.ThreadLocalPageContext; 021 import railo.runtime.engine.ThreadLocalPageSource; 022 import railo.runtime.exp.ExpressionException; 023 import railo.runtime.type.util.ComponentUtil; 024 025 public final class UDFProperties implements Sizeable,Serializable,Externalizable { 026 027 028 public String functionName; 029 public int returnType; 030 public String strReturnType; 031 public boolean output; 032 public String hint; 033 public String displayName; 034 //public Page page; 035 public PageSource pageSource; 036 public int index; 037 public FunctionArgument[] arguments; 038 public Struct meta; 039 public String description; 040 public Boolean secureJson; 041 public Boolean verifyClient; 042 public boolean async; 043 public String strReturnFormat; 044 public int returnFormat; 045 public Set<Collection.Key> argumentsSet; 046 public int access; 047 048 049 public UDFProperties( 050 Page page, 051 FunctionArgument[] arguments, 052 int index, 053 String functionName, 054 String strReturnType, 055 String strReturnFormat, 056 boolean output, 057 boolean async, 058 String strAccess, 059 String displayName, 060 String description, 061 String hint, 062 Boolean secureJson, 063 Boolean verifyClient, 064 StructImpl meta) throws ExpressionException { 065 this(page.getPageSource(), 066 arguments, 067 index, 068 functionName, 069 strReturnType, 070 strReturnFormat, 071 output, 072 async, 073 ComponentUtil.toIntAccess(strAccess), 074 displayName, 075 description, 076 hint, 077 secureJson, 078 verifyClient, 079 meta); 080 081 } 082 083 084 public UDFProperties( 085 Page page, 086 FunctionArgument[] arguments, 087 int index, 088 String functionName, 089 String strReturnType, 090 String strReturnFormat, 091 boolean output, 092 boolean async, 093 int access, 094 String displayName, 095 String description, 096 String hint, 097 Boolean secureJson, 098 Boolean verifyClient, 099 StructImpl meta) throws ExpressionException { 100 101 this( 102 page.getPageSource(), 103 arguments, 104 index, 105 functionName, 106 strReturnType, 107 strReturnFormat, 108 output, 109 async, 110 access, 111 displayName, 112 description, 113 hint, 114 secureJson, 115 verifyClient, 116 meta); 117 118 } 119 120 public UDFProperties( 121 PageSource pageSource, 122 FunctionArgument[] arguments, 123 int index, 124 String functionName, 125 String strReturnType, 126 String strReturnFormat, 127 boolean output, 128 boolean async, 129 int access, 130 String displayName, 131 String description, 132 String hint, 133 Boolean secureJson, 134 Boolean verifyClient, 135 StructImpl meta) throws ExpressionException { 136 137 // this happens when a arcive is based on older source code 138 if(pageSource==null){ 139 pageSource = ThreadLocalPageSource.get(); 140 } 141 142 143 if(arguments.length>0){ 144 this.argumentsSet=new HashSet<Collection.Key>(); 145 for(int i=0;i<arguments.length;i++){ 146 argumentsSet.add(arguments[i].getName()); 147 } 148 } 149 else this.argumentsSet=null; 150 this.arguments = arguments; 151 this.async = async; 152 this.description = description; 153 this.displayName = displayName; 154 this.functionName = functionName; 155 this.hint = hint; 156 this.index = index; 157 this.meta = meta; 158 this.output = output; 159 //this.page = PageProxy.toProxy(page); 160 this.pageSource=pageSource; 161 162 163 this.strReturnType=strReturnType; 164 this.returnType=CFTypes.toShortStrict(strReturnType,CFTypes.TYPE_UNKNOW); 165 this.strReturnFormat=strReturnFormat; 166 this.returnFormat=UDFImpl.toReturnFormat(strReturnFormat); 167 168 this.secureJson = secureJson; 169 this.verifyClient = verifyClient; 170 this.access = access; 171 172 } 173 174 175 public UDFProperties( 176 Page page, 177 FunctionArgument[] arguments, 178 int index, 179 String functionName, 180 short returnType, 181 String strReturnFormat, 182 boolean output, 183 boolean async, 184 String strAccess, 185 String displayName, 186 String description, 187 String hint, 188 Boolean secureJson, 189 Boolean verifyClient, 190 StructImpl meta) throws ExpressionException { 191 this(page.getPageSource(), 192 arguments, 193 index, 194 functionName, 195 returnType, 196 strReturnFormat, 197 output, 198 async, 199 ComponentUtil.toIntAccess(strAccess), 200 displayName, 201 description, 202 hint, 203 secureJson, 204 verifyClient, 205 meta); 206 } 207 208 /** 209 * NEVER USE THIS CONSTRUCTOR, this constructor is only for deserialize this object from stream 210 */ 211 public UDFProperties(){ 212 213 } 214 215 //@deprecated use instead UDFProperties(PageSource pageSource,... 216 public UDFProperties(Page page, FunctionArgument[] arguments, int index, String functionName, short returnType, 217 String strReturnFormat, boolean output, boolean async, int access, String displayName, String description,String hint, 218 Boolean secureJson,Boolean verifyClient,StructImpl meta) throws ExpressionException { 219 this(page.getPageSource(),arguments,index,functionName, returnType, strReturnFormat, output, async,access, displayName, 220 description, hint, secureJson,verifyClient,meta); 221 } 222 223 public UDFProperties( 224 PageSource pageSource, 225 FunctionArgument[] arguments, 226 int index, 227 String functionName, 228 short returnType, 229 String strReturnFormat, 230 boolean output, 231 boolean async, 232 int access, 233 String displayName, 234 String description, 235 String hint, 236 Boolean secureJson, 237 Boolean verifyClient, 238 StructImpl meta) throws ExpressionException { 239 240 // this happens when a arcive is based on older source code 241 if(pageSource==null){ 242 pageSource = ThreadLocalPageSource.get(); 243 } 244 245 246 if(arguments.length>0){ 247 this.argumentsSet=new HashSet<Collection.Key>(); 248 for(int i=0;i<arguments.length;i++){ 249 argumentsSet.add(arguments[i].getName()); 250 } 251 } 252 else this.argumentsSet=null; 253 254 this.arguments = arguments; 255 this.async = async; 256 this.description = description; 257 this.displayName = displayName; 258 this.functionName = functionName; 259 this.hint = hint; 260 this.index = index; 261 this.meta = meta; 262 this.output = output; 263 this.pageSource = pageSource; 264 265 this.strReturnType=CFTypes.toString(returnType,"any"); 266 this.returnType=returnType; 267 this.strReturnFormat=strReturnFormat; 268 this.returnFormat=UDFImpl.toReturnFormat(strReturnFormat); 269 270 this.secureJson = secureJson; 271 this.verifyClient = verifyClient; 272 this.access = access; 273 274 } 275 276 277 278 /** 279 * @see railo.runtime.engine.Sizeable#sizeOf() 280 */ 281 public long sizeOf() { 282 return 283 SizeOf.size(functionName)+ 284 SizeOf.size(returnType)+ 285 SizeOf.size(strReturnType)+ 286 SizeOf.size(output)+ 287 SizeOf.size(hint)+ 288 SizeOf.size(index)+ 289 SizeOf.size(displayName)+ 290 SizeOf.size(arguments)+ 291 SizeOf.size(meta)+ 292 SizeOf.size(description)+ 293 SizeOf.size(secureJson)+ 294 SizeOf.size(verifyClient)+ 295 SizeOf.size(async)+ 296 SizeOf.size(strReturnFormat)+ 297 SizeOf.size(returnFormat); 298 } 299 300 301 /** 302 * @return the access 303 */ 304 public int getAccess() { 305 return access; 306 } 307 308 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 309 try { 310 PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get(); 311 ConfigWebImpl cw = (ConfigWebImpl) ThreadLocalPageContext.getConfig(pc); 312 String path=ExternalizableUtil.readString(in); 313 pageSource=PageSourceImpl.best(cw.getPageSources(pc,null, path, false,true,true)); 314 315 } 316 catch (Throwable e) { 317 e.printStackTrace(); 318 throw ExceptionUtil.toIOException(e); 319 } 320 321 arguments=(FunctionArgument[]) in.readObject(); 322 access = in.readInt(); 323 index = in.readInt(); 324 returnFormat = in.readInt(); 325 returnType = in.readInt(); 326 async = in.readBoolean(); 327 description = ExternalizableUtil.readString(in); 328 displayName = ExternalizableUtil.readString(in); 329 functionName = ExternalizableUtil.readString(in); 330 hint = ExternalizableUtil.readString(in); 331 meta = (Struct) in.readObject(); 332 output = in.readBoolean(); 333 secureJson = ExternalizableUtil.readBoolean(in); 334 strReturnFormat = ExternalizableUtil.readString(in); 335 strReturnType = ExternalizableUtil.readString(in); 336 verifyClient = ExternalizableUtil.readBoolean(in); 337 338 if(arguments!=null && arguments.length>0){ 339 this.argumentsSet=new HashSet<Collection.Key>(); 340 for(int i=0;i<arguments.length;i++){ 341 argumentsSet.add(arguments[i].getName()); 342 } 343 } 344 345 } 346 347 348 public void writeExternal(ObjectOutput out) throws IOException { 349 350 out.writeObject(pageSource.getFullRealpath()); 351 out.writeObject(arguments); 352 out.writeInt(access); 353 out.writeInt(index); 354 out.writeInt(returnFormat); 355 out.writeInt(returnType); 356 out.writeBoolean(async); 357 ExternalizableUtil.writeString(out,description); 358 ExternalizableUtil.writeString(out,displayName); 359 ExternalizableUtil.writeString(out,functionName); 360 ExternalizableUtil.writeString(out,hint); 361 out.writeObject(meta); 362 out.writeBoolean(output); 363 ExternalizableUtil.writeBoolean(out,secureJson); 364 ExternalizableUtil.writeString(out,strReturnFormat); 365 ExternalizableUtil.writeString(out,strReturnType); 366 ExternalizableUtil.writeBoolean(out,verifyClient); 367 368 369 } 370 371 372 373 374 }