📄 cpe.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package org.openacs.js;import java.util.Iterator;import java.util.Map.Entry;import java.util.Set;import java.util.logging.Level;import java.util.logging.Logger;import javax.jms.JMSException;import org.mozilla.javascript.Context;import org.mozilla.javascript.Function;import org.mozilla.javascript.Scriptable;import org.mozilla.javascript.ScriptableObject;import org.openacs.CPELocal;import org.openacs.HostsLocal;import org.openacs.Message;import org.openacs.message.*;import org.openacs.utils.Ejb;/** * * @author Administrator */public class Cpe extends ScriptableObject { private Inform lastInform; private CPELocal cpe; private String lastCommandKey = ""; private HostsLocal host; private TransferComplete transferComplete; public Cpe () { } public Cpe (Context cx, Function ctor, Object[] args) {// System.out.println ("Construct: "+lastInform); this.lastInform = (Inform)args[0]; this.host = (HostsLocal)args[1]; if (args.length > 2 && args[2]!=null) { transferComplete = (TransferComplete)args[2]; put ("TransferComplete", this, ExportTransferComplete (cx, ctor)); } cpe = Ejb.lookupCPEBean(); put ("Inform", this, ExportInform (cx, ctor)); } @Override public String getClassName() { return "Cpe"; } private Message Call (Message msg) { //msg = cpe.Call (oui, sn, msg); long timeout = 0; Object to = getProperty(this, "timeout"); //System.out.println ("TIMEOUT to = "+to +" "+to.getClass().getName()); if (to != null && to != NOT_FOUND) { timeout = Object2Int(to); } msg = cpe.Call (host, msg, timeout); if (msg.isFault()) { Fault fault = (Fault)msg; throw new RuntimeException(fault.getFaultString () +fault.getFaultStringCwmp ()); } return msg; } private Scriptable ExportTransferComplete (Context cx, Scriptable top) { Scriptable tc = cx.newObject(top); tc.put("CommandKey", tc, transferComplete.CommandKey); tc.put("CompleteTime", tc, transferComplete.CompleteTime); tc.put("FaultCode", tc, transferComplete.FaultCode); tc.put("FaultString", tc, transferComplete.FaultString); tc.put("StartTime", tc, transferComplete.StartTime); return tc; } private Scriptable ExportInform (Context cx, Scriptable top) { Scriptable io = cx.newObject(top); Scriptable d = cx.newObject(io); d.put ("Manufacturer", d, lastInform.Manufacturer); d.put ("OUI", d, lastInform.oui); d.put ("ProductClass", d, lastInform.ProductClass); d.put ("SerialNumber", d, lastInform.sn); io.put ("DeviceId", io, d); io.put("MaxEnvelopes", io, lastInform.MaxEnvelopes); io.put("RetryCount", io, lastInform.RetryCount); io.put ("CurrentTime", io, lastInform.CurrentTime); Scriptable e = cx.newArray(io, lastInform.events.size()); int i = 0; for (String ev : lastInform.events.keySet()) { Scriptable event = cx.newObject(io); event.put ("EventCode", event, ev); event.put ("CommandKey", event, lastInform.events.get(ev)); e.put(i++, e, event); } io.put("Event", io, e); Scriptable pl = cx.newArray(io, lastInform.params.size()); i = 0; for (String p : lastInform.params.keySet()) { Scriptable param = cx.newObject(io); param.put ("Name", param, p); param.put ("Value", param, lastInform.params.get(p)); pl.put(i++, pl, param); } io.put("ParameterList", io, pl); return io; } public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) { return new Cpe (cx, ctorObj, args); } /* public String jsGet_sn() { return lastInform.sn; } public Scriptable jsGet_ssnn() { return inf; } public String jsGet_inform() { System.out.println ("jsGet_Inform()"); return lastInform.sn;// return ExportInform (); } */ public static int jsFunction_SetParameterValues (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; SetParameterValues msg_in = new SetParameterValues ();// NativeArray params = (NativeArray)args [0]; Scriptable params = (Scriptable)args [0]; if (args.length > 1) { msg_in.key = (String)args[1]; } // int l = (int)params.getLength(); int l = (int)params.getIds().length; for (int i = 0; i < l; i++) {// NativeObject nv = (NativeObject) params.get(i, params); Scriptable nv = (Scriptable) params.get(i, params); String n = (String)nv.get("name", nv); String v = (String)nv.get("value", nv); //System.out.println ("Setparams: "+n+" = "+v); msg_in.AddValue(n, v); } SetParameterValuesResponse msg_out = (SetParameterValuesResponse) _this.Call ( msg_in); //System.out.println ("Setparams: status="+msg_out.Status); return msg_out.Status; } public static /*NativeArray*/ Scriptable jsFunction_GetRPCMethods (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; GetRPCMethods msg_in = new GetRPCMethods (); GetRPCMethodsResponse msg_out = (GetRPCMethodsResponse) _this.Call ( msg_in);// NativeArray ra = new NativeArray (msg_out.methods.length); Scriptable ra = cx.newArray(thisObj, msg_out.methods.length); for (int i = 0; i < msg_out.methods.length; i++) { ra.put (i, ra, msg_out.methods [i]); } return ra; } public static Scriptable /*NativeArray*/ jsFunction_GetParameterValues (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; GetParameterValues msg_in = new GetParameterValues (); //NativeArray parameterNames = (NativeArray)args [0]; Scriptable parameterNames = (Scriptable)args [0]; //int l = (int)parameterNames.getLength(); int l = (int)parameterNames.getIds().length; msg_in.parameterNames = new String [l]; for (int i = 0; i < l; i++) { msg_in.parameterNames [i] = (String) parameterNames.get(i, parameterNames); } GetParameterValuesResponse msg_out = (GetParameterValuesResponse) _this.Call ( msg_in); return toNativeArray(cx, thisObj, msg_out.values.entrySet(), "name", "value"); }/* private static String [] toStringArray (NativeArray na) { int l = (int)na.getLength(); String [] sa = new String [l]; for (int i = 0; i < l; i++) { sa [i] = (String) na.get(i, na); } return sa; } */ private static String [] toStringArray (Scriptable na) { int l = (int)na.getIds().length; String [] sa = new String [l]; for (int i = 0; i < l; i++) { sa [i] = (String) na.get(i, na); } return sa; } public static Scriptable /*NativeObject*/ jsFunction_AddObject (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; AddObject msg_in = new AddObject (); msg_in.ObjectName = (String)args[0]; msg_in.ParameterKey = (String)args[1]; AddObjectResponse msg_out = (AddObjectResponse) _this.Call ( msg_in); // System.out.println ("Add: "+msg_out.InstanceNumber+" Status="+msg_out.Status);// NativeObject ro = new NativeObject(); Scriptable ro = cx.newObject(thisObj); ro.put("Status", ro, msg_out.Status); ro.put("InstanceNumber", ro, msg_out.InstanceNumber); return ro; } public static int jsFunction_DeleteObject (Context cx, Scriptable thisObj, Object[] args, Function funObj) {// System.out.println ("Delete: "+args[0]+" key="+args[1]); Cpe _this = (Cpe)thisObj;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -