org.iids.aos.util
Class Jason2ASAgent

java.lang.Object
  extended by org.iids.aos.util.Jason2ASAgent

public class Jason2ASAgent
extends java.lang.Object

Utility class to convert a jason agent (asl file + InternalActions) to a runnable AgentScape agent. This agent is simply a jar file containing the asl file and all classes of the InternalActions and additionally the AgentScapeAgArch agent that reads the asl file and executes it as a Jason agent.

Author:
Reinier Timmer (rjtimmer@cs.vu.nl)

Constructor Summary
Jason2ASAgent()
          Creates a new Class2Jar context.
 
Method Summary
 void addClassesOfDirectory(java.io.File dir, java.lang.String basedir, boolean recurse)
           
 void addJarFile(byte[] b)
           
 void addJarFile(java.io.File jarFile)
           
 void addResource(java.lang.String path, java.io.File contents)
          Put a resource in the jar file.
static java.lang.String getBaseName(java.lang.String name)
           
 java.lang.Iterable<java.io.File> getClasses()
           
 byte[] getJar()
          Generate a JAR file from the classes/main class.
 java.io.File getJarFile()
           
 java.lang.Class getMainClass()
           
 byte[] getManifest()
           
static java.lang.String getPathName(java.lang.Package p)
          Get directory name for a given package
static java.lang.String getPathName(java.lang.String packageName)
           
static java.lang.String getZipFileEntryName(java.lang.Class c)
           
static java.lang.String getZipFileEntryName(java.lang.Package p)
           
static boolean isZipDirectoryEntryName(java.lang.String name)
           
static void main(java.lang.String[] args)
           
static byte[] readFile(java.net.URI file)
          Read a file completely as a byte[].
 void setJarFile(java.io.File jarFile)
           
 void setManifest(byte[] manifest)
           
static void usage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jason2ASAgent

public Jason2ASAgent()
Creates a new Class2Jar context. To generate a Jar file, first add jarfile and/or Directories to the Class2Jar context. Once all desired classes are added, a Jar archive containing only these classes can be obtained by calling the method getJar.

Method Detail

setManifest

public void setManifest(byte[] manifest)

getManifest

public byte[] getManifest()

getJarFile

public java.io.File getJarFile()

setJarFile

public void setJarFile(java.io.File jarFile)

addClassesOfDirectory

public void addClassesOfDirectory(java.io.File dir,
                                  java.lang.String basedir,
                                  boolean recurse)

addJarFile

public void addJarFile(byte[] b)
                throws java.io.IOException
Throws:
java.io.IOException

addJarFile

public void addJarFile(java.io.File jarFile)
                throws java.io.IOException
Throws:
java.io.IOException

getClasses

public java.lang.Iterable<java.io.File> getClasses()

getMainClass

public java.lang.Class getMainClass()

addResource

public void addResource(java.lang.String path,
                        java.io.File contents)
Put a resource in the jar file. The bytes are stored in a specified path (paths separated by forward slashes). In case of relative paths the file is stored in the root.

Parameters:
path - Path name to store the contents in.
contents - file with contents.

getJar

public byte[] getJar()
              throws java.lang.ClassNotFoundException
Generate a JAR file from the classes/main class. This includes generating a manifest file, and copying the bytecode from the classes to the JAR file.

Returns:
A byte[] containing the raw JAR file. This can directly be written to a file, or used to create an agent (code segment).
Throws:
java.lang.ClassNotFoundException - If one or more of the classes entered through cannot be found in the class path.

readFile

public static byte[] readFile(java.net.URI file)
Read a file completely as a byte[].

Note: this may take up a lot of memory for large files. It is better to work with input/output streams or writers for copying file contents.

Parameters:
file - Location of the file to read.
Returns:
The file contents in a byte[]

getBaseName

public static java.lang.String getBaseName(java.lang.String name)

isZipDirectoryEntryName

public static boolean isZipDirectoryEntryName(java.lang.String name)

getZipFileEntryName

public static java.lang.String getZipFileEntryName(java.lang.Class c)

getZipFileEntryName

public static java.lang.String getZipFileEntryName(java.lang.Package p)

getPathName

public static java.lang.String getPathName(java.lang.Package p)
Get directory name for a given package

Parameters:
p - package
Returns:
directory name of package

getPathName

public static java.lang.String getPathName(java.lang.String packageName)

usage

public static void usage()

main

public static void main(java.lang.String[] args)


Copyright © 2003, 2004 IIDS Group. All Rights Reserved.