@Test public void testGetSupportedModel() { ProtocolRoleSimulator sim=new ProtocolRoleSimulator(); String filename="monitor/models/PurchaseGoods.spr"; java.io.InputStream is= ClassLoader.getSystemResourceAsStream(filename); try { SimulationModel simmodel=new SimulationModel(filename, is); Object model=sim.getModel(simmodel,null); if (model == null) { fail("Model is null"); } else if ((model instanceof ProtocolModel) == false) { fail("Model is not a ProtocolModel"); } } catch(Exception e) { fail("Exception occurred: "+e); } }
public Object getModel(SimulationModel model, final ResourceLocator locator) { Object ret=null; if (LOG.isLoggable(Level.FINE)) { LOG.fine("Get model for '"+model.getName()+"'"); } try { java.io.InputStream is=model.getContents(); byte[] b=new byte[is.available()]; is.read(b); is.close(); Content content=new ByteArrayContent(model.getName(), b); CachedJournal journal=new CachedJournal(); org.scribble.common.resource.ResourceLocator res= new org.scribble.common.resource.ResourceLocator() { public URI getResourceURI(String arg0) throws Exception { return locator.getResourceURI(arg0); } }; DefaultProtocolContext context= new DefaultProtocolContext(ProtocolServices.getParserManager(), res); ret = ProtocolServices.getParserManager().parse(context, content, journal); if (journal.hasErrors()) { LOG.severe("Failed to parse model '"+model.getName()+""); journal.apply(new ConsoleJournal()); ret = null; } } catch(Exception e) { LOG.log(Level.SEVERE, "Failed to get model", e); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Returning model for '"+model.getName()+"' = "+ret); } return (ret); }
ProtocolRoleSimulator implements RoleSimulator { public Object getModel(SimulationModel model, final ResourceLocator locator) { Object ret=null; if (LOG.isLoggable(Level.FINE)) { LOG.fine("Get model for '"+model.getName()+"'"); } try { java.io.InputStream is=model.getContents(); byte[] b=new byte[is.available()]; is.read(b); is.close(); Content content=new ByteArrayContent(model.getName(), b); CachedJournal journal=new CachedJournal(); org.scribble.common.resource.ResourceLocator res= new org.scribble.common.resource.ResourceLocator() { public URI getResourceURI(String arg0) throws Exception { return locator.getResourceURI(arg0); } }; DefaultProtocolContext context= new DefaultProtocolContext(ProtocolServices.getParserManager(), res); ret = ProtocolServices.getParserManager().parse(context, content, journal); if (journal.hasErrors()) { LOG.severe("Failed to parse model '"+model.getName()+""); journal.apply(new ConsoleJournal()); ret = null; } } catch(Exception e) { LOG.log(Level.SEVERE, "Failed to get model", e); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Returning model for '"+model.getName()+"' = "+ret); } return (ret); } }
ProtocolRoleSimulator implements RoleSimulator { public Object getModel(SimulationModel model, final ResourceLocator locator) { Object ret=null; if (LOG.isLoggable(Level.FINE)) { LOG.fine("Get model for '"+model.getName()+"'"); } try { java.io.InputStream is=model.getContents(); byte[] b=new byte[is.available()]; is.read(b); is.close(); Content content=new ByteArrayContent(model.getName(), b); CachedJournal journal=new CachedJournal(); org.scribble.common.resource.ResourceLocator res= new org.scribble.common.resource.ResourceLocator() { public URI getResourceURI(String arg0) throws Exception { return locator.getResourceURI(arg0); } }; DefaultProtocolContext context= new DefaultProtocolContext(ProtocolServices.getParserManager(), res); ret = ProtocolServices.getParserManager().parse(context, content, journal); if (journal.hasErrors()) { LOG.severe("Failed to parse model '"+model.getName()+""); journal.apply(new ConsoleJournal()); ret = null; } } catch(Exception e) { LOG.log(Level.SEVERE, "Failed to get model", e); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Returning model for '"+model.getName()+"' = "+ret); } return (ret); }  }
ProtocolRoleSimulator implements RoleSimulator { public Object getModel(SimulationModel model, final ResourceLocator locator) { Object ret=null; if (LOG.isLoggable(Level.FINE)) { LOG.fine("Get model for '"+model.getName()+"'"); } try { java.io.InputStream is=model.getContents(); byte[] b=new byte[is.available()]; is.read(b); is.close(); Content content=new ByteArrayContent(model.getName(), b); CachedJournal journal=new CachedJournal(); org.scribble.common.resource.ResourceLocator res= new org.scribble.common.resource.ResourceLocator() { public URI getResourceURI(String arg0) throws Exception { return locator.getResourceURI(arg0); } }; DefaultProtocolContext context= new DefaultProtocolContext(ProtocolServices.getParserManager(), res); ret = ProtocolServices.getParserManager().parse(context, content, journal); if (journal.hasErrors()) { LOG.severe("Failed to parse model '"+model.getName()+""); journal.apply(new ConsoleJournal()); ret = null; } } catch(Exception e) { LOG.log(Level.SEVERE, "Failed to get model", e); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Returning model for '"+model.getName()+"' = "+ret); } return (ret); }  String getName(); void initialize(SimulationContext context); boolean isSupported(SimulationModel model); Object getModel(SimulationModel model, final ResourceLocator locator); List<Role> getModelRoles(Object model); Object getModelForRole(Object model, Role role, final ResourceLocator locator); void onEvent(SimulationContext context, Event event,
							SimulationHandler handler); void close(SimulationContext context); }
ProtocolRoleSimulator implements RoleSimulator { public Object getModel(SimulationModel model, final ResourceLocator locator) { Object ret=null; if (LOG.isLoggable(Level.FINE)) { LOG.fine("Get model for '"+model.getName()+"'"); } try { java.io.InputStream is=model.getContents(); byte[] b=new byte[is.available()]; is.read(b); is.close(); Content content=new ByteArrayContent(model.getName(), b); CachedJournal journal=new CachedJournal(); org.scribble.common.resource.ResourceLocator res= new org.scribble.common.resource.ResourceLocator() { public URI getResourceURI(String arg0) throws Exception { return locator.getResourceURI(arg0); } }; DefaultProtocolContext context= new DefaultProtocolContext(ProtocolServices.getParserManager(), res); ret = ProtocolServices.getParserManager().parse(context, content, journal); if (journal.hasErrors()) { LOG.severe("Failed to parse model '"+model.getName()+""); journal.apply(new ConsoleJournal()); ret = null; } } catch(Exception e) { LOG.log(Level.SEVERE, "Failed to get model", e); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Returning model for '"+model.getName()+"' = "+ret); } return (ret); }  String getName(); void initialize(SimulationContext context); boolean isSupported(SimulationModel model); Object getModel(SimulationModel model, final ResourceLocator locator); List<Role> getModelRoles(Object model); Object getModelForRole(Object model, Role role, final ResourceLocator locator); void onEvent(SimulationContext context, Event event,
							SimulationHandler handler); void close(SimulationContext context); static final String PROTOCOL_SIMULATOR; }