public String toString() { final StringBuilder buf = new StringBuilder(255); buf.append(namespaces.toString()); if (_parent != null) { buf.append('\n'); buf.append(_parent.toString()); } return buf.toString(); }
/** * An example of a variable-arguments method. * * <p>All variable arguments methods must have the same number and types of parameters, and must * be static. * * <p> * * @param cx the Context of the current thread * @param thisObj the JavaScript 'this' value. * @param args the array of arguments for this call * @param funObj the function object of the invoked JavaScript function This value is useful to * compute a scope using Context.getTopLevelScope(). * @return computes the string values and types of 'this' and of each of the supplied arguments * and returns them in a string. * @see org.mozilla.javascript.ScriptableObject#getTopLevelScope */ @JSFunction public static Object varargs(Context cx, Scriptable thisObj, Object[] args, Function funObj) { StringBuilder buf = new StringBuilder(); buf.append("this = "); buf.append(Context.toString(thisObj)); buf.append("; args = ["); for (int i = 0; i < args.length; i++) { buf.append(Context.toString(args[i])); if (i + 1 != args.length) buf.append(", "); } buf.append("]"); return buf.toString(); }
public Gender computeGender(Context c) { Gender gender; double[] gdist = genModel.genderDistribution(c); if (debugOn) { System.err.println( "MaxentCompatibilityModel.computeGender: " + c.toString() + " m=" + gdist[genModel.getMaleIndex()] + " f=" + gdist[genModel.getFemaleIndex()] + " n=" + gdist[genModel.getNeuterIndex()]); } if (genModel.getMaleIndex() >= 0 && gdist[genModel.getMaleIndex()] > minGenderProb) { gender = new Gender(GenderEnum.MALE, gdist[genModel.getMaleIndex()]); } else if (genModel.getFemaleIndex() >= 0 && gdist[genModel.getFemaleIndex()] > minGenderProb) { gender = new Gender(GenderEnum.FEMALE, gdist[genModel.getFemaleIndex()]); } else if (genModel.getNeuterIndex() >= 0 && gdist[genModel.getNeuterIndex()] > minGenderProb) { gender = new Gender(GenderEnum.NEUTER, gdist[genModel.getNeuterIndex()]); } else { gender = new Gender(GenderEnum.UNKNOWN, minGenderProb); } return gender; }
@Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof OnFragmentInteractionListener) { mListener = (OnFragmentInteractionListener) context; } else { throw new RuntimeException( context.toString() + " must implement OnFragmentInteractionListener"); } }
private Object parseMessage() { // Consume SOAP message, if any // TODO: Add a SOAP handler in Parser.java if (soapAction != null) { try { MimeHeaders mime_headers = new MimeHeaders(); for (Object k : headers.getIds()) { if (k instanceof String) { String name = (String) k; String value = Context.toString(ScriptableObject.getProperty(headers, name)); mime_headers.addHeader(name, value); } } return MessageFactory.newInstance(SOAPConstants.DYNAMIC_SOAP_PROTOCOL) .createMessage(mime_headers, request.getInputStream()); } catch (IOException ex) { throw new ESXXException("Unable to read SOAP message stream: " + ex.getMessage()); } catch (SOAPException ex) { throw new ESXXException(400 /* Bad Request */, "Invalid SOAP message: " + ex.getMessage()); } finally { try { request.getInputStream().close(); } catch (Exception ignored) { } } } else if (contentType != null && contentLength > 0) { try { ESXX esxx = ESXX.getInstance(); return esxx.parseStream( contentType, request.getInputStream(), URI.create("urn:x-esxx:incoming-request-entity"), null, new java.io.PrintWriter(request.getErrorWriter()), Context.getCurrentContext(), this); } catch (Exception ex) { throw new ESXXException( 400 /* Bad Request */, "Unable to parse request entity: " + ex.getMessage(), ex); } finally { try { request.getInputStream().close(); } catch (Exception ignored) { } } } else { // Return a dummy object return Context.getCurrentContext().newObject(this); } }
public static Object jsFunction_remove( Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception { JSURI js_this = checkInstance(thisObj); String type = null; HashMap<String, String> params = new HashMap<String, String>(); if (args.length >= 1 && args[0] != Context.getUndefinedValue()) { type = ESXX.parseMIMEType(Context.toString(args[0]), params); } return js_this.protocolHandler.remove(cx, thisObj, type, params); }
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (args.length == 3) { final String file = Context.toString(args[0]); // TODO Implement mode // String mode = Context.toString(args[1]); final Function callback = (Function) args[2]; return mkdir(cx, scope, thisObj, file, callback); } else { throw new RuntimeException("Only writeFile with 3 parameters supported"); } }
public static Object jsFunction_modify( Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception { JSURI js_this = checkInstance(thisObj); String type = null; HashMap<String, String> params = new HashMap<String, String>(); if (args.length < 1 || args[0] == Context.getUndefinedValue()) { throw Context.reportRuntimeError("Missing append() argument"); } if (args.length >= 2 && args[1] != Context.getUndefinedValue()) { type = ESXX.parseMIMEType(Context.toString(args[1]), params); } return js_this.protocolHandler.modify(cx, thisObj, args[0], type, params); }
private int filterProperty(Context cx, Scriptable param, String key, Object value) { Object rule = param.get(key, param); if (rule == null || rule == Scriptable.NOT_FOUND || value == null) { return 0; } if (rule instanceof Number && value instanceof Number) { return ((Number) rule).doubleValue() == ((Number) value).doubleValue() ? 1 : -1000; } else if (rule instanceof NativeRegExp) { return ((NativeRegExp) rule).call(cx, this, (NativeRegExp) rule, new Object[] {value}) != null ? 1 : -1000; } else { return Context.toString(rule).equals(value.toString()) ? 1 : -1000; } }
/** Use example for DAGraph and Lattice classes * */ public static void ExampleDAGraph() { try { String name = "DAGraph"; // create the directory to save files File f = new File(outputDir + name); f.mkdir(); // create the Readme file name = name + File.separator + name; BufferedWriter file = new BufferedWriter(new FileWriter(outputDir + name + "Readme.txt")); String log = "EXAMPLE FOR DAGRAPH AND LATTICE CLASSES\n"; log += "-----------------------------------------\n"; System.out.println(log); file.write(log); // randomly generates a directed graph of 10 nodes DAGraph G = DAGraph.random(10); String nameGraph = name + ".dot"; G.save(outputDir + nameGraph); log = "-> Randomly generated DAGraph saved in " + nameGraph + "\n"; System.out.println(log + G.toString()); file.write(log); // verify if the dagraph is acyclic log = nameGraph + " acyclic? " + G.isAcyclic() + "\n"; System.out.println(log); file.write(log); // computes and print the transitive reduction of the dagraph G.transitiveReduction(); String nameTR = name + "TransitiveReduction.dot"; G.save(outputDir + nameTR); log = "-> Transitive reduction saved in " + nameTR + "\n"; System.out.println(log + G.toString()); file.write(log); // computes and print the ideal and the filter of the first node Node n = G.getNodes().first(); DAGraph ideal = G.ideal(n); String nameIdeal = name + "Ideal.dot"; ideal.save(outputDir + nameIdeal); log = "-> Minorants of " + n + " : " + G.minorants(n) + "\n saved as a dagraph in " + nameIdeal + "\n"; System.out.println(log); file.write(log); DAGraph filter = G.filter(n); String nameFilter = name + "Filter.dot"; filter.save(outputDir + nameFilter); log = "-> Majorants of " + n + " : " + G.majorants(n) + "\n saved as a dagraph in " + nameFilter + "\n"; System.out.println(log); file.write(log); // computes and print the ideals lattice of the dagraph ConceptLattice CSL = ConceptLattice.idealLattice(G); String nameIdealsLattice = name + "IdealsLattice.dot"; CSL.save(outputDir + nameIdealsLattice); log = "-> Ideal lattice saved in " + nameIdealsLattice + "\n"; System.out.println(log + CSL.toString()); file.write(log); // check if the ideals lattice is a lattice log = "-> Check if the ideal lattice is a lattice ? " + CSL.isLattice() + "\n"; System.out.println(log); file.write(log); // print the irreducibles elements of the ideal lattice log = "-> Join irreducibles of ideal lattice: " + CSL.joinIrreducibles() + "\n"; log += "Meet irreducibles of ideal lattice: " + CSL.meetIrreducibles() + "\n"; System.out.println(log); file.write(log); // reduces the ideal lattice by replacing each join irreducible node by one element Lattice L = CSL.getJoinReduction(); String nameReducedLattice = name + "ReducedLattice.dot"; L.save(outputDir + nameReducedLattice); log = "-> Reduced ideal lattice saved in " + nameReducedLattice + "\n"; System.out.println(log + L.toString()); file.write(log); // print the irreducibles elements of the reduces ideal lattice log = "-> Join irreducibles of reduced ideal lattice: " + L.joinIrreducibles() + "\n"; log += "Meet irreducibles of reduced ideal lattice: " + L.meetIrreducibles() + "\n"; System.out.println(log); file.write(log); // computes the table of the reduced lattice Context T = L.getTable(); String nameTable = name + "IrrTable.txt"; T.save(outputDir + nameTable); log = "-> Irreducibles table of the reduced ideal lattice saved in " + nameTable + ":\n " + T.toString(); System.out.println(log); file.write(log); // compute the subgraph of join irreducible nodes DAGraph JIrr = L.joinIrreduciblesSubgraph(); String nameIrrSG = name + "IrrSubgraph.dot"; JIrr.save(outputDir + nameIrrSG); log = "-> Join irreducibles subgraph saved in " + nameIrrSG + "\n"; System.out.println(log + JIrr.toString()); file.write(log); // BIJECTION log = "--- BIJECTION --- \n"; log += "Initial random DAGraph (" + nameGraph + ") isomorphic to\n"; log += "Join irreducible subgraph of its ideal lattice (" + nameIrrSG + ")\n"; System.out.println(log); file.write(log); file.close(); } catch (Exception e) { } }
public String toString(Context ctxt) { if (ctxt == null) return toString(); return ctxt.toString(val, unit); }
public String toString() { return currentContext.toString(); }
public static Object jsConstructor( Context cx, java.lang.Object[] args, Function ctorObj, boolean inNewExpr) throws URISyntaxException { JSURI prop_src_uri = null; URI uri = null; String uri_string = null; String uri_relative = null; Scriptable params = null; if (args.length < 1 || args[0] == Context.getUndefinedValue()) { throw Context.reportRuntimeError("Missing argument"); } // First argument is always the URI if (args.length >= 1 && args[0] != Context.getUndefinedValue()) { if (args[0] instanceof JSURI) { prop_src_uri = (JSURI) args[0]; uri = prop_src_uri.uri; } else if (args[0] instanceof URL) { uri = ((URL) args[0]).toURI(); } else if (args[0] instanceof URI) { uri = (URI) args[0]; } else { uri_string = Context.toString(args[0]); } } // Third argument can only by params if (args.length >= 3 && args[2] != Context.getUndefinedValue()) { params = (Scriptable) args[2]; } // Second argument can be relative URI or params if (args.length >= 2 && args[1] != Context.getUndefinedValue()) { if (args[1] instanceof Scriptable) { if (params != null) { throw Context.reportRuntimeError("Expected a String as second argument."); } params = (Scriptable) args[1]; } else { // args[1] should be resolved against args[0] uri_relative = Context.toString(args[1]); } } if (params != null) { // Replace {...} patterns in string arguments if params was supplied final Scriptable final_params = params; StringUtil.ParamResolver resolver = new StringUtil.ParamResolver() { public String resolveParam(String param) { Object obj; try { obj = final_params.get(Integer.parseInt(param), final_params); } catch (NumberFormatException ex) { obj = final_params.get(param, final_params); } try { String value = Context.toString(obj); return StringUtil.encodeURI(value, false /* == encodeURIComponent() */); } catch (URISyntaxException ex) { throw new WrappedException(ex); } } }; uri_string = StringUtil.format(uri_string, resolver); uri_relative = StringUtil.format(uri_relative, resolver); } if (uri_string != null) { // Resolve URI against current location, if possible JSESXX js_esxx = JSGlobal.getJSESXX(cx, ctorObj); if (js_esxx != null) { prop_src_uri = js_esxx.jsGet_wd(); if (prop_src_uri != null) { uri = resolveURI(prop_src_uri.uri, uri_string); } } if (uri == null) { // Fall back to non-relative uri = new URI(uri_string); } } if (uri_relative != null) { // Resolve relative part against first URI argument uri = resolveURI(uri, uri_relative); } JSURI rc = new JSURI(uri); if (prop_src_uri != null) { // Copy local properties from previous JSURI object for (Object o : prop_src_uri.getIds()) { if (o instanceof String) { String key = (String) o; rc.put(key, rc, prop_src_uri.get(key, prop_src_uri)); } else { int key = (Integer) o; rc.put(key, rc, prop_src_uri.get(key, prop_src_uri)); } } } return rc; }