1 package org.jbpm.identity.ant; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.FileNotFoundException ; 6 7 import org.apache.tools.ant.BuildException; 8 import org.apache.tools.ant.Task; 9 import org.hibernate.Session; 10 import org.jbpm.ant.AntTaskJbpmSessionFactory; 11 import org.jbpm.db.JbpmSession; 12 import org.jbpm.db.JbpmSessionFactory; 13 import org.jbpm.identity.Entity; 14 import org.jbpm.identity.hibernate.IdentitySession; 15 import org.jbpm.identity.xml.IdentityXmlParser; 16 17 public class LoadIdentitiesTask extends Task { 18 19 private String file = null; 20 private String cfg = null; 21 private String properties = null; 22 23 public void execute() throws BuildException { 24 JbpmSessionFactory jbpmSessionFactory = AntTaskJbpmSessionFactory.getJbpmSessionFactory(cfg,properties); 26 27 if (file==null) throw new BuildException("no file specified in the loadidentities task"); 29 30 log( "loading identities from "+file+" ..." ); 31 File identitiesFile = new File (file); 32 FileInputStream fileInputStream = null; 33 try { 34 fileInputStream = new FileInputStream (identitiesFile); 35 } catch (FileNotFoundException e) { 36 throw new BuildException("identities file '"+file+"' not found"); 37 } 38 Entity[] entities = IdentityXmlParser.parseEntitiesResource(fileInputStream); 39 40 JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSessionAndBeginTransaction(); 41 Session session = jbpmSession.getSession(); 42 IdentitySession identitySession = new IdentitySession(session); 43 try { 44 for (int i=0; i<entities.length; i++) { 45 identitySession.saveEntity(entities[i]); 46 } 47 } finally { 48 jbpmSession.commitTransactionAndClose(); 49 } 50 } 51 52 public void setFile(String file) { 53 this.file = file; 54 } 55 public void setCfg(String cfg) { 56 this.cfg = cfg; 57 } 58 public void setProperties(String properties) { 59 this.properties = properties; 60 } 61 } 62 | Popular Tags |