001 package railo.intergral.fusiondebug.server.type.coll; 002 003 import java.util.ArrayList; 004 import java.util.Arrays; 005 import java.util.List; 006 007 import railo.intergral.fusiondebug.server.type.FDValueSupport; 008 import railo.intergral.fusiondebug.server.type.FDVariable; 009 import railo.intergral.fusiondebug.server.util.FDCaster; 010 import railo.runtime.Component; 011 import railo.runtime.type.Array; 012 import railo.runtime.type.Collection; 013 import railo.runtime.type.Collection.Key; 014 import railo.runtime.type.Struct; 015 import railo.runtime.type.comparator.TextComparator; 016 import railo.runtime.type.util.CollectionUtil; 017 018 import com.intergral.fusiondebug.server.FDLanguageException; 019 import com.intergral.fusiondebug.server.FDMutabilityException; 020 import com.intergral.fusiondebug.server.IFDStackFrame; 021 022 public class FDCollection extends FDValueSupport { 023 024 private static final int INTERVALL = 10; 025 private ArrayList children; 026 private Collection coll; 027 private String name; 028 private Key[] keys; 029 030 /** 031 * Constructor of the class 032 * @param frame 033 * @param name 034 * @param name 035 * @param coll 036 */ 037 038 039 public FDCollection(IFDStackFrame frame, String name, Collection coll) { 040 this(frame,name,coll,keys(coll)); 041 } 042 043 public FDCollection(IFDStackFrame frame, String name, Collection coll, Key[] keys) { 044 045 this.name=name; 046 this.coll=coll; 047 this.keys=keys; 048 //Key[] keys = coll.keys(); 049 children=new ArrayList(); 050 051 int intervall=INTERVALL; 052 while(intervall*intervall<keys.length) 053 intervall*=intervall; 054 055 if(keys.length>intervall){ 056 FDCollection node; 057 058 059 int len=keys.length; 060 061 int max; 062 for(int i=0;i<len;i+=intervall) { 063 max=(i+(intervall))<len?(intervall):len-i; 064 Key[] skeys=new Key[max]; 065 for(int y=0;y<max;y++) { 066 skeys[y]=keys[i+y]; 067 } 068 node = new FDCollection(frame,"Rows",coll,skeys); 069 children.add(new FDVariable(frame,node.getName(),node)); 070 } 071 } 072 else { 073 FDCollectionNode node; 074 for(int i=0;i<keys.length;i++){ 075 node = new FDCollectionNode(frame,coll,keys[i]); 076 children.add(new FDVariable(frame,node.getName(),node)); 077 } 078 } 079 } 080 081 private static Key[] keys(Collection coll) { 082 Key[] keys=CollectionUtil.keys(coll); 083 if(coll instanceof Array) return keys; 084 TextComparator comp=new TextComparator(true,true); 085 Arrays.sort(keys,comp); 086 return keys; 087 } 088 089 @Override 090 public List getChildren() { 091 return children; 092 } 093 094 095 public IFDStackFrame getStackFrame() { 096 // TODO Auto-generated method stub 097 return null; 098 } 099 100 @Override 101 public boolean isMutable() { 102 return false; 103 } 104 105 public void set(String arg0) throws FDMutabilityException,FDLanguageException { 106 throw new FDMutabilityException(); 107 } 108 109 @Override 110 public boolean hasChildren() { 111 return true; 112 } 113 114 115 @Override 116 public String toString() { 117 if(coll instanceof Array) 118 return "["+fromto()+"]"; 119 if(coll instanceof Component){ 120 Component c=(Component) coll; 121 return "Component "+c.getName()+"("+c.getPageSource().getDisplayPath()+")"; 122 } 123 if(coll instanceof Struct) 124 return "{"+fromto()+"}"; 125 return FDCaster.serialize(coll); 126 } 127 128 129 private String fromto() { 130 StringBuffer sb=new StringBuffer(); 131 for(int i=0;i<keys.length;i++){ 132 if(i!=0)sb.append(","); 133 sb.append(keys[i].toString()); 134 } 135 return keys[0]+" ... "+keys[keys.length-1]; 136 } 137 138 139 @Override 140 public String getName() { 141 return name; 142 } 143 }