001    package railo.runtime.op;
002    
003    import railo.runtime.PageContext;
004    import railo.runtime.PageSource;
005    import railo.runtime.db.SQL;
006    import railo.runtime.exp.Abort;
007    import railo.runtime.exp.AbortException;
008    import railo.runtime.exp.ApplicationException;
009    import railo.runtime.exp.CasterException;
010    import railo.runtime.exp.CustomTypeException;
011    import railo.runtime.exp.DatabaseException;
012    import railo.runtime.exp.ExpressionException;
013    import railo.runtime.exp.FunctionException;
014    import railo.runtime.exp.LockException;
015    import railo.runtime.exp.MissingIncludeException;
016    import railo.runtime.exp.NativeException;
017    import railo.runtime.exp.PageException;
018    import railo.runtime.exp.SecurityException;
019    import railo.runtime.exp.TemplateException;
020    import railo.runtime.exp.XMLException;
021    import railo.runtime.reflection.Reflector;
022    import railo.runtime.util.Excepton;
023    
024    /**
025     * Implementation of Exception Util
026     */
027    public final class ExceptonImpl implements Excepton {
028    
029        private static Class[] exceptions=new Class[14];
030        
031        static {
032            exceptions[TYPE_ABORT]=Abort.class;
033            exceptions[TYPE_ABORT_EXP]=AbortException.class;
034            exceptions[TYPE_APPLICATION_EXP]=ApplicationException.class;
035            exceptions[TYPE_CASTER_EXP]=CasterException.class;
036            exceptions[TYPE_CUSTOM_TYPE_EXP]=CustomTypeException.class;
037            exceptions[TYPE_DATABASE_EXP]=DatabaseException.class;
038            exceptions[TYPE_EXPRESSION_EXP]=ExpressionException.class;
039            exceptions[TYPE_FUNCTION_EXP]=FunctionException.class;
040            exceptions[TYPE_LOCK_EXP]=LockException.class;
041            exceptions[TYPE_MISSING_INCLUDE_EXP]=MissingIncludeException.class;
042            exceptions[TYPE_NATIVE_EXP]=NativeException.class;
043            exceptions[TYPE_SECURITY_EXP]=SecurityException.class;
044            exceptions[TYPE_TEMPLATE_EXP]=TemplateException.class;
045            exceptions[TYPE_XML_EXP]=XMLException.class;
046        }
047        
048        private static ExceptonImpl singelton;
049    
050        /**
051         * @return singleton instance
052         */
053        public static Excepton getInstance() {
054            if(singelton==null)singelton=new ExceptonImpl();
055            return singelton;
056        }
057    
058        /**
059         * @see railo.runtime.util.Excepton#createAbort()
060         */
061        public PageException createAbort() {
062            return new Abort(Abort.SCOPE_REQUEST);
063        }
064        
065        /**
066         * @see railo.runtime.util.Excepton#createAbortException(java.lang.String)
067         */
068        public PageException createAbortException(String showError) {
069            return new AbortException(showError);
070        }
071        
072        /**
073         * @see railo.runtime.util.Excepton#createApplicationException(java.lang.String)
074         */
075        public PageException createApplicationException(String message) {
076            return new ApplicationException(message);
077        }
078        
079        /**
080         * @see railo.runtime.util.Excepton#createApplicationException(java.lang.String, java.lang.String)
081         */
082        public PageException createApplicationException(String message, String detail) {
083            return new ApplicationException(message,detail);
084        }
085        
086        /**
087         * @see railo.runtime.util.Excepton#createCasterException(java.lang.String)
088         */
089        public PageException createCasterException(String message) {
090            return new CasterException(message);
091        }
092        
093        /**
094         * @see railo.runtime.util.Excepton#createCustomTypeException(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
095         */
096        public PageException createCustomTypeException(String message, String detail, String errorcode, String customType) {
097            return createCustomTypeException(message, detail, errorcode, customType, null);
098        }
099        
100        public PageException createCustomTypeException(String message, String detail, String errorcode, String customType,String extendedInfo) {
101            return new CustomTypeException(message,detail,errorcode,customType,extendedInfo);
102        }
103        
104        /**
105         * @see railo.runtime.util.Excepton#createDatabaseException(java.lang.String)
106         */
107        public PageException createDatabaseException(String message) {
108            return new DatabaseException(message,null,null,null);
109        }
110        
111        /**
112         * @see railo.runtime.util.Excepton#createDatabaseException(java.lang.String, java.lang.String)
113         */
114        public PageException createDatabaseException(String message, String detail) {
115            return new DatabaseException(message,detail,null,null,null);
116        }
117        
118        /**
119         * @see railo.runtime.util.Excepton#createDatabaseException(java.lang.String, railo.runtime.db.SQL)
120         */
121        public PageException createDatabaseException(String message, SQL sql) {
122            return new DatabaseException(message,null,sql,null);
123        }
124        
125        /**
126         * @see railo.runtime.util.Excepton#createExpressionException(java.lang.String)
127         */
128        public PageException createExpressionException(String message) {
129            return new ExpressionException(message);
130        }
131        
132        /**
133         * @see railo.runtime.util.Excepton#createExpressionException(java.lang.String, java.lang.String)
134         */
135        public PageException createExpressionException(String message, String detail) {
136            return new ExpressionException(message, detail);
137        }
138        
139        /**
140         * @see railo.runtime.util.Excepton#createFunctionException(railo.runtime.PageContext, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
141         */
142        public PageException createFunctionException(PageContext pc,String functionName, String badArgumentPosition, String badArgumentName, String message) {
143            return new FunctionException(pc,functionName, badArgumentPosition, badArgumentName,message);
144        }
145        
146        /**
147         * @see railo.runtime.util.Excepton#createLockException(java.lang.String, java.lang.String, java.lang.String)
148         */
149        public PageException createLockException(String operation, String name, String message) {
150            return new LockException(operation,name,message);
151        }
152        
153        /**
154         * @see railo.runtime.util.Excepton#createMissingIncludeException(railo.runtime.PageSource)
155         */
156        public PageException createMissingIncludeException(PageSource ps) {
157            return new MissingIncludeException(ps);
158        }
159        
160        /**
161         * @see railo.runtime.util.Excepton#createNativeException(java.lang.Throwable)
162         */
163        public PageException createNativeException(Throwable t) {
164            return new NativeException(t);
165        }
166        
167        /**
168         * @see railo.runtime.util.Excepton#createSecurityException(java.lang.String)
169         */
170        public PageException createSecurityException(String message) {
171            return new SecurityException(message);
172        }
173        
174        /**
175         * @see railo.runtime.util.Excepton#createSecurityException(java.lang.String, java.lang.String)
176         */
177        public PageException createSecurityException(String message, String detail) {
178            return new SecurityException(message,detail);
179        }
180        
181        /**
182         * @see railo.runtime.util.Excepton#createTemplateException(java.lang.String)
183         */
184        public PageException createTemplateException(String message) {
185            return new TemplateException(message);
186        }
187        
188        /**
189         * @see railo.runtime.util.Excepton#createTemplateException(java.lang.String, java.lang.String)
190         */
191        public PageException createTemplateException(String message, String detail) {
192            return new TemplateException(message,detail);
193        }
194        
195        /**
196         * @see railo.runtime.util.Excepton#createXMLException(java.lang.String)
197         */
198        public PageException createXMLException(String message) {
199            return new XMLException(message);
200        }
201        
202        /**
203         * @see railo.runtime.util.Excepton#createXMLException(java.lang.String, java.lang.String)
204         */
205        public PageException createXMLException(String message, String detail) {
206            return new XMLException(message,detail);
207        }
208    
209        /**
210         * @see railo.runtime.util.Excepton#isOfType(int, java.lang.Throwable)
211         */
212        
213        public boolean isOfType(int type, Throwable t) {
214            switch(type){
215                    case TYPE_ABORT:                                return Abort.isSilentAbort(t);
216                    case TYPE_ABORT_EXP:                    return t instanceof AbortException;
217                    case TYPE_APPLICATION_EXP:              return t instanceof ApplicationException;
218                    case TYPE_CASTER_EXP:                   return t instanceof CasterException;
219                    case TYPE_CUSTOM_TYPE_EXP:              return t instanceof CustomTypeException;
220                    case TYPE_DATABASE_EXP:                 return t instanceof DatabaseException;
221                    case TYPE_EXPRESSION_EXP:               return t instanceof ExpressionException;
222                    case TYPE_FUNCTION_EXP:                 return t instanceof FunctionException;
223                    case TYPE_LOCK_EXP:                             return t instanceof LockException;
224                    case TYPE_MISSING_INCLUDE_EXP:  return t instanceof MissingIncludeException;
225                    case TYPE_NATIVE_EXP:                   return t instanceof NativeException;
226                    case TYPE_SECURITY_EXP:                 return t instanceof SecurityException;
227                    case TYPE_TEMPLATE_EXP:                 return t instanceof TemplateException;
228                    case TYPE_XML_EXP:                              return t instanceof XMLException;
229            }
230            return Reflector.isInstaneOf(t.getClass(),exceptions[type]);
231        }
232        
233    
234    }