Skip to content

Commit

Permalink
Added code that runs in IDEA, remains to add maven configuration for …
Browse files Browse the repository at this point in the history
…running tests, adding guibuilder .forms specific generated code, and packaging an executable jar.
  • Loading branch information
kenglxn committed Aug 19, 2010
1 parent 7ae14e0 commit 4164296
Show file tree
Hide file tree
Showing 5 changed files with 417 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pom.xml
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>JMSUtility</groupId>
<artifactId>JMSUtility</artifactId>
<version>1.0</version>


<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.3.0</version>
</dependency>

<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>5.0</version>
</dependency>
<!-- TEST SCOPE -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
150 changes: 150 additions & 0 deletions src/main/java/net/glxn/jmsutility/JMSUtility.form
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.glxn.jmsutility.JMSUtility">
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="379"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="e994d" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="53d9d"/>
<text value="Queue Destination"/>
</properties>
</component>
<component id="53d9d" class="javax.swing.JTextField" binding="queueDestinationTextField" default-binding="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="13596" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="f8f71"/>
<text value="JMS Server URL"/>
</properties>
</component>
<component id="f8f71" class="javax.swing.JTextField" binding="jmsServerUrl" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="tcp://localhost:61616"/>
</properties>
</component>
<component id="68131" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="661a0"/>
<text value="# Messages"/>
</properties>
</component>
<component id="661a0" class="javax.swing.JTextField" binding="messagesTextField" default-binding="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="1"/>
</properties>
</component>
<component id="7f892" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="46" height="121"/>
</grid>
</constraints>
<properties>
<labelFor value="c864"/>
<text value="Message"/>
</properties>
</component>
<scrollpane id="9a6a6">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="6" height="121"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="c864" class="javax.swing.JTextPane" binding="messageTextPane" default-binding="true">
<constraints/>
<properties>
<text value=""/>
</properties>
</component>
</children>
</scrollpane>
<component id="4330" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="75" height="130"/>
</grid>
</constraints>
<properties>
<labelFor value="9a5f0"/>
<text value="Parameter List"/>
</properties>
</component>
<scrollpane id="1a33c">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="6" height="130"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="9a5f0" class="javax.swing.JTextPane" binding="parameterListTextPane" default-binding="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<grid id="52cbb" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="771c1" class="javax.swing.JButton" binding="sendMessageSButton" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Send message(s)"/>
</properties>
</component>
<component id="5d87c" class="javax.swing.JButton" binding="helpButton" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Help!"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
159 changes: 159 additions & 0 deletions src/main/java/net/glxn/jmsutility/JMSUtility.java
@@ -0,0 +1,159 @@
package net.glxn.jmsutility;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JMSUtility extends Component {
private JPanel panel1;
protected JTextField jmsServerUrl;
protected JTextField queueDestinationTextField;
protected JTextField messagesTextField;
protected JTextPane messageTextPane;
protected JTextPane parameterListTextPane;
private JButton sendMessageSButton;
private JButton helpButton;
private int parameters;
private String[] parameterValues;
private Integer numberOfMessagesToSend;

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}

private static void createAndShowGUI() {
JFrame frame = new JFrame("JMSUtilForm");
frame.setContentPane(new JMSUtility().panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}

public JMSUtility() {
helpButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
showHelpDialog();
} catch (Exception ex) {
showErrorPane(ex.getMessage(), ExceptionUtils.getFullStackTrace(ex));
}
}
});
sendMessageSButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
validateInputFields();
// sendMessage();
} catch (Exception ex) {
showErrorPane(ex.getMessage(), ExceptionUtils.getFullStackTrace(ex));
}
}
});
}

