📄 cpe.java
字号:
DeleteObject msg_in = new DeleteObject (); msg_in.ObjectName = (String)args[0]; msg_in.ParameterKey = (String)args[1]; DeleteObjectResponse msg_out = (DeleteObjectResponse) _this.Call ( msg_in); return msg_out.Status; } public static void jsFunction_Reboot (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; _this.Call ( new Reboot ((String)args[0])); } public static void jsFunction_FactoryReset (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; _this.Call ( new FactoryReset()); } public static void jsFunction_SetParameterAttributes (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; //NativeArray attrs = (NativeArray)args[0]; Scriptable attrs = (Scriptable)args[0]; SetParameterAttributes msg_in = new SetParameterAttributes ();// int c = (int)attrs.getLength(); int c = (int)attrs.getIds().length; for (int i=0; i < c; i++) {// NativeObject o = (NativeObject)attrs.get(i, attrs); Scriptable o = (Scriptable)attrs.get(i, attrs);// NativeArray acl = (NativeArray)o.get("AccessList", o); Scriptable acl = (Scriptable)o.get("AccessList", o); String [] sacl = toStringArray(acl); String Name = (String)o.get ("Name", o); boolean NotificationChange = (Boolean)o.get ("NotificationChange", o); int Notification = ((Double)o.get ("Notification", o)).intValue(); boolean AccessListChange = (Boolean)o.get ("AccessListChange", o); msg_in.AddAttribute(Name, NotificationChange, Notification, AccessListChange, sacl); } //SetParameterAttributesResponse msg_out = (SetParameterAttributesResponse) _this.Call ( msg_in); } /* private static NativeArray toNativeArray (Context cx, Scriptable scriptable, Set <Entry <String, String>> s, String n, String k) { NativeArray ra = new NativeArray (s.size()); Iterator <Entry <String, String>> it = s.iterator(); int i = 0; while (it.hasNext()) { Entry <String, String> e = it.next(); //NativeObject o = new NativeObject(); Scriptable o = cx.newObject(scriptable); o.put(n, o, e.getKey()); o.put(k, o, e.getValue()); ra.put(i++, ra, o); } return ra; } */ private static Scriptable toNativeArray (Context cx, Scriptable scriptable, Set <Entry <String, String>> s, String n, String k) { Scriptable ra = cx.newArray(scriptable, s.size()); Iterator <Entry <String, String>> it = s.iterator(); int i = 0; while (it.hasNext()) { Entry <String, String> e = it.next(); //NativeObject o = new NativeObject(); Scriptable o = cx.newObject(scriptable); o.put(n, o, e.getKey()); o.put(k, o, e.getValue()); ra.put(i++, ra, o); } return ra; } public static Scriptable /*NativeArray*/ jsFunction_GetParameterNames (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; GetParameterNames msg_in = new GetParameterNames (); msg_in.parameterPath = (String)args[0]; msg_in.nextLevel = (Boolean)args[1]; //System.out.println ("nextlevel "+args[1].getClass().getName()); GetParameterNamesResponse msg_out = (GetParameterNamesResponse) _this.Call ( msg_in); return toNativeArray(cx, thisObj, msg_out.names.entrySet(), "name", "writable"); } public static Scriptable /*NativeArray*/ jsFunction_GetParameterAttributes (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; GetParameterAttributes msg_in = new GetParameterAttributes ();// NativeArray parameterNames = (NativeArray)args [0];// int l = (int)parameterNames.getLength(); Scriptable parameterNames = (Scriptable)args [0]; 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); } GetParameterAttributesResponse msg_out = (GetParameterAttributesResponse) _this.Call ( msg_in);// NativeArray ra = new NativeArray (msg_out.attributes.length); Scriptable ra = cx.newArray(thisObj, msg_out.attributes.length); for (int i = 0; i < msg_out.attributes.length; i++) {// NativeArray acl = new NativeArray (msg_out.attributes[i].AccessList); Object [] acla = new Object [msg_out.attributes[i].AccessList.length]; for (int aclix = 0; aclix < msg_out.attributes[i].AccessList.length; aclix++) { acla [aclix] = msg_out.attributes[i].AccessList[aclix]; } Scriptable acl = cx.newArray (thisObj, acla);// NativeObject attr = new NativeObject(); Scriptable attr = cx.newObject(thisObj); attr.put ("Name", attr, msg_out.attributes[i].Name); attr.put ("Notification", attr, msg_out.attributes[i].Notification); attr.put ("AccessList", attr, acl); ra.put(i, ra, attr); } return ra; } public static void jsFunction_log (Context cx, Scriptable thisObj, Object[] args, Function funObj){ if (args.length > 0 && args[0] != Context.getUndefinedValue()) { System.out.println ("jsFunction_log: " + Context.toString(args[0])); } } public static Scriptable jsFunction_Download (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; Download msg_in = new Download ();/* for (Object a : args) { System.out.println ("arg="+a.getClass().getName()+" value= "+a); }*/ msg_in.CommandKey = _this.lastCommandKey = (String)args[0]; msg_in.FileType = (String)args[1]; msg_in.url = (String)args[2]; msg_in.UserName = (String)args[3]; msg_in.Password = (String)args[4];// msg_in.FileSize = Long.parseLong((String)args[5]); msg_in.FileSize = (Integer)args[5]; msg_in.TargetFileName = (String)args[6]; if (args.length >= 8) msg_in.DelaySeconds = (Integer)args[7]; if (args.length >= 9) msg_in.SuccessUrl = (String)args[8]; if (args.length >= 10) msg_in.FailureUrl = (String)args[9]; DownloadResponse msg_out = (DownloadResponse) _this.Call ( msg_in); Scriptable r = cx.newObject(thisObj); r.put("StartTime", r, msg_out.StartTime); r.put("CompleteTime", r, msg_out.CompleteTime); r.put("Status", r, msg_out.Status); return r; } public static Scriptable jsFunction_WaitForTransferComplete (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; System.out.println ("Wait for trasnfercomplete cmd="+_this.lastCommandKey); if (_this.lastCommandKey.equals ("")) return null; long timeout = 10*1000; if (args.length > 0) timeout = (Integer)args[0]*1000; try { TransferComplete tc = (TransferComplete) _this.cpe.WaitJmsReply("JMSCorrelationID='" + _this.lastCommandKey + "'", timeout); Scriptable ro = cx.newObject(thisObj); ro.put("CompleteTime", ro, tc.CompleteTime); ro.put("StartTime", ro, tc.StartTime); ro.put("FaultCode", ro, tc.FaultCode); ro.put("FaultString", ro, tc.FaultString); return ro; } catch (JMSException ex) { Logger.getLogger(Cpe.class.getName()).log(Level.SEVERE, null, ex); } finally { _this.lastCommandKey = ""; } return null; } private static int Object2Int (Object o) { if (o == null) return 0; String c = o.getClass().getName(); if (c.equals("java.lang.Double")) { return ((Double)o).intValue(); } if (c.equals("java.lang.Integer")) { return (Integer)o; } throw new RuntimeException ("Failed to convert object to int"); } public static Scriptable jsFunction_Upload (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; Upload msg_in = new Upload (); msg_in.CommandKey = _this.lastCommandKey = (String)args[0]; msg_in.FileType = (String)args[1]; msg_in.URL = (String)args[2]; msg_in.Username = (String)args[3]; msg_in.Password = (String)args[4]; msg_in.DelaySeconds = Object2Int (args[5]); UploadResponse msg_out = (UploadResponse) _this.Call ( msg_in); Scriptable r = cx.newObject(thisObj); r.put("StartTime", r, msg_out.StartTime); r.put("CompleteTime", r, msg_out.CompleteTime); r.put("Status", r, msg_out.Status); return r; } public static void jsFunction_ScheduleInform (Context cx, Scriptable thisObj, Object[] args, Function funObj) { Cpe _this = (Cpe)thisObj; ScheduleInform msg_in = new ScheduleInform (); msg_in.DelaySeconds = Object2Int (args[0]); msg_in.CommandKey = _this.lastCommandKey = (String)args[1]; _this.Call ( msg_in); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -