001    package railo.runtime.exp;
002    
003    import railo.runtime.Info;
004    import railo.runtime.PageContext;
005    import railo.runtime.dump.DumpData;
006    import railo.runtime.dump.DumpProperties;
007    import railo.runtime.dump.DumpTable;
008    import railo.runtime.op.Caster;
009    import railo.runtime.reflection.Reflector;
010    import railo.runtime.type.Collection;
011    import railo.runtime.type.util.KeyConstants;
012    
013    
014    /**
015     * Box a Native Exception, Native = !PageException
016     */
017    public class NativeException extends PageExceptionImpl {
018    
019            private static final long serialVersionUID = 6221156691846424801L;
020            
021            private Throwable t;
022    
023        /**
024             * Standart constructor for native Exception class
025             * @param t Throwable
026             */
027            public NativeException(Throwable t) {
028            super(t,t.getClass().getName());
029            this.t=t;
030            StackTraceElement[] st = t.getStackTrace();
031            if(hasRailoRuntime(st))setStackTrace(st);
032            else {
033                    StackTraceElement[] cst = new Exception("Stack trace").getStackTrace();
034                    if(hasRailoRuntime(cst)){
035                            StackTraceElement[] mst=new StackTraceElement[st.length+cst.length-1];
036                            System.arraycopy(st, 0, mst, 0, st.length);
037                            System.arraycopy(cst, 1, mst, st.length, cst.length-1);
038                            
039                            setStackTrace(mst);
040                    }
041                    else setStackTrace(st);
042            }
043            setAdditional(KeyConstants._Cause, t.getClass().getName());
044            }
045    
046            private boolean hasRailoRuntime(StackTraceElement[] st) {
047                    if(st!=null)for(int i=0;i<st.length;i++){
048                            if(st[i].getClassName().indexOf("railo.runtime")!=-1) return true;
049                    }
050                    return false;
051            }
052    
053            @Override
054            public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
055                DumpData data = super.toDumpData(pageContext, maxlevel,dp);
056                if(data instanceof DumpTable)
057            ((DumpTable)data).setTitle("Railo ["+Info.getVersionAsString()+"] - Error ("+Caster.toClassName(t)+")");
058            
059            return data;
060        }
061    
062        @Override
063        public boolean typeEqual(String type) {
064            if(super.typeEqual(type))return true;
065            return Reflector.isInstaneOfIgnoreCase(t.getClass(),type);
066        }
067    
068            @Override
069            public void setAdditional(Collection.Key key, Object value) {
070                    super.setAdditional(key, value);
071            }
072    }