/** Generate detail HTML code for the given elements. */ protected void generateDetails(StringBuffer buf, String type, Set elements) { if (!elements.isEmpty()) { buf.append("<h4>"); buf.append(type); buf.append(" details</h4>\n<ul>\n"); for (Iterator it = elements.iterator(); it.hasNext(); ) { Object obj = it.next(); String name = getObjectName(obj); buf.append("<li><a name=\""); buf.append(SUtil.makeConform(name)); buf.append("\">"); buf.append(SUtil.makeConform(name)); // Add name of configuration (hack???) // if(elements[i] instanceof IMConfigElement) // { // MElement owner = (MElement)elements[i]; // while(owner!=null && !(owner instanceof IMConfiguration)) // owner = owner.getOwner(); // if(owner!=null) // buf.append(" in "); // buf.append(SUtil.makeConform(""+owner)); // } buf.append("</a> errors:\n"); Tuple[] errors = getElementErrors(obj); buf.append("<dl>\n"); for (int j = 0; j < errors.length; j++) { Object obj2 = getObject(errors[j]); if (!obj.equals(obj2)) { buf.append("<dt>"); buf.append(getObjectName(obj2)); buf.append("</dt>\n"); } // SourceLocation loc = errors[j].getSourceLocation(); // if(loc!=null) // { // buf.append(" ("); // buf.append(loc.getFilename()); // buf.append(": line "); // buf.append(loc.getLineNumber()); // buf.append(", column "); // buf.append(loc.getColumnNumber()); // buf.append(")"); // } String[] msgs = getMessages(errors[j]); buf.append("<dd>"); for (int k = 0; k < msgs.length; k++) { buf.append(msgs[k]); buf.append("\n"); if (msgs.length > 1 && k != msgs.length - 1) buf.append("<br>"); } buf.append("</dd>\n"); } buf.append("</dl>\n</li>\n"); } buf.append("</ul>\n"); } }
/** Generate a string representation of the report. */ protected String generateErrorText() { StringBuffer buf = new StringBuffer(); buf.append("Report for "); buf.append(name); buf.append("\n"); if (filename != null) { buf.append("File: "); buf.append(filename); buf.append("\n"); } buf.append("\n"); Tuple[] elements = getElements(); for (int i = 0; i < elements.length; i++) { Object obj = getObject(elements[i]); if (obj != null) { String name = getObjectName(obj); name = name.replace("\n", " "); buf.append(name); buf.append(":\n"); } else { buf.append("Errors:\n"); } String[] messages = getMessages(elements[i]); for (int j = 0; j < messages.length; j++) { buf.append("\t"); buf.append(messages[j]); buf.append("\n"); } } return SUtil.stripTags(buf.toString()); }
/** Generate overview HTML code for the given elements. */ protected void generateOverview(StringBuffer buf, String type, Set elements) { if (!elements.isEmpty()) { buf.append("<li>"); buf.append(type); buf.append(" errors\n<ul>\n"); for (Iterator it = elements.iterator(); it.hasNext(); ) { Object obj = it.next(); String name = getObjectName(obj); buf.append("<li><a href=\"#"); buf.append(SUtil.makeConform(name)); buf.append("\">"); buf.append(SUtil.makeConform(name)); buf.append("</a> has errors.</li>\n"); } buf.append("</ul>\n</li>\n"); } }
/** Get the filename. */ public URL getFilenameUrl() { URL ret = null; try { // ResourceInfo rinfo = SUtil.getResourceInfo0("jadex/examples/alarmclock/alarm.mp3"); ResourceInfo rinfo = SUtil.getResourceInfo0(getFilename(), Alarm.class.getClassLoader()); if (rinfo == null) { System.out.println("Resource not found: " + getFilename()); } else { if (rinfo.getInputStream() != null) { rinfo.getInputStream().close(); } String file = rinfo.getFilename(); if (!file.startsWith("jar:")) { file = (file.startsWith("/") ? "file://" : "file:///") + file; } // System.out.println(file); ret = new URL(file); } } catch (Exception e) { e.printStackTrace(); } return ret; }
/** * Test initiating a contract net interaction with given settings. * * @param executeall True, if all acceptable proposals should be executed. * @param cfp_info Use given cfp info (e.g. for default plans) */ protected void performTest(String name, String description, boolean executeall, Object cfp_info) { // Create 3 participants with different offers. Map[] args = new Map[] {new HashMap(), new HashMap(), new HashMap()}; args[0].put("offer", new Integer(5)); args[0].put("execute", Boolean.TRUE); args[1].put("offer", new Integer(1)); args[1].put("execute", Boolean.TRUE); args[2].put("offer", new Integer(7)); args[2].put( "execute", new Boolean( executeall)); // Fails when only one is needed, to check if proposal 5 gets executed. List agents = createAgents("/jadex/bdi/testcases/planlib/ICNPReceiver.agent.xml", args); TestReport tr = new TestReport(name, description); if (assureTest(tr)) { try { IGoal cnpini = createGoal("cnpcap.icnp_initiate"); cnpini .getParameterSet("receivers") .addValues(agents.toArray(new IComponentIdentifier[agents.size()])); cnpini.getParameter("cfp").setValue("CFP for a task."); cnpini.getParameter("cfp_info").setValue(cfp_info); cnpini.getParameter("executeall").setValue(new Boolean(executeall)); dispatchSubgoalAndWait(cnpini); getLogger() .info( "CNP result:" + SUtil.arrayToString(cnpini.getParameterSet("result").getValues())); // Check for correct number of negotiation rounds. NegotiationRecord[] history = (NegotiationRecord[]) cnpini.getParameterSet("history").getValues(); if (history.length == 4) // 3 rounds + execution. { // Check final proposals executed in last round. ParticipantProposal[] finalproposals = history[history.length - 1].getProposals(); if (executeall) { // Check number of proposals. if (finalproposals.length == 2) { // Check values of proposals. if (((Number) finalproposals[0].getProposal()).intValue() == 7 && ((Number) finalproposals[1].getProposal()).intValue() == 5) { // For executeall, both evaluation values should be success. if ("success".equals(finalproposals[0].getEvaluation()) && "success".equals(finalproposals[1].getEvaluation())) { tr.setSucceeded(true); } else { tr.setFailed( "Wrong evaluations for accepted proposals: " + SUtil.arrayToString(finalproposals)); } } else { tr.setFailed( "Wrong values for accepted proposals: " + SUtil.arrayToString(finalproposals)); } } else { tr.setFailed( "Wrong number of accepted proposals: " + SUtil.arrayToString(finalproposals)); } } else { // Check number of proposals. if (finalproposals.length == 1) { // Check values of proposals. if (((Number) finalproposals[0].getProposal()).intValue() == 5) { // For not executeall, evaluation value should be success. if ("success".equals(finalproposals[0].getEvaluation())) { tr.setSucceeded(true); } else { tr.setFailed( "Wrong evaluations for accepted proposals: " + SUtil.arrayToString(finalproposals)); } } else { tr.setFailed( "Wrong values for accepted proposals: " + SUtil.arrayToString(finalproposals)); } } else { tr.setFailed( "Wrong number of accepted proposals: " + SUtil.arrayToString(finalproposals)); } } } else { tr.setFailed("Wrong number of negotiation rounds: " + history.length); } } catch (GoalFailureException e) { tr.setFailed("Exception occurred: " + e); } } // Destroy agents first, as setting report might abort plan unexpectedly. destroyAgents(); getBeliefbase().getBeliefSet("testcap.reports").addFact(tr); }
/** * Add an array of message to the table. * * @param messages The Array of messages to add. */ public void addMessages(Message[] messages) { this.messages.addAll(SUtil.arrayToList(messages)); fireTableDataChanged(); }