Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package jason.util;
  
  
  import java.io.File;
  
 
Convert an agent asl code to xml.

Author(s):
Jomi
 
 public class asl2xml  {
 
     public static void main(String[] argsthrows Exception {
         if (args.length != 1) {
             ..println("The asl code file must be informed");
             System.exit(1);
         }
         new asl2xml().run(args[0]);
     }
 
     void run(String filethrows Exception {
         Agent ag = loadAg(file);
         if (ag != null) {
             ..println(transform(ag));
         }
     }
 
     Agent loadAg(String file)  throws Exception {
         Agent ag = new Agent();
         ag.initAg();
         if (ag.parseAS(new File(file))) {
             ag.setASLSrc(file);
             ag.addInitialBelsInBB();
             return ag;
         } else {
             return null;
         }
     }
 
     public String transform(String agCodethrows Exception {
         jason.asSyntax.parser.as2j parser = new jason.asSyntax.parser.as2j(new StringReader(agCode));
         Agent ag = new Agent();
         ag.initAg();
         parser.agent(ag);
         return transform(ag.getAgProgram());
     }
     
     public String transform(Agent ag)  throws Exception {
         return transform(ag.getAgProgram());
     }
 
     public String transform(Document agState)  throws Exception {
         StringWriter so = new StringWriter();
         getTransformer().transform(new DOMSource(agState), new StreamResult(so));
         return so.toString();
     }
 
     protected Transformer transCache = null;
     public Transformer getTransformer()  throws Exception {
         if ( == null) {
              = getFactory().newTransformer();
             .setOutputProperty(."yes");
         }
         return ;
     }
 
     
     TransformerFactory fac = null;
     TransformerFactory getFactory() throws Exception {
         if ( == null) {
              = TransformerFactory.newInstance();
             .setURIResolver(new URIResolver() {
                 public Source resolve(String hrefString basethrows TransformerException {
                     try {
                         return new StreamSource(asl2xml.class.getResource("/xml/" + href).openStream());
                     } catch (Exception e) {
                         ..println("Error - " + href + "-" + base);
                         e.printStackTrace();
                         return null;
                     }
                 }
             });
        }
        return ;
    }
New to GrepCode? Check out our FAQ X