001 package railo.runtime.cache.eh.remote.soap; 002 003 import java.io.ByteArrayInputStream; 004 import java.io.ObjectInputStream; 005 import java.util.Date; 006 007 import railo.commons.io.cache.CacheEntry; 008 import railo.loader.util.Util; 009 import railo.runtime.cache.CacheUtil; 010 import railo.runtime.type.Struct; 011 012 public class SoapCacheEntry implements CacheEntry { 013 014 private Element element; 015 016 public SoapCacheEntry(Element element) { 017 this.element=element; 018 019 } 020 021 022 /** 023 * @see railo.commons.io.cache.CacheEntry#created() 024 */ 025 public Date created() { 026 return new Date(element.getExpirationDate().longValue()-element.getTimeToLiveSeconds().longValue()); 027 } 028 029 /** 030 * @see railo.commons.io.cache.CacheEntry#lastHit() 031 */ 032 public Date lastHit() { 033 return new Date(0); 034 // TODO return new Date(element.getLastAccessTime()); 035 } 036 037 /** 038 * @see railo.commons.io.cache.CacheEntry#lastModified() 039 */ 040 public Date lastModified() { 041 return new Date(0); 042 // TODO long value = element.getLastUpdateTime(); 043 // TODO if(value==0)return created(); 044 // TODO return new Date(value); 045 } 046 047 /** 048 * @see railo.commons.io.cache.CacheEntry#hitCount() 049 */ 050 public int hitCount() { 051 return 0; 052 // TODO return (int)element.getHitCount(); 053 } 054 055 /** 056 * @see railo.commons.io.cache.CacheEntry#idleTimeSpan() 057 */ 058 public long idleTimeSpan() { 059 return element.getTimeToIdleSeconds().intValue()*1000; 060 } 061 062 /** 063 * @see railo.commons.io.cache.CacheEntry#validUntil() 064 */ 065 public long liveTimeSpan() { 066 return element.getTimeToLiveSeconds().intValue()*1000; 067 } 068 069 /** 070 * @see railo.commons.io.cache.CacheEntry#size() 071 */ 072 public long size() { 073 return element.getValue().length; 074 } 075 076 /** 077 * @see railo.commons.io.cache.CacheEntry#getKey() 078 */ 079 public String getKey() { 080 return (String) element.getKey(); 081 } 082 083 /** 084 * @see railo.commons.io.cache.CacheEntry#getValue() 085 */ 086 public Object getValue() { 087 try{ 088 ByteArrayInputStream bais = new ByteArrayInputStream(element.getValue()); 089 if("application/x-java-serialized-object".equals(element.getMimeType())){ 090 ObjectInputStream ois=new ObjectInputStream(bais); 091 return ois.readObject(); 092 } 093 // other 094 return Util.toString(bais); 095 } 096 catch(Throwable t){ 097 return null; 098 } 099 } 100 101 public void setElement(Element element) { 102 this.element=element; 103 } 104 105 106 /** 107 * @see java.lang.Object#toString() 108 */ 109 public String toString() { 110 return CacheUtil.toString(this); 111 } 112 113 /** 114 * @see railo.commons.io.cache.CacheEntry#getCusomInfo() 115 */ 116 public Struct getCustomInfo() { 117 Struct info=CacheUtil.getInfo(this); 118 // TODO info.setEL("version", new Double(element.getVersion())); 119 return info; 120 } 121 122 }