protected void validateInputFields() {
if (!jmsServerUrl.getText().matches("\\w{2,5}://\\w*:\\d{2,6}")) {
showErrorPane("input validation error", "JMS Server URL is not a valid URL. " +
"\n\n should be: [protocol]://[host]:[port]" +
"\n example: tcp://localhost:61616");
}
if (StringUtils.isBlank(queueDestinationTextField.getText())) {
showErrorPane("input validation error", "You must supply a Queue destination");
}
if (!StringUtils.isNumeric(messagesTextField.getText())) {
showErrorPane("input validation error", "Number of messages must be a number");
}
if (StringUtils.isBlank(messageTextPane.getText())) {
showErrorPane("input validation error", "Message can not be blank");
}
parameters = numberOfParametersInText(messageTextPane.getText());
parameterValues = StringUtils.split(parameterListTextPane.getText(), "\n");
if (parameters > 0 && parameterValues.length == 0) {
showErrorPane("input validation error", "You have supplied a parameterized message but no parameters. " +
"\n\nPlease see the Help! dialog.");
}
if (parameters == 0 && parameterValues.length > 0) {
showErrorPane("input validation error", "You have supplied parameters to a message that has no placeholders." +
"\n\nPlease see the Help! dialog.");
}
if (parameters > 1) {
boolean parameterNumberOfFieldsMismatch = false;
for (String parameterValue : parameterValues) {
int numberOfFieldsInParameterValue = StringUtils.countMatches(parameterValue, "|");
if (numberOfFieldsInParameterValue != (parameters - 1)) {
parameterNumberOfFieldsMismatch = true;
}
}
if (parameterNumberOfFieldsMismatch) {
showErrorPane("input validation error", "Your parameter list contains at least one entry that does not " +
"satisfy the parameterized message." +
"\n\nPlease see the Help! dialog.");
}
}
}

int numberOfParametersInText(String text) {
return StringUtils.countMatches(text, "%s");
}

private void sendMessage() {
LogWindow logWindow = new LogWindow(panel1.getX() + panel1.getWidth() + 25, panel1.getY());
if (parameterValues.length > 0) {
logWindow.log("Sending messages for parameters in list. \nTotal number of messages to send=" + parameterValues.length);

//TODO, iterate list of parameters and create message merging in the value in the message and send message

} else {
numberOfMessagesToSend = Integer.valueOf(messagesTextField.getText());
logWindow.log("Sending " + numberOfMessagesToSend + " message(s)");

//TODO, send numberOfMessagesToSend number of messages using only the message field

}
}

private void showHelpDialog() {
String message = "This tool let's you send a JMS messsage to a queue. " +
"\nSupply the input fields with correct values and click send button." +
"\n\nThere is a special feature for the message and parameter list input fields." +
"\nThese fields work together, so if you supply the message with a placeholder, namely %s, " +
"\nthen the tool will attempt to fill the placeholder with values from the parameter list. If you have one %s in you message, " +
"\nthen you can send several messages with each message being given a new value for %s with the next value in the list. " +
"\nThe parameter list entries need to be separated by a carriage return/new line feed. " +
"\n------" +
"\nExample parameter list for input with one %s:" +
"\nparam1" +
"\nparam2" +
"\nparam3" +
"\n------" +
"\nIf you have more than one placeholder, then the values should be separated by a pipe (|) in the parameter list. " +
"\nSo message 'hello %s %s' could be given the parameter list 'mr|duke' and the resulting message would be 'hello mr duke'." +
"\n------" +
"\nExample parameter list for input with two %s:" +
"\nmr|duke" +
"\nms|daisy" +
"\nmrs|robinson" +
"\n------" +
"\nIf you have given the number of messages when using parameter list, the number of messages to send will be ignored " +
"\nand messages will be sent for entire parameter list";
JOptionPane pane = new JOptionPane(message, JOptionPane.INFORMATION_MESSAGE);
JDialog dialog = pane.createDialog(this, "Help!");
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
}

protected void showErrorPane(String title, String msg) {
JOptionPane pane = new JOptionPane(msg, JOptionPane.ERROR_MESSAGE);
JDialog dialog = pane.createDialog("Application says: " + title);
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
}
}
22 changes: 22 additions & 0 deletions src/main/java/net/glxn/jmsutility/LogWindow.java
@@ -0,0 +1,22 @@
package net.glxn.jmsutility;

import javax.swing.*;

class LogWindow extends JFrame {
private JTextArea textArea = new JTextArea();

@SuppressWarnings({"UndesirableClassUsage"})
public LogWindow(int x, int y) {
super("");
setLocation(x, y);
setSize(500, 300);
add(new JScrollPane(textArea));
setAlwaysOnTop(true);
setVisible(true);
}

public void log(String msg) {
textArea.append(msg);
this.validate();
}
}

0 comments on commit 4164296

Please sign in to comment.