/**
*    Copyright (C) 2008 10gen Inc.
*  
*    This program is free software: you can redistribute it and/or  modify
*    it under the terms of the GNU Affero General Public License, version 3,
*    as published by the Free Software Foundation.
*  
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU Affero General Public License for more details.
*  
*    You should have received a copy of the GNU Affero General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package ed.appserver.templates.djang10;

import ed.js.JSFunction;
import ed.js.JSObject;
import ed.js.engine.Scope;
import ed.js.func.JSFunctionCalls2;

public class Djang10Exception extends RuntimeException implements JSObject {
    private String detailMessage;
    private Throwable cause;
    
    public Djang10Exception() { }

    public Djang10Exception(String detailMessage) {
        this();
        this.detailMessage = detailMessage;
    }
    
    public Djang10Exception(String detailMessage, Throwable t) {
        this(detailMessage);
        this.cause = t;
    }
    
    protected void init(String detailMessage, Throwable cause) {
        this.detailMessage = detailMessage;
        this.cause = cause;
    }
    
    //Minimal JSObject
    public JSFunction getConstructor() {
        return cons;
    }
    public JSObject getSuper() {
        return null;
    }
    public Object get( Object n ){
        return null;
    }
    public java.util.Collection<String> keySet(){
        throw new UnsupportedOperationException();
    }
    public java.util.Collection<String> keySet( boolean includePrototype ){
        throw new UnsupportedOperationException();
    }
    public boolean containsKey( String s ){
        throw new UnsupportedOperationException();
    }
    public Object set( Object n , Object v ){
        throw new UnsupportedOperationException();
    }
    public Object setInt( int n , Object v ){
        throw new UnsupportedOperationException();
    }
    public Object getInt( int n ){
        throw new UnsupportedOperationException();
    }
    public Object removeField( Object n ){
        throw new UnsupportedOperationException();
    }

    
    //Exception overrides
    public Throwable getCause() {
        return cause;
    }
    public String getMessage() {
        return detailMessage;
    }
    
    
    public static final Constructor cons = new Constructor();

    private static class Constructor extends JSFunctionCalls2 {
        public JSObject newOne() {
            return new Djang10Exception();
        }
        public Object call(Scope scope, Object detailMessageObj, Object causeObj, Object[] extra) {
            Djang10Exception thisObj = (Djang10Exception)scope.getThis();
            
            thisObj.init((detailMessageObj == null)? null : detailMessageObj.toString(), (Throwable)causeObj);

            return null;
        }
    }
}

@@ -754,16 +754,43 @@
 Object;%0A
+import ed.js.JSObjectBase;%0A
 import e
@@ -999,34 +999,129 @@
    p
-ublic Djang10Exception() %7B
+rotected JSObjectBase inner;%0A    %0A    public Djang10Exception() %7B%0A        inner = new JSObjectBase(getConstructor());%0A   
  %7D%0A%0A
@@ -1530,15 +1530,19 @@
   //
-Minimal
+Delegate to
  JSO
@@ -1655,36 +1655,48 @@
 %0A        return 
-null
+inner.getSuper()
 ;%0A    %7D%0A    publ
@@ -1733,28 +1733,36 @@
      return 
-null
+inner.get(n)
 ;%0A    %7D%0A    
@@ -1819,47 +1819,27 @@
     
-throw new UnsupportedOperationException
+return inner.keySet
 ();%0A
@@ -1932,48 +1932,44 @@
     
-throw new UnsupportedOperationException(
+return inner.keySet(includePrototype
 );%0A 
@@ -2029,48 +2029,34 @@
     
-throw new UnsupportedOperationException(
+return inner.containsKey(s
 );%0A 
@@ -2118,48 +2118,29 @@
     
-throw new UnsupportedOperationException(
+return inner.set(n, v
 );%0A 
@@ -2202,48 +2202,32 @@
     
-throw new UnsupportedOperationException(
+return inner.setInt(n, v
 );%0A 
@@ -2278,48 +2278,29 @@
     
-throw new UnsupportedOperationException(
+return inner.getInt(n
 );%0A 
@@ -2359,48 +2359,34 @@
     
-throw new UnsupportedOperationException(
+return inner.removeField(n
 );%0A 

fix djang10 exceptions....delegate all jsobject tasks to an inner jsobject