|
From: <jom...@us...> - 2015-10-16 19:11:55
|
Revision: 1848
http://sourceforge.net/p/jason/svn/1848
Author: jomifred
Date: 2015-10-16 19:11:52 +0000 (Fri, 16 Oct 2015)
Log Message:
-----------
improve create agent (so that jacamo can override it)
Modified Paths:
--------------
trunk/doc/index.html
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSyntax/directives/Include.java
trunk/src/jason/stdlib/create_agent.java
Modified: trunk/doc/index.html
===================================================================
--- trunk/doc/index.html 2015-10-08 17:00:01 UTC (rev 1847)
+++ trunk/doc/index.html 2015-10-16 19:11:52 UTC (rev 1848)
@@ -17,7 +17,7 @@
<li><a href="faq.html">FAQ</a> (html)</li><br/>
-<li><a href="api/jason/stdlib/package-summary.html#package.description">Stantard internal actions</a> (html)</li>
+<li><a href="api/jason/stdlib/package-summary.html#package_description">Stantard internal actions</a> (html)</li>
<li><a href="api/jason/functions/package-summary.html">Stantard arithmetic functions</a> (html)</li>
<li>API of all classes: generated by <a href="api/index.html">JavaDoc</a>.</li><br>
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2015-10-08 17:00:01 UTC (rev 1847)
+++ trunk/src/jason/asSemantics/Agent.java 2015-10-16 19:11:52 UTC (rev 1848)
@@ -455,6 +455,10 @@
return objIA;
}
+ public void setIA(String iaName, InternalAction ia) {
+ internalActions.put(iaName, ia);
+ }
+
public void initDefaultFunctions() {
if (functions == null)
functions = new HashMap<String, ArithFunction>();
Modified: trunk/src/jason/asSyntax/directives/Include.java
===================================================================
--- trunk/src/jason/asSyntax/directives/Include.java 2015-10-08 17:00:01 UTC (rev 1847)
+++ trunk/src/jason/asSyntax/directives/Include.java 2015-10-16 19:11:52 UTC (rev 1848)
@@ -46,7 +46,7 @@
file = checkPathAndFixWithSourcePath(file, aslSourcePath, outerPrefix);
in = new URL(file).openStream();
- } if (outerPrefix.startsWith(CRPrefix)) {
+ } else if (outerPrefix.startsWith(CRPrefix)) {
// outer is loaded from a resource ("application".jar) file, used for java web start
int posSlash = outerPrefix.lastIndexOf("/");
Modified: trunk/src/jason/stdlib/create_agent.java
===================================================================
--- trunk/src/jason/stdlib/create_agent.java 2015-10-08 17:00:01 UTC (rev 1847)
+++ trunk/src/jason/stdlib/create_agent.java 2015-10-16 19:11:52 UTC (rev 1848)
@@ -108,6 +108,37 @@
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
checkArguments(args);
+ String name = getName(args);
+ String source = getSource(args);
+
+ List<String> agArchClasses = getAgArchClasses(args);
+
+ String agClass = null;
+ ClassParameters bbPars = null;
+ if (args.length > 2) { // optional parameter
+ // get the parameters
+ for (Term t: (ListTerm)args[2]) {
+ if (t.isStructure()) {
+ Structure s = (Structure)t;
+ if (s.getFunctor().equals("beliefBaseClass")) {
+ bbPars = new ClassParameters(testString(s.getTerm(0)));
+ } else if (s.getFunctor().equals("agentClass")) {
+ agClass = testString(s.getTerm(0)).toString();
+ }
+ }
+ }
+ }
+ RuntimeServicesInfraTier rs = ts.getUserAgArch().getRuntimeServices();
+ name = rs.createAgent(name, source, agClass, agArchClasses, bbPars, ts.getSettings());
+ rs.startAgent(name);
+
+ if (args[0].isVar())
+ return un.unifies(new StringTermImpl(name), args[0]);
+ else
+ return true;
+ }
+
+ protected String getName(Term[] args) {
String name;
if (args[0].isString())
name = ((StringTerm)args[0]).getString();
@@ -116,7 +147,10 @@
if (args[0].isVar())
name = name.substring(0,1).toLowerCase() + name.substring(1);
-
+ return name;
+ }
+
+ protected String getSource(Term[] args) throws JasonException {
String source = null;
if (args.length > 1) {
@@ -132,33 +166,23 @@
}
source = fSource.getAbsolutePath();
}
-
- String agClass = null;
+ return source;
+ }
+
+ protected List<String> getAgArchClasses(Term[] args) {
List<String> agArchClasses = new ArrayList<String>();
- ClassParameters bbPars = null;
if (args.length > 2) { // optional parameter
// get the parameters
for (Term t: (ListTerm)args[2]) {
if (t.isStructure()) {
Structure s = (Structure)t;
- if (s.getFunctor().equals("beliefBaseClass")) {
- bbPars = new ClassParameters(testString(s.getTerm(0)));
- } else if (s.getFunctor().equals("agentClass")) {
- agClass = testString(s.getTerm(0)).toString();
- } else if (s.getFunctor().equals("agentArchClass")) {
+ if (s.getFunctor().equals("agentArchClass")) {
agArchClasses.add(testString(s.getTerm(0)).toString());
}
}
}
}
- RuntimeServicesInfraTier rs = ts.getUserAgArch().getRuntimeServices();
- name = rs.createAgent(name, source, agClass, agArchClasses, bbPars, ts.getSettings());
- rs.startAgent(name);
-
- if (args[0].isVar())
- return un.unifies(new StringTermImpl(name), args[0]);
- else
- return true;
+ return agArchClasses;
}
private Structure testString(Term t) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|