package THE_PACKAGE;

public class THE_RUBOTO_CLASS THE_ACTION THE_ANDROID_CLASS {
    private String scriptName;
    private boolean initialized = false;

    public void setCallbackProc(int id, Object obj) {
        // Error: no callbacks
        throw new RuntimeException("RubotoBroadcastReceiver does not accept callbacks");
    }
	
    public void setScriptName(String name){
        scriptName = name;
    }

    public THE_RUBOTO_CLASS() {
        this(null);
    }

    public THE_RUBOTO_CLASS(String name) {
        super();

        if (name != null)
            setScriptName(name);
    }

    public void onReceive(android.content.Context context, android.content.Intent intent) {
        if (Script.setUpJRuby(context)) {
            Script.defineGlobalVariable("$context", context);
            Script.defineGlobalVariable("$broadcast_receiver", this);
            Script.defineGlobalVariable("$intent", intent);

            try {
                if (scriptName != null && !initialized) {
                    new Script(scriptName).execute();
                    initialized = true;
                } else {
                    Script.execute("$broadcast_receiver.on_receive($context, $intent)");
                }
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }
}	



@@ -15,16 +15,45 @@
 CKAGE;%0A%0A
+import java.io.IOException;%0A%0A
 public c
@@ -134,16 +134,23 @@
 riptName
+ = null
 ;%0A    pr
@@ -590,16 +590,18 @@
 != null)
+ %7B
 %0A       
@@ -634,144 +634,98 @@
     
-%7D%0A
+    
 %0A    
-public void onReceive(android.content.Context context, android.content.Intent intent) %7B%0A        if (Script.setUpJRuby(context)) %7B
+        if (Script.isInitialized()) %7B%0A                loadScript();%0A            %7D
 %0A   
@@ -733,192 +733,133 @@
     
+%7D%0A
     
-Script.defineGlobalVariable(%22$context%22, context);%0A            Script.defineGlobalVariable(%22$broadcast_receiver%22, this);%0A            Script.defineGlobalVariable(%22$intent%22, intent);%0A
+%7D%0A%0A    protected void loadScript() %7B%0A        Script.put(%22$broadcast_receiver%22, this);%0A        if (scriptName != null) %7B
 %0A   
@@ -881,35 +881,42 @@
                 
-if 
+new Script
 (scriptName != n
@@ -914,87 +914,151 @@
 Name
- != null && !initialized) %7B%0A                    new Script(scriptName).execute(
+).execute();%0A            %7D catch(IOException e) %7B%0A                throw new RuntimeException(%22IOException loading broadcast receiver script%22, e
 );%0A 
@@ -1068,24 +1068,26 @@
         
+%7D%0A
         
 initiali
@@ -1082,52 +1082,238 @@
     
-initialized = true;%0A                %7D else %7B
+%7D%0A    %7D%0A%0A    public void onReceive(android.content.Context context, android.content.Intent intent) %7B%0A        Script.put(%22$context%22, context);%0A        Script.put(%22$broadcast_receiver%22, this);%0A        Script.put(%22$intent%22, intent);%0A
 %0A   
@@ -1309,32 +1309,38 @@
 tent);%0A%0A        
+try %7B%0A
             Scri
@@ -1408,30 +1408,8 @@
 %22);%0A
-                %7D%0A    
     
@@ -1447,20 +1447,16 @@
         
-    
 e.printS
@@ -1464,38 +1464,24 @@
 ackTrace();%0A
-            %7D%0A
         %7D%0A  

Update to work through manifest and directly