[jbpm-commits] JBoss JBPM SVN: r6252 - in jbpm3/branches/jbpm-3.2-soa/modules: core/src/main/java/org/jbpm/jpdl/convert and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Apr 7 07:39:26 EDT 2010
Author: alex.guizar at jboss.com
Date: 2010-04-07 07:39:24 -0400 (Wed, 07 Apr 2010)
New Revision: 6252
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/convert/Converter.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/mail/Mail.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/MailTest.java
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/IntegrationTestSetup.java
Log:
replace StringTokenizer occurrences with String.split
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java 2010-04-07 10:02:00 UTC (rev 6251)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/calendar/Day.java 2010-04-07 11:39:24 UTC (rev 6252)
@@ -57,7 +57,7 @@
public Day(String dayPartsText, DateFormat dateFormat, BusinessCalendar businessCalendar) {
this.businessCalendar = businessCalendar;
- String[] dayPartTexts = dayPartsText.split("[\\s\\&]+");
+ String[] dayPartTexts = dayPartsText.split("[\\s&]+");
if (dayPartTexts.length > 1 || dayPartTexts[0].length() > 0) {
dayParts = new DayPart[dayPartTexts.length];
for (int i = 0; i < dayParts.length; i++) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/convert/Converter.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/convert/Converter.java 2010-04-07 10:02:00 UTC (rev 6251)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/jpdl/convert/Converter.java 2010-04-07 11:39:24 UTC (rev 6252)
@@ -50,159 +50,127 @@
public class Converter {
private static final String STYLESHEET_NAME = "convert-pdl-2.0-to-3.0.xslt";
-
+
File indir;
File outdir;
-
- public Document convert(Document document)
- throws Exception {
+ public Document convert(Document document) throws Exception {
// load the transformer using JAXP
TransformerFactory factory = TransformerFactory.newInstance();
- Transformer transformer = factory.newTransformer(
- new StreamSource( this.getClass().getResourceAsStream( STYLESHEET_NAME ) ) );
+ Transformer transformer = factory.newTransformer(new StreamSource(this.getClass()
+ .getResourceAsStream(STYLESHEET_NAME)));
// apply the conversion stylesheet to the incoming process definition
- DocumentSource source = new DocumentSource( document );
+ DocumentSource source = new DocumentSource(document);
DocumentResult result = new DocumentResult();
- transformer.transform( source, result );
+ transformer.transform(source, result);
// return the transformed document
-
return result.getDocument();
}
-
+
public String convertPar(ProcessArchive pa) {
-
- try
- {
- // Parse the process definition XML into a DOM document
- Document doc =
- DocumentHelper.parseText(
- new String( pa.getEntry("processdefinition.xml") ) );
-
- // Convert from 2.0 to 3.0 PDL
- Document doc30 = convert(doc);
-
- // Serialize the resulting document as the result
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- serializetoXML( bos, doc30) ;
-
- return bos.toString();
-
- }
- catch(DocumentException de)
- {
- log.error("Conversion had trouble parsing the 2.0 process definition", de);
- }
- catch(Exception ex)
- {
- log.error("Unexpected error in conversion", ex);
- }
-
- return null; // things did not go well
+ try {
+ // Parse the process definition XML into a DOM document
+ Document doc = DocumentHelper.parseText(new String(pa.getEntry("processdefinition.xml")));
+
+ // Convert from 2.0 to 3.0 PDL
+ Document doc30 = convert(doc);
+
+ // Serialize the resulting document as the result
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ serializetoXML(bos, doc30);
+
+ return bos.toString();
+ }
+ catch (DocumentException de) {
+ log.error("Conversion had trouble parsing the 2.0 process definition", de);
+ }
+ catch (Exception ex) {
+ log.error("Unexpected error in conversion", ex);
+ }
+
+ // things did not go well
+ return null;
}
-
- public void serializetoXML(OutputStream out, Document document)
- throws Exception {
-
- OutputFormat outformat = OutputFormat.createPrettyPrint();
- //outformat.setEncoding(aEncodingScheme);
- XMLWriter writer = new XMLWriter(out, outformat);
- writer.write( document );
- writer.flush();
+
+ public void serializetoXML(OutputStream out, Document document) throws Exception {
+ OutputFormat outformat = OutputFormat.createPrettyPrint();
+ // outformat.setEncoding(aEncodingScheme);
+ XMLWriter writer = new XMLWriter(out, outformat);
+ writer.write(document);
+ writer.flush();
}
-
- public static void main(String[] args)
- throws Exception
- {
-
- Converter converter = new Converter();
-
- if (!converter.parse(args)){
- System.err.println();
- System.err.println("Usage: java -jar converter.jar input-directory output-directory\n\n" +
- "input-directory is the directory where you have 2.0 process archives (*.par)\n" +
- "The converted process files will be placed in the output-directory");
- System.exit(1);
- }
+ public static void main(String[] args) throws Exception {
+ Converter converter = new Converter();
- converter.convertPars();
-
+ if (!converter.parse(args)) {
+ System.err.println();
+ System.err.println("Usage: java -jar converter.jar input-directory output-directory\n\n"
+ + "input-directory is the directory where you have 2.0 process archives (*.par)\n"
+ + "The converted process files will be placed in the output-directory");
+ System.exit(1);
+ }
+
+ converter.convertPars();
}
-
- boolean parse(String[] args){
-
- if (args.length != 2)
- return false;
-
- // Check for valid input and output directories
- indir = new File( args[0] );
- if (!indir.isDirectory())
- {
- System.err.println("Input file " + args[0] + " is not a valid directory name.");
- return false;
- }
-
- outdir = new File( args[1] );
- if (!outdir.isDirectory())
- {
- System.err.println("Output file " + args[1] + " is not a valid directory name.");
- return false;
- }
-
- return true;
+
+ boolean parse(String[] args) {
+ if (args.length != 2) return false;
+
+ // Check for valid input and output directories
+ indir = new File(args[0]);
+ if (!indir.isDirectory()) {
+ System.err.println("Input file " + args[0] + " is not a valid directory name.");
+ return false;
+ }
+
+ outdir = new File(args[1]);
+ if (!outdir.isDirectory()) {
+ System.err.println("Output file " + args[1] + " is not a valid directory name.");
+ return false;
+ }
+
+ return true;
}
-
+
void convertPars() throws Exception {
-
- String[] files = indir.list( new FilenameFilter() {
- public boolean accept(File dir, String name){
- return name.toLowerCase().endsWith(".par");
- }
- });
+ String[] files = indir.list(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.toLowerCase().endsWith(".par");
+ }
+ });
- for (int i = 0; i < files.length; i++)
- {
- ZipInputStream zip = new ZipInputStream(
- new FileInputStream(
- indir.getPath() + "/" + files[i]));
-
- ProcessArchive pa = new ProcessArchive(zip);
-
- String xml = convertPar( pa );
-
- // Create new process archive in designated output directory
- ZipOutputStream zippo = new ZipOutputStream(
- new FileOutputStream(
- outdir.getPath() + "/" + files[i] ));
-
- // Copy all non-pdl entries and insert new pdl
-
- for (Iterator iter = pa.getEntries().keySet().iterator(); iter.hasNext(); )
- {
- String name = (String) iter.next();
-
- zippo.putNextEntry( new ZipEntry( name ) );
- if ("processdefinition.xml".equalsIgnoreCase(name))
- {
- zippo.write( xml.getBytes( ) );
- }
- else
- {
- zippo.write( pa.getEntry(name) );
- }
-
- zippo.closeEntry();
- }
-
- zippo.close();
-
- System.out.println("Converted " + files[i]);
-
- } // process next PAR
+ for (int i = 0; i < files.length; i++) {
+ ZipInputStream zip = new ZipInputStream(new FileInputStream(indir.getPath() + "/"
+ + files[i]));
+ ProcessArchive pa = new ProcessArchive(zip);
+ String xml = convertPar(pa);
+
+ // Create new process archive in designated output directory
+ ZipOutputStream zippo = new ZipOutputStream(new FileOutputStream(outdir.getPath() + "/"
+ + files[i]));
+
+ // Copy all non-pdl entries and insert new pdl
+ for (Iterator iter = pa.getEntries().keySet().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+
+ zippo.putNextEntry(new ZipEntry(name));
+ if ("processdefinition.xml".equalsIgnoreCase(name)) {
+ zippo.write(xml.getBytes());
+ }
+ else {
+ zippo.write(pa.getEntry(name));
+ }
+
+ zippo.closeEntry();
+ }
+
+ zippo.close();
+ System.out.println("Converted " + files[i]);
+ } // process next PAR
}
-
+
private static final Log log = LogFactory.getLog(Converter.class);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/mail/Mail.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/mail/Mail.java 2010-04-07 10:02:00 UTC (rev 6251)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/mail/Mail.java 2010-04-07 11:39:24 UTC (rev 6252)
@@ -11,7 +11,6 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.StringTokenizer;
import javax.mail.Message;
import javax.mail.MessagingException;
@@ -58,7 +57,7 @@
}
public Mail(String template, String actors, String to, String bccActors, String bcc,
- String subject, String text) {
+ String subject, String text) {
this.template = template;
this.actors = actors;
this.to = to;
@@ -152,49 +151,44 @@
}
public static void send(Properties mailServerProperties, String fromAddress, List recipients,
- String subject, String text) {
+ String subject, String text) {
send(mailServerProperties, fromAddress, recipients, null, subject, text);
}
public static void send(Properties mailServerProperties, String fromAddress, List recipients,
- List bccRecipients, String subject, String text) {
- if ((recipients == null || recipients.isEmpty()) &&
- (bccRecipients == null || bccRecipients.isEmpty())) {
+ List bccRecipients, String subject, String text) {
+ if ((recipients == null || recipients.isEmpty())
+ && (bccRecipients == null || bccRecipients.isEmpty())) {
log.debug("skipping mail because there are no recipients");
return;
}
- try {
- int retries = 5;
- while (0 < retries) {
- retries--;
- try {
- sendMailInternal(mailServerProperties, fromAddress, recipients, bccRecipients, subject, text);
- break;
- }
- catch (MessagingException msgex) {
- if (retries == 0) throw msgex;
+ for (int retries = 5;; retries--) {
+ try {
+ sendMailInternal(mailServerProperties, fromAddress, recipients, bccRecipients, subject, text);
+ break;
+ }
+ catch (MessagingException msgex) {
+ if (retries == 0) throw new JbpmException("cannot send email", msgex);
- System.out.println("Cannot send mail, now retrying: " + msgex);
- log.error("Cannot send mail, now retrying: " + msgex);
+ log.error("cannot send mail (" + retries + " retries left): " + msgex.getMessage());
+ try {
Thread.sleep(1000);
}
+ catch (InterruptedException e) {
+ // reassert interruption
+ Thread.currentThread().interrupt();
+ throw new JbpmException("cannot send email", msgex);
+ }
}
}
- catch (Exception e) {
- throw new JbpmException("Cannot send email", e);
- }
}
private static void sendMailInternal(Properties mailServerProperties, String fromAddress,
- List recipients, List bccRecipients, String subject, String text) throws Exception {
- log.debug("sending email to '" +
- recipients +
- "' " +
- (bccRecipients != null ? "and in bcc to '" + bccRecipients + "' " : "") +
- "about '" +
- subject +
- "'");
+ List recipients, List bccRecipients, String subject, String text) throws MessagingException {
+ log.debug("sending email to '" + recipients + "' "
+ + (bccRecipients != null ? "and in bcc to '" + bccRecipients + "' " : "") + "about '"
+ + subject + "'");
Session session = Session.getDefaultInstance(mailServerProperties, null);
MimeMessage message = new MimeMessage(session);
if (fromAddress != null) {
@@ -224,21 +218,15 @@
}
protected List tokenize(String text) {
- if (text == null) {
- return null;
- }
- List list = new ArrayList();
- StringTokenizer tokenizer = new StringTokenizer(text, ";:");
- while (tokenizer.hasMoreTokens()) {
- list.add(tokenizer.nextToken());
- }
- return list;
+ if (text == null) return null;
+
+ String[] tokens = text.split("[;:]+");
+ return Arrays.asList(tokens);
}
protected Collection resolveAddresses(List actorIds) {
List emailAddresses = new ArrayList();
- Iterator iter = actorIds.iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = actorIds.iterator(); iter.hasNext();) {
String actorId = (String) iter.next();
AddressResolver addressResolver = (AddressResolver) JbpmConfiguration.Configs.getObject("jbpm.mail.address.resolver");
Object resolvedAddresses = addressResolver.resolveAddress(actorId);
@@ -253,12 +241,9 @@
emailAddresses.addAll(Arrays.asList((String[]) resolvedAddresses));
}
else {
- throw new JbpmException("Address resolver '" +
- addressResolver +
- "' returned '" +
- resolvedAddresses.getClass().getName() +
- "' instead of a String, Collection or String-array: " +
- resolvedAddresses);
+ throw new JbpmException("Address resolver '" + addressResolver + "' returned '"
+ + resolvedAddresses.getClass().getName()
+ + "' instead of a String, Collection or String-array: " + resolvedAddresses);
}
}
}
@@ -276,9 +261,8 @@
}
catch (Exception e) {
throw new JbpmException(
- "couldn't get configuration properties for jbpm mail server from resource '" +
- mailServerPropertiesResource +
- "'", e);
+ "could not get configuration properties for jbpm mail server from resource '"
+ + mailServerPropertiesResource + "'", e);
}
}
else if (JbpmConfiguration.Configs.hasObject("jbpm.mail.smtp.host")) {
@@ -300,7 +284,7 @@
templates = new HashMap();
String mailTemplatesResource = JbpmConfiguration.Configs.getString("resource.mail.templates");
org.w3c.dom.Element mailTemplatesElement = XmlUtil.parseXmlResource(mailTemplatesResource, false)
- .getDocumentElement();
+ .getDocumentElement();
List mailTemplateElements = XmlUtil.elements(mailTemplatesElement, "mail-template");
for (Iterator iter = mailTemplateElements.iterator(); iter.hasNext();) {
org.w3c.dom.Element mailTemplateElement = (org.w3c.dom.Element) iter.next();
@@ -327,7 +311,7 @@
}
void addTemplateProperty(org.w3c.dom.Element mailTemplateElement, String property,
- Properties templateProperties) {
+ Properties templateProperties) {
org.w3c.dom.Element element = XmlUtil.element(mailTemplateElement, property);
if (element != null) {
templateProperties.put(property, XmlUtil.getContentText(element));
@@ -363,5 +347,5 @@
}
}
- private static Log log = LogFactory.getLog(Mail.class);
+ private static final Log log = LogFactory.getLog(Mail.class);
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java 2010-04-07 10:02:00 UTC (rev 6251)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java 2010-04-07 11:39:24 UTC (rev 6252)
@@ -28,10 +28,8 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.StringTokenizer;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmException;
@@ -311,12 +309,11 @@
pooledActors = (String[]) collection.toArray(new String[collection.size()]);
}
else if (result instanceof String) {
- List pooledActorList = new ArrayList();
- StringTokenizer tokenizer = new StringTokenizer((String) result, ",");
- while (tokenizer.hasMoreTokens()) {
- pooledActorList.add(tokenizer.nextToken().trim());
+ String csv = (String) result;
+ pooledActors = csv.split(",");
+ for (int i = 0; i < pooledActors.length; i++) {
+ pooledActors[i] = pooledActors[i].trim();
}
- pooledActors = (String[]) pooledActorList.toArray(new String[pooledActorList.size()]);
}
else {
throw new JbpmException("pooled-actors expression '"
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/MailTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/MailTest.java 2010-04-07 10:02:00 UTC (rev 6251)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/mail/MailTest.java 2010-04-07 11:39:24 UTC (rev 6252)
@@ -260,7 +260,7 @@
"<process-definition>" +
" <start-state>" +
" <transition to='end'>" +
- " <mail name='send email' to='george at humpydumpy.gov; spiderman at hollywood.ca.us'" +
+ " <mail name='send email' to='george at humpydumpy.gov: spiderman at hollywood.ca.us'" +
" subject='readmylips' text='nomoretaxes' />" +
" </transition>" +
" </start-state>" +
Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/IntegrationTestSetup.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/IntegrationTestSetup.java 2010-04-07 10:02:00 UTC (rev 6251)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/IntegrationTestSetup.java 2010-04-07 11:39:24 UTC (rev 6252)
@@ -27,7 +27,6 @@
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
-import java.util.StringTokenizer;
import javax.management.MBeanServerConnection;
@@ -43,12 +42,12 @@
public class IntegrationTestSetup extends TestSetup {
private IntegrationTestHelper delegate = new IntegrationTestHelper();
- private String[] archives = new String[0];
+ private String[] archives;
private ClassLoader originalClassLoader;
public IntegrationTestSetup(Class testClass, String archiveList) {
super(new TestSuite(testClass));
- getArchiveArray(archiveList);
+ archives = getArchiveArray(archiveList);
}
public File getArchiveFile(String archive) {
@@ -63,14 +62,8 @@
return delegate.getServer();
}
- private void getArchiveArray(String archiveList) {
- if (archiveList != null) {
- StringTokenizer st = new StringTokenizer(archiveList, ", ");
- archives = new String[st.countTokens()];
-
- for (int i = 0; i < archives.length; i++)
- archives[i] = st.nextToken();
- }
+ private String[] getArchiveArray(String archiveList) {
+ return archiveList == null ? new String[0] : archiveList.split("[\\s,]+");
}
protected void setUp() throws Exception {
More information about the jbpm-commits
mailing list