
If you are ever looking for a nice UML class designer look no further than NClass. I used this for a project to port a large code base from .NET to Java. The program was able to reverse engineer UML from compiled .NET code. Love it.
If you are ever looking for a nice UML class designer look no further than NClass. I used this for a project to port a large code base from .NET to Java. The program was able to reverse engineer UML from compiled .NET code. Love it.
01 import java.util.*;
02
03 class MySingletonClass {
04 private static final instance = new MySingletonClass();
05 private static final ListMY_STRINGS;
06 static {
07 MY_STRINGS = new ArrayList();
08 }
09 public MySingletonClass() {
10 System.out.println("MY_STRINGS: "+MYSTRINGS);
11 }
12 }
01 import java.util.*;
02
03 class MySingletonClass {
04 private static final instance;
05 private static final ListMY_STRINGS;
06 static {
07 MY_STRINGS = new ArrayList();
08 instance = new MySingletonClass();
09 }
10 public MySingletonClass() {
11 System.out.println("MY_STRINGS: "+MYSTRINGS);
12 }
13 }
@XmlJavaTypeAdapter(com.fourgablesguy.dao.hibernate.util.TimestampAdapter.class)
public Timestamp getCreateTs() {
return this.createTs;
}
package com.fourgablesguy.dao.hibernate.util;
import java.sql.Timestamp;
import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class TimestampAdapter extends XmlAdapter{
@Override
public Date marshal(Timestamp v) throws Exception {
return new Date(v.getTime());
}
@Override
public Timestamp unmarshal(Date v) throws Exception {
return new Timestamp(v.getTime());
}
}
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters
({
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(value=com.fourgablesguy.dao.hibernate.util.TimestampAdapter.class,type=java.sql.Timestamp.class)
})
package com.myama.dao.hibernate;
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.21</version>
<configuration>
<!-- <jettyConfig>src/main/resources/devJetty.xml</jettyConfig> -->
<webXml>${basedir}/src/main/resources/jetty-web.xml</webXml>
<jettyEnvXml>${basedir}/src/main/resources/jetty-env.xml</jettyEnvXml>
<contextPath>/OCM</contextPath>
<scanIntervalSeconds>3</scanIntervalSeconds>
<scanTargetPatterns>
<scanTargetPattern>
<directory>src/main/webapp/WEB-INF</directory>
<excludes>
<exclude>**/*.jsp</exclude>
</excludes>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</scanTargetPattern>
</scanTargetPatterns>
<stopKey>foo</stopKey>
<stopPort>9966</stopPort>
</configuration>
</plugin>
Key lines are
<webXml>${basedir}/src/main/resources/jetty-web.xml</webXml>
<jettyEnvXml>${basedir}/src/main/resources/jetty-env.xml</jettyEnvXml>
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC -//Mort Bay Consulting//DTD Configure//EN http://jetty.mortbay.org/configure.dtd>
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<!-- an XADataSource -->
<New id="MAVENJETTYDS" class="org.mortbay.jetty.plus.naming.Resource">
<Arg></Arg>
<Arg>jdbc/datasource</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="driverClassName">[[jdbc driver class]]</Set> <!-- for example, com.ibm.db2.jcc.DB2Driver -->
<Set name="url">[[jdbc url]]</Set> <!-- for example, jdbc:db2://yourdbhostnameorip:[port]/yourdb -->
<Set name="username">[[username]]</Set><!-- for example, yourmom -->
<Set name="password">[[password]]</Set><!-- for example, correcthorsebatterystaple -->
<Set name="defaultCatalog">[[schema, if needed]]</Set>
</New>
</Arg>
</New>
</Configure>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_1270163143862">
<pre>
<!-- SNIP -->
<!-- Bug fix for editing locked CSS and JS running in Jetty -->
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>useFileMappedBuffer</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<resource-ref>
<res-ref-name>jdbc/datasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
The following can be pasted into a JSP and then used to display (either in HTML source or in the browser window), the JSP Request, Session, Page, and Application settings for the environment and container the JSP is running within.
I have found this to be a quick useful way to get the lay of the land, when joining a project already in development.
<!--
<%@ page import="java.util.*"%>
<%
Object eobj = request.getParameter("error");
if (eobj != null) {
Exception exception = null;
Object obj = request.getAttribute("exception");
if (obj != null && obj instanceof Exception) {
exception = (Exception) obj;
}
if (exception == null) {
obj = request.getAttribute("javax.servlet.error.exception");
if (obj != null && obj instanceof Exception) {
exception = (Exception) obj;
}
}
if (exception != null) {
%><pre>
<%
exception.printStackTrace(new java.io.PrintWriter(out));
%>
</pre>
<%
}
}
out.println("<h3>Request:</h3><ul>");
Enumeration names = request.getHeaderNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
out.println("<li>HEADER " + name + ": "
+ request.getHeader(name));
}
for (Enumeration e = request.getParameterNames(); e
.hasMoreElements();) {
String name = (String) e.nextElement();
out.println("<li>PARAM " + name + "="
+ request.getParameter(name) + "</li>");
}
for (Enumeration e = request.getAttributeNames(); e
.hasMoreElements();) {
String name = (String) e.nextElement();
out.println("<li>ATTRIB " + name + "="
+ request.getAttribute(name) + "</li>");
}
out.println("</ul><h3>Session:</h3><ul>");
for (Enumeration e = session.getAttributeNames(); e
.hasMoreElements();) {
String name = (String) e.nextElement();
out.println("<li>ATTRIB " + name + "="
+ session.getAttribute(name) + "</li>");
}
out.println("</ul><h3>Page Scope Attributes:</h3><ul>");
for (Enumeration e = pageContext
.getAttributeNamesInScope(pageContext.PAGE_SCOPE); e
.hasMoreElements();) {
String name = (String) e.nextElement();
out.println("<li>ATTRIB "
+ name
+ "="
+ pageContext
.getAttribute(name, pageContext.PAGE_SCOPE)
+ "</li>");
}
out.println("</ul><h3>Application Scope Attributes:</h3><ul>");
for (Enumeration e = pageContext
.getAttributeNamesInScope(pageContext.APPLICATION_SCOPE); e
.hasMoreElements();) {
String name = (String) e.nextElement();
if (name.equals("com.sun.jsp.taglibraryCache")) {
out.print("<li>ATTRIB " + name
+ "= <b>NULL POINTER!</b></li>");
continue;
}
out.print("<li>ATTRIB " + name + "=");
out.println(pageContext.getAttribute(name,
pageContext.APPLICATION_SCOPE)
+ "</li>");
}
out.println("</ul>");
%>
-->
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*,javax.naming.*,javax.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Data Source</title>
</head>
<body>
<h1>Test Data Source</h1>
<p>Hello</p>
<%
DataSource ds = null;
Connection con = null;
Statement stmnt = null;
ResultSet resultSet = null;
try {
InitialContext ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/DataSource");
con = ds.getConnection();
stmnt = con.createStatement();
resultSet = stmnt.executeQuery("select * from PERSON");
if (resultSet != null) {
%><table><tr><%
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int nOfColumns = resultSetMetaData.getColumnCount();
for(int j = 0; j<nOfColumns; j++) {
String columnLabel = resultSetMetaData.getColumnLabel(j+1);
%><th><%=columnLabel %></th><%
}
%></tr><%
if (resultSet.getType() != ResultSet.TYPE_FORWARD_ONLY) {
resultSet.beforeFirst();
}
while (resultSet.next()) {
%><tr><%
for (int i = 1; i <= nOfColumns; ++i) {
%><td><%
Object value = resultSet.getObject(i);
if (resultSet.wasNull()) {
%><b>null</b><%
} else {
%><%=value.toString() %><%
}
%></td><%
}
%></tr><%
}
%></table><%
}
} catch(NamingException e) {
throw e;
} catch(SQLException e) {
throw e;
} finally {
try {
if (resultSet != null) {
resultSet.close();
}
} catch (SQLException e) {
}
resultSet = null;
try {
if (stmnt != null) {
stmnt.close();
}
} catch (SQLException e) {
}
stmnt = null;
try {
if (con != null) {
con.close();
}
} catch (SQLException e) {
}
con = null;
ds = null;
}
%>
</body>
</html>
java:comp/env/jdbc/DataSource
Cloudscape | #SQL SELECT 1 |
#DB2 | #SQL SELECT COUNT(*) FROM SYSIBM.SYSTABLES |
#Informix | #SQL SELECT COUNT(*) FROM SYSTABLES |
#Microsoft SQL Server | #SQL SELECT COUNT(*) FROM SYSOBJECTS |
#MySQL | #SQL SELECT 1 |
#Oracle | #SQL SELECT 1 FROM DUAL |
#PointBase | #SQL SELECT COUNT(*) FROM SYSTABLES |
#PostgreSQL | #SQL SELECT 1 |
#Progress | #SQL SELECT COUNT(*) FROM SYSTABLES |
#Sybase | #SQL SELECT COUNT(*) FROM SYSOBJECTS |
When I setup a connection pool or database tool with a new database profile I like to test that it works, here are some vendor specific SQL you can use to test your db connection.
Cloudscape | #SQL SELECT 1 |
#DB2 | #SQL SELECT COUNT(*) FROM SYSIBM.SYSTABLES |
#Informix | #SQL SELECT COUNT(*) FROM SYSTABLES |
#Microsoft SQL Server | #SQL SELECT COUNT(*) FROM SYSOBJECTS |
#MySQL | #SQL SELECT 1 |
#Oracle | #SQL SELECT 1 FROM DUAL |
#PointBase | #SQL SELECT COUNT(*) FROM SYSTABLES |
#PostgreSQL | #SQL SELECT 1 |
#Progress | #SQL SELECT COUNT(*) FROM SYSTABLES |
#Sybase | #SQL SELECT COUNT(*) FROM SYSOBJECTS |
This is useful because you don't often know what tables exist in a database to test a query with, you can't assume select * from person would work if no person table was created. These queries are for the builtin system database resource in the specific vendor database types, they should exist even on a freshly installed or blank database server.
The insert syntax for adding new lines or line terminators in varchar columns in DB2 is not straightforward:
INSERT INTO EXAMPLE_TABLE ("ID","LEVEL_ID","VERSION","CONTENT","TYPE","FRAGMENT_ID") VALUES (158781,317339,20110701, 'your line of text' || x'0D' || x'0A' || 'your next line of text','HTML',0);
The key to the query is to use || operator to concatenate the strings for the content column. The syntax for adding CR LF is :
'your line of text' || x'0D' || x'0A' 'your next line of text'
DB2 will take the above and combine the strings into a single value for the database. The x'0D' x'0A' is to say hex value OD (carriage return) and hex value 0A (line feed). Windows expects both, for Linux/Unix OS only the 0A character is expected. For some versions of Mac OS you use only 0D, the newest ones use only 0A to end a line. For browsers, 0A is also the only needed character which is often ignored unless surrounded by pre or code tags however having both 0D and 0A will not cause display issues. The newest Windows OS may have support for just 0A as well in some cases.
OutputStreamWriter out = null;
try {
try {
out = new OutputStreamWriter(new FileOutputStream(outputFile),"UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage,e);
}
try {
out.append(yourStringDataToWriteToOutputFile);
out.flush();
} catch (IOException e) {
throw new RuntimeException(e.getMessage,e);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e.getMessage,e);
} finally {
try {
out.close();
} catch (IOException e) {
throw new RuntimeException(e.getMessage,e);
}
}
Here is how I did it:
In my controller:
import org.springframework.context.ApplicationContext; ...
@Autowired private ApplicationContext context;
In the resource bundle ApplicationResources.properties
gotocode.error.notfound=Sorry {0} is not recognized as a code.
Back in the controller
public static final String GOTOCODE_NOTFOUND_KEY = "gotocode.error.notfound";
public static final String CODE_NOT_FOUND_MESSAGE = "Sorry the entry {0} is not recognized as a code.";
...
public ModelAndView findNextInSeries(String code,..
String errorMessage = context.getMessage(
GOTOCODE_NOTFOUND_KEY, new Object[] { code }, CODE_NOT_FOUND_MESSAGE, Locale.getDefault());
Previously my ApplicationResources.properties was configured in the web.xml
http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_1270163143862"></web-app>
<display-name>Sample Spring Resource Bundle
<distributable>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext
<param-value>ApplicationResources
As well as in the Spring Application context configuration (dispatcher-servlet.xml):
This is a document to help you setup Eclipse TPTP plugin for performance monitoring of J2EE application deployed to Jetty using the jetty-maven-plugin.
Open MyEclipse Configuration center and search for TPTP, download the newest version of TPTP plugin, restart your IDE after the install finishes.
Next go to the TPTP homepage and download the Agent controller for your architecture (I downloaded windows IA32).
Extract the Agent controller zip to C:\Tools\agntctrl.win_ia32-TPTP-4.7.2
Edit your system environment variables and add
RASERVER_HOME=C:\Tools\agntctrl.win_ia32-TPTP-4.7.2 PATH=C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin;%PATH% Open a command prompt and goto agent controller cd C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin SetConfig.bat
This should display the following:
C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin>SetConfig.bat Specify the fully qualified path of "javaw.exe" (e.g. c:\jdk1.4\jre\bin\javaw.ex e): Default>"C:\Program Files\IBM\WebSphere\AppServer\java\jre\bin\javaw.exe" (Pre ss to accept the default value) New value> Network access mode (ALL=allow any host, LOCAL=allow only this host, CUSTOM=list of hosts): Default>"LOCAL" (Press to accept the default value) New value>ALL Security enabled. (true/false): Default>"FALSE" (Press to accept the default value) New value>
Start the Agent Controller by launching a command console window with Administrator privledges (Run as Admni..) The change your working directory to
cd C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin
ACServer.exe
See this link for more agent controller info http://dev.eclipse.org/viewcvs/viewvc.cgi/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/packaging_md/windows/getting_started.html?root=TPTP_Project&view=co
This is also a link with good info on TPTP http://eclipse.sys-con.com/node/508048?page=0,2
Configure piAgent and start your application with Maven by adding this to MAVEN_OPTS environment variable:
-XrunpiAgent:server=enabled
From eclipse navigate to Run | Profile Configurations... | Attach to Agent | New
ACServer should be running on localhost port 10002, check this with netstat -a -b -n command or test button in eclipse
Jetty JVM Agent should be detected on the Agent tab. select ONLY ONE of the profile probes, CPU --or-- MEMORY etc.. do NOT select more than one, treat them as mutually exclusive radio buttons rather than check boxes.
You can then perform tasks in your application and save the data captured. Also you can create new reports from the captured data with TPTP eclipse tools.
See http://www.eclipse.org/articles/Article-TPTP-Profiling-Tool/tptpProfilingArticle.html