Patch from Dave to excise all remaining tabs.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2759 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -38,7 +38,7 @@ public class ByteArrayOutInputStream extends ByteArrayOutputStream
|
|||||||
*/
|
*/
|
||||||
public ByteArrayOutInputStream ()
|
public ByteArrayOutInputStream ()
|
||||||
{
|
{
|
||||||
this(32);
|
this(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -81,56 +81,56 @@ public abstract class ExtensiblePrintStream extends PrintStream
|
|||||||
public void print (char c)
|
public void print (char c)
|
||||||
{
|
{
|
||||||
super.print(c);
|
super.print(c);
|
||||||
handlePrinted(String.valueOf(c));
|
handlePrinted(String.valueOf(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print (int i)
|
public void print (int i)
|
||||||
{
|
{
|
||||||
super.print(i);
|
super.print(i);
|
||||||
handlePrinted(String.valueOf(i));
|
handlePrinted(String.valueOf(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print (long l)
|
public void print (long l)
|
||||||
{
|
{
|
||||||
super.print(l);
|
super.print(l);
|
||||||
handlePrinted(String.valueOf(l));
|
handlePrinted(String.valueOf(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print (float f)
|
public void print (float f)
|
||||||
{
|
{
|
||||||
super.print(f);
|
super.print(f);
|
||||||
handlePrinted(String.valueOf(f));
|
handlePrinted(String.valueOf(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print (double d)
|
public void print (double d)
|
||||||
{
|
{
|
||||||
super.print(d);
|
super.print(d);
|
||||||
handlePrinted(String.valueOf(d));
|
handlePrinted(String.valueOf(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print (char[] s)
|
public void print (char[] s)
|
||||||
{
|
{
|
||||||
super.print(s);
|
super.print(s);
|
||||||
handlePrinted(String.valueOf(s));
|
handlePrinted(String.valueOf(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print (String s)
|
public void print (String s)
|
||||||
{
|
{
|
||||||
super.print(s);
|
super.print(s);
|
||||||
handlePrinted((s == null) ? "null" : s);
|
handlePrinted((s == null) ? "null" : s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print (Object obj)
|
public void print (Object obj)
|
||||||
{
|
{
|
||||||
super.print(obj);
|
super.print(obj);
|
||||||
handlePrinted(String.valueOf(obj));
|
handlePrinted(String.valueOf(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ public class JDBCUtil
|
|||||||
* nothing).
|
* nothing).
|
||||||
*/
|
*/
|
||||||
public static void close (Statement stmt)
|
public static void close (Statement stmt)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
if (stmt != null) {
|
if (stmt != null) {
|
||||||
stmt.close();
|
stmt.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,11 +72,11 @@ public class JDBCUtil
|
|||||||
* nothing).
|
* nothing).
|
||||||
*/
|
*/
|
||||||
public static void close (Connection conn)
|
public static void close (Connection conn)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class Repository
|
|||||||
* indicative of a basic JDBC failure. The transaction
|
* indicative of a basic JDBC failure. The transaction
|
||||||
* <em>will</em> be rolled back in such cases, however.
|
* <em>will</em> be rolled back in such cases, however.
|
||||||
*/
|
*/
|
||||||
public V invoke (Connection conn, DatabaseLiaison liaison)
|
public V invoke (Connection conn, DatabaseLiaison liaison)
|
||||||
throws SQLException, PersistenceException;
|
throws SQLException, PersistenceException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,14 +256,14 @@ public class StaticConnectionProvider implements ConnectionProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static String requireProp (Properties props, String name, String errmsg)
|
protected static String requireProp (Properties props, String name, String errmsg)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
String value = props.getProperty(name);
|
String value = props.getProperty(name);
|
||||||
if (StringUtil.isBlank(value)) {
|
if (StringUtil.isBlank(value)) {
|
||||||
errmsg = "Unable to get connection. " + errmsg; // augment the error message
|
errmsg = "Unable to get connection. " + errmsg; // augment the error message
|
||||||
throw new PersistenceException(errmsg);
|
throw new PersistenceException(errmsg);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Contains information on a particular connection to which any number of database identifiers
|
/** Contains information on a particular connection to which any number of database identifiers
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class Cursor<V>
|
|||||||
* more rows
|
* more rows
|
||||||
*/
|
*/
|
||||||
public V next ()
|
public V next ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
// if we closed everything up after the last call to next(),
|
// if we closed everything up after the last call to next(),
|
||||||
// table will be null here and we should bail immediately
|
// table will be null here and we should bail immediately
|
||||||
@@ -78,7 +78,7 @@ public class Cursor<V>
|
|||||||
if (_stmt != null) {
|
if (_stmt != null) {
|
||||||
_stmt.close();
|
_stmt.close();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,11 +119,11 @@ public class Cursor<V>
|
|||||||
* drivers.
|
* drivers.
|
||||||
*/
|
*/
|
||||||
public void update ()
|
public void update ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
if (_currObject == null) {
|
if (_currObject == null) {
|
||||||
throw new IllegalStateException("No current object");
|
throw new IllegalStateException("No current object");
|
||||||
}
|
}
|
||||||
_table.updateVariables(_result, _currObject);
|
_table.updateVariables(_result, _currObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,11 +142,11 @@ public class Cursor<V>
|
|||||||
* drivers.
|
* drivers.
|
||||||
*/
|
*/
|
||||||
public void delete ()
|
public void delete ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
if (_currObject == null) {
|
if (_currObject == null) {
|
||||||
throw new IllegalStateException("No current object");
|
throw new IllegalStateException("No current object");
|
||||||
}
|
}
|
||||||
_result.deleteRow();
|
_result.deleteRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ public class Cursor<V>
|
|||||||
* @return List with objects constructed from fetched records.
|
* @return List with objects constructed from fetched records.
|
||||||
*/
|
*/
|
||||||
public ArrayList<V> toArrayList (int maxElements)
|
public ArrayList<V> toArrayList (int maxElements)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
ArrayList<V> al = new ArrayList<V>(Math.min(maxElements, 100));
|
ArrayList<V> al = new ArrayList<V>(Math.min(maxElements, 100));
|
||||||
V o;
|
V o;
|
||||||
@@ -197,7 +197,7 @@ public class Cursor<V>
|
|||||||
* @return Array with objects constructed from fetched records.
|
* @return Array with objects constructed from fetched records.
|
||||||
*/
|
*/
|
||||||
public ArrayList<V> toArrayList ()
|
public ArrayList<V> toArrayList ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
return toArrayList(Integer.MAX_VALUE);
|
return toArrayList(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
@@ -213,12 +213,12 @@ public class Cursor<V>
|
|||||||
FieldMask mask, boolean like)
|
FieldMask mask, boolean like)
|
||||||
{
|
{
|
||||||
_table = table;
|
_table = table;
|
||||||
_conn = conn;
|
_conn = conn;
|
||||||
_like = like;
|
_like = like;
|
||||||
_qbeObject = obj;
|
_qbeObject = obj;
|
||||||
_qbeMask = mask;
|
_qbeMask = mask;
|
||||||
_query = table.buildQueryList(obj, mask, like);
|
_query = table.buildQueryList(obj, mask, like);
|
||||||
_stmt = null;
|
_stmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Table<V> _table;
|
protected Table<V> _table;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class FieldDescriptor
|
|||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.field = field;
|
this.field = field;
|
||||||
this.scale = -1;
|
this.scale = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean isAtomic ()
|
protected final boolean isAtomic ()
|
||||||
@@ -53,336 +53,320 @@ class FieldDescriptor
|
|||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
switch (outType) {
|
switch (outType) {
|
||||||
case t_byte:
|
case t_byte:
|
||||||
pstmt.setByte(column, field.getByte(obj));
|
pstmt.setByte(column, field.getByte(obj));
|
||||||
break;
|
break;
|
||||||
case t_short:
|
case t_short:
|
||||||
pstmt.setShort(column, field.getShort(obj));
|
pstmt.setShort(column, field.getShort(obj));
|
||||||
break;
|
break;
|
||||||
case t_int:
|
case t_int:
|
||||||
pstmt.setInt(column, field.getInt(obj));
|
pstmt.setInt(column, field.getInt(obj));
|
||||||
break;
|
break;
|
||||||
case t_long:
|
case t_long:
|
||||||
pstmt.setLong(column, field.getLong(obj));
|
pstmt.setLong(column, field.getLong(obj));
|
||||||
break;
|
break;
|
||||||
case t_float:
|
case t_float:
|
||||||
pstmt.setFloat(column, field.getFloat(obj));
|
pstmt.setFloat(column, field.getFloat(obj));
|
||||||
break;
|
break;
|
||||||
case t_double:
|
case t_double:
|
||||||
pstmt.setDouble(column, field.getDouble(obj));
|
pstmt.setDouble(column, field.getDouble(obj));
|
||||||
break;
|
break;
|
||||||
case t_boolean:
|
case t_boolean:
|
||||||
pstmt.setBoolean(column, field.getBoolean(obj));
|
pstmt.setBoolean(column, field.getBoolean(obj));
|
||||||
break;
|
break;
|
||||||
case tByte:
|
case tByte:
|
||||||
pstmt.setByte(column, ((Byte)field.get(obj)).byteValue());
|
pstmt.setByte(column, ((Byte)field.get(obj)).byteValue());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tShort:
|
case tShort:
|
||||||
pstmt.setShort(column, ((Short)field.get(obj)).shortValue());
|
pstmt.setShort(column, ((Short)field.get(obj)).shortValue());
|
||||||
break;
|
break;
|
||||||
case tInteger:
|
case tInteger:
|
||||||
pstmt.setInt(column, ((Integer)field.get(obj)).intValue());
|
pstmt.setInt(column, ((Integer)field.get(obj)).intValue());
|
||||||
break;
|
break;
|
||||||
case tLong:
|
case tLong:
|
||||||
pstmt.setLong(column, ((Long)field.get(obj)).longValue());
|
pstmt.setLong(column, ((Long)field.get(obj)).longValue());
|
||||||
break;
|
break;
|
||||||
case tFloat:
|
case tFloat:
|
||||||
pstmt.setFloat(column, ((Float)field.get(obj)).floatValue());
|
pstmt.setFloat(column, ((Float)field.get(obj)).floatValue());
|
||||||
break;
|
break;
|
||||||
case tDouble:
|
case tDouble:
|
||||||
pstmt.setDouble(column,((Double)field.get(obj)).doubleValue());
|
pstmt.setDouble(column,((Double)field.get(obj)).doubleValue());
|
||||||
break;
|
break;
|
||||||
case tBoolean:
|
case tBoolean:
|
||||||
pstmt.setBoolean(column,
|
pstmt.setBoolean(column, ((Boolean)field.get(obj)).booleanValue());
|
||||||
((Boolean)field.get(obj)).booleanValue());
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case tDecimal:
|
case tDecimal:
|
||||||
pstmt.setBigDecimal(column, (BigDecimal)field.get(obj));
|
pstmt.setBigDecimal(column, (BigDecimal)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tString:
|
case tString:
|
||||||
pstmt.setString(column, (String)field.get(obj));
|
pstmt.setString(column, (String)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tBytes:
|
case tBytes:
|
||||||
pstmt.setBytes(column, (byte[])field.get(obj));
|
pstmt.setBytes(column, (byte[])field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tDate:
|
case tDate:
|
||||||
pstmt.setDate(column, (java.sql.Date)field.get(obj));
|
pstmt.setDate(column, (java.sql.Date)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tTime:
|
case tTime:
|
||||||
pstmt.setTime(column, (java.sql.Time)field.get(obj));
|
pstmt.setTime(column, (java.sql.Time)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tTimestamp:
|
case tTimestamp:
|
||||||
pstmt.setTimestamp(column, (java.sql.Timestamp)field.get(obj));
|
pstmt.setTimestamp(column, (java.sql.Timestamp)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tStream:
|
case tStream:
|
||||||
java.io.InputStream in = (java.io.InputStream)field.get(obj);
|
java.io.InputStream in = (java.io.InputStream)field.get(obj);
|
||||||
pstmt.setBinaryStream(column, in, in.available());
|
pstmt.setBinaryStream(column, in, in.available());
|
||||||
break;
|
break;
|
||||||
case tBlob:
|
case tBlob:
|
||||||
pstmt.setBlob(column, (Blob)field.get(obj));
|
pstmt.setBlob(column, (Blob)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tClob:
|
case tClob:
|
||||||
pstmt.setClob(column, (Clob)field.get(obj));
|
pstmt.setClob(column, (Clob)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tAsString:
|
case tAsString:
|
||||||
pstmt.setString(column, field.get(obj).toString());
|
pstmt.setString(column, field.get(obj).toString());
|
||||||
break;
|
break;
|
||||||
case tClosure:
|
case tClosure:
|
||||||
// There is no reason to use piped streams because
|
// There is no reason to use piped streams because
|
||||||
// we need to pass total number of bytes to JDBC driver
|
// we need to pass total number of bytes to JDBC driver
|
||||||
java.io.ByteArrayOutputStream out =
|
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
||||||
new java.io.ByteArrayOutputStream();
|
java.io.ObjectOutputStream clu = new java.io.ObjectOutputStream(out);
|
||||||
java.io.ObjectOutputStream clu =
|
clu.writeObject(field.get(obj));
|
||||||
new java.io.ObjectOutputStream(out);
|
clu.close();
|
||||||
clu.writeObject(field.get(obj));
|
pstmt.setBytes(column, out.toByteArray());
|
||||||
clu.close();
|
break;
|
||||||
pstmt.setBytes(column, out.toByteArray());
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch(SQLException ex) {
|
} catch(SQLException ex) {
|
||||||
if (outType != tClosure && outType != tAsString) {
|
if (outType != tClosure && outType != tAsString) {
|
||||||
outType = tAsString;
|
outType = tAsString;
|
||||||
return bindVariable(pstmt, obj, column);
|
return bindVariable(pstmt, obj, column);
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
} catch(IllegalAccessException ex) {
|
} catch(IllegalAccessException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
throw new IllegalAccessError();
|
throw new IllegalAccessError();
|
||||||
} catch(java.io.IOException ex) {
|
} catch(java.io.IOException ex) {
|
||||||
throw new DataTransferError(ex);
|
throw new DataTransferError(ex);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean updateVariable (
|
protected final boolean updateVariable (ResultSet result, Object obj, int column)
|
||||||
ResultSet result, Object obj, int column)
|
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
switch (outType) {
|
switch (outType) {
|
||||||
case t_byte:
|
case t_byte:
|
||||||
result.updateByte(column, field.getByte(obj));
|
result.updateByte(column, field.getByte(obj));
|
||||||
break;
|
break;
|
||||||
case t_short:
|
case t_short:
|
||||||
result.updateShort(column, field.getShort(obj));
|
result.updateShort(column, field.getShort(obj));
|
||||||
break;
|
break;
|
||||||
case t_int:
|
case t_int:
|
||||||
result.updateInt(column, field.getInt(obj));
|
result.updateInt(column, field.getInt(obj));
|
||||||
break;
|
break;
|
||||||
case t_long:
|
case t_long:
|
||||||
result.updateLong(column, field.getLong(obj));
|
result.updateLong(column, field.getLong(obj));
|
||||||
break;
|
break;
|
||||||
case t_float:
|
case t_float:
|
||||||
result.updateFloat(column, field.getFloat(obj));
|
result.updateFloat(column, field.getFloat(obj));
|
||||||
break;
|
break;
|
||||||
case t_double:
|
case t_double:
|
||||||
result.updateDouble(column, field.getDouble(obj));
|
result.updateDouble(column, field.getDouble(obj));
|
||||||
break;
|
break;
|
||||||
case t_boolean:
|
case t_boolean:
|
||||||
result.updateBoolean(column, field.getBoolean(obj));
|
result.updateBoolean(column, field.getBoolean(obj));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tByte:
|
case tByte:
|
||||||
result.updateByte(column, ((Byte)field.get(obj)).byteValue());
|
result.updateByte(column, ((Byte)field.get(obj)).byteValue());
|
||||||
break;
|
break;
|
||||||
case tShort:
|
case tShort:
|
||||||
result.updateShort(column,
|
result.updateShort(column, ((Short)field.get(obj)).shortValue());
|
||||||
((Short)field.get(obj)).shortValue());
|
break;
|
||||||
break;
|
|
||||||
case tInteger:
|
case tInteger:
|
||||||
result.updateInt(column, ((Integer)field.get(obj)).intValue());
|
result.updateInt(column, ((Integer)field.get(obj)).intValue());
|
||||||
break;
|
break;
|
||||||
case tLong:
|
case tLong:
|
||||||
result.updateLong(column, ((Long)field.get(obj)).longValue());
|
result.updateLong(column, ((Long)field.get(obj)).longValue());
|
||||||
break;
|
break;
|
||||||
case tFloat:
|
case tFloat:
|
||||||
result.updateFloat(column,
|
result.updateFloat(column, ((Float)field.get(obj)).floatValue());
|
||||||
((Float)field.get(obj)).floatValue());
|
break;
|
||||||
break;
|
|
||||||
case tDouble:
|
case tDouble:
|
||||||
result.updateDouble(column,
|
result.updateDouble(column, ((Double)field.get(obj)).doubleValue());
|
||||||
((Double)field.get(obj)).doubleValue());
|
break;
|
||||||
break;
|
|
||||||
case tBoolean:
|
case tBoolean:
|
||||||
result.updateBoolean(column,
|
result.updateBoolean(column, ((Boolean)field.get(obj)).booleanValue());
|
||||||
((Boolean)field.get(obj)).booleanValue());
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case tDecimal:
|
case tDecimal:
|
||||||
result.updateBigDecimal(column, (BigDecimal)field.get(obj));
|
result.updateBigDecimal(column, (BigDecimal)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tString:
|
case tString:
|
||||||
result.updateString(column, (String)field.get(obj));
|
result.updateString(column, (String)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tBytes:
|
case tBytes:
|
||||||
result.updateBytes(column, (byte[])field.get(obj));
|
result.updateBytes(column, (byte[])field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tDate:
|
case tDate:
|
||||||
result.updateDate(column, (java.sql.Date)field.get(obj));
|
result.updateDate(column, (java.sql.Date)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tTime:
|
case tTime:
|
||||||
result.updateTime(column, (java.sql.Time)field.get(obj));
|
result.updateTime(column, (java.sql.Time)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tTimestamp:
|
case tTimestamp:
|
||||||
result.updateTimestamp(column,
|
result.updateTimestamp(column, (java.sql.Timestamp)field.get(obj));
|
||||||
(java.sql.Timestamp)field.get(obj));
|
break;
|
||||||
break;
|
|
||||||
case tStream:
|
case tStream:
|
||||||
java.io.InputStream in = (java.io.InputStream)field.get(obj);
|
java.io.InputStream in = (java.io.InputStream)field.get(obj);
|
||||||
result.updateBinaryStream(column, in, in.available());
|
result.updateBinaryStream(column, in, in.available());
|
||||||
break;
|
break;
|
||||||
case tBlob:
|
case tBlob:
|
||||||
Blob blob = (Blob)field.get(obj);
|
Blob blob = (Blob)field.get(obj);
|
||||||
result.updateBinaryStream(column,
|
result.updateBinaryStream(column, blob.getBinaryStream(), (int)blob.length());
|
||||||
blob.getBinaryStream(),
|
break;
|
||||||
(int)blob.length());
|
|
||||||
break;
|
|
||||||
case tClob:
|
case tClob:
|
||||||
Clob clob = (Clob)field.get(obj);
|
Clob clob = (Clob)field.get(obj);
|
||||||
result.updateCharacterStream(column,
|
result.updateCharacterStream(column, clob.getCharacterStream(), (int)clob.length());
|
||||||
clob.getCharacterStream(),
|
break;
|
||||||
(int)clob.length());
|
|
||||||
break;
|
|
||||||
case tAsString:
|
case tAsString:
|
||||||
result.updateString(column, field.get(obj).toString());
|
result.updateString(column, field.get(obj).toString());
|
||||||
break;
|
break;
|
||||||
case tClosure:
|
case tClosure:
|
||||||
// There is no reason to use piped streams because
|
// There is no reason to use piped streams because
|
||||||
// we need to pass total number of bytes to JDBC driver
|
// we need to pass total number of bytes to JDBC driver
|
||||||
java.io.ByteArrayOutputStream out =
|
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
||||||
new java.io.ByteArrayOutputStream();
|
java.io.ObjectOutputStream clu = new java.io.ObjectOutputStream(out);
|
||||||
java.io.ObjectOutputStream clu =
|
clu.writeObject(field.get(obj));
|
||||||
new java.io.ObjectOutputStream(out);
|
clu.close();
|
||||||
clu.writeObject(field.get(obj));
|
result.updateBytes(column, out.toByteArray());
|
||||||
clu.close();
|
break;
|
||||||
result.updateBytes(column, out.toByteArray());
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch(SQLException ex) {
|
} catch(SQLException ex) {
|
||||||
if (outType != tClosure && outType != tAsString) {
|
if (outType != tClosure && outType != tAsString) {
|
||||||
outType = tAsString;
|
outType = tAsString;
|
||||||
return updateVariable(result, obj, column);
|
return updateVariable(result, obj, column);
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
} catch(IllegalAccessException ex) {
|
} catch(IllegalAccessException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
throw new IllegalAccessError();
|
throw new IllegalAccessError();
|
||||||
} catch(java.io.IOException ex) {
|
} catch(java.io.IOException ex) {
|
||||||
throw new DataTransferError(ex);
|
throw new DataTransferError(ex);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean loadVariable (
|
protected final boolean loadVariable (
|
||||||
ResultSet result, Object obj, int column)
|
ResultSet result, Object obj, int column)
|
||||||
throws SQLException, IllegalAccessException
|
throws SQLException, IllegalAccessException
|
||||||
{
|
{
|
||||||
switch (inType) {
|
switch (inType) {
|
||||||
case t_byte:
|
case t_byte:
|
||||||
field.setByte(obj, result.getByte(column));
|
field.setByte(obj, result.getByte(column));
|
||||||
break;
|
break;
|
||||||
case t_short:
|
case t_short:
|
||||||
field.setShort(obj, result.getShort(column));
|
field.setShort(obj, result.getShort(column));
|
||||||
break;
|
break;
|
||||||
case t_int:
|
case t_int:
|
||||||
field.setInt(obj, result.getInt(column));
|
field.setInt(obj, result.getInt(column));
|
||||||
break;
|
break;
|
||||||
case t_long:
|
case t_long:
|
||||||
field.setLong(obj, result.getLong(column));
|
field.setLong(obj, result.getLong(column));
|
||||||
break;
|
break;
|
||||||
case t_float:
|
case t_float:
|
||||||
field.setFloat(obj, result.getFloat(column));
|
field.setFloat(obj, result.getFloat(column));
|
||||||
break;
|
break;
|
||||||
case t_double:
|
case t_double:
|
||||||
field.setDouble(obj, result.getDouble(column));
|
field.setDouble(obj, result.getDouble(column));
|
||||||
break;
|
break;
|
||||||
case t_boolean:
|
case t_boolean:
|
||||||
field.setBoolean(obj, result.getBoolean(column));
|
field.setBoolean(obj, result.getBoolean(column));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tByte:
|
case tByte:
|
||||||
byte b = result.getByte(column);
|
byte b = result.getByte(column);
|
||||||
field.set(obj, result.wasNull() ? null : Byte.valueOf(b));
|
field.set(obj, result.wasNull() ? null : Byte.valueOf(b));
|
||||||
break;
|
break;
|
||||||
case tShort:
|
case tShort:
|
||||||
short s = result.getShort(column);
|
short s = result.getShort(column);
|
||||||
field.set(obj, result.wasNull() ? null : Short.valueOf(s));
|
field.set(obj, result.wasNull() ? null : Short.valueOf(s));
|
||||||
break;
|
break;
|
||||||
case tInteger:
|
case tInteger:
|
||||||
int i = result.getInt(column);
|
int i = result.getInt(column);
|
||||||
field.set(obj, result.wasNull() ? null : Integer.valueOf(i));
|
field.set(obj, result.wasNull() ? null : Integer.valueOf(i));
|
||||||
break;
|
break;
|
||||||
case tLong:
|
case tLong:
|
||||||
long l = result.getLong(column);
|
long l = result.getLong(column);
|
||||||
field.set(obj, result.wasNull() ? null : Long.valueOf(l));
|
field.set(obj, result.wasNull() ? null : Long.valueOf(l));
|
||||||
break;
|
break;
|
||||||
case tFloat:
|
case tFloat:
|
||||||
float f = result.getFloat(column);
|
float f = result.getFloat(column);
|
||||||
field.set(obj, result.wasNull() ? null : Float.valueOf(f));
|
field.set(obj, result.wasNull() ? null : Float.valueOf(f));
|
||||||
field.setFloat(obj, result.getFloat(column));
|
field.setFloat(obj, result.getFloat(column));
|
||||||
break;
|
break;
|
||||||
case tDouble:
|
case tDouble:
|
||||||
double d = result.getDouble(column);
|
double d = result.getDouble(column);
|
||||||
field.set(obj, result.wasNull() ? null : Double.valueOf(d));
|
field.set(obj, result.wasNull() ? null : Double.valueOf(d));
|
||||||
break;
|
break;
|
||||||
case tBoolean:
|
case tBoolean:
|
||||||
boolean bl = result.getBoolean(column);
|
boolean bl = result.getBoolean(column);
|
||||||
field.set(obj, result.wasNull() ? null : Boolean.valueOf(bl));
|
field.set(obj, result.wasNull() ? null : Boolean.valueOf(bl));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tDecimal:
|
case tDecimal:
|
||||||
field.set(obj, result.getBigDecimal(column));
|
field.set(obj, result.getBigDecimal(column));
|
||||||
break;
|
break;
|
||||||
case tString:
|
case tString:
|
||||||
field.set(obj, result.getString(column));
|
field.set(obj, result.getString(column));
|
||||||
break;
|
break;
|
||||||
case tBytes:
|
case tBytes:
|
||||||
field.set(obj, result.getBytes(column));
|
field.set(obj, result.getBytes(column));
|
||||||
break;
|
break;
|
||||||
case tDate:
|
case tDate:
|
||||||
field.set(obj, result.getDate(column));
|
field.set(obj, result.getDate(column));
|
||||||
break;
|
break;
|
||||||
case tTime:
|
case tTime:
|
||||||
field.set(obj, result.getTime(column));
|
field.set(obj, result.getTime(column));
|
||||||
break;
|
break;
|
||||||
case tTimestamp:
|
case tTimestamp:
|
||||||
field.set(obj, result.getTimestamp(column));
|
field.set(obj, result.getTimestamp(column));
|
||||||
break;
|
break;
|
||||||
case tStream:
|
case tStream:
|
||||||
field.set(obj, result.getBinaryStream(column));
|
field.set(obj, result.getBinaryStream(column));
|
||||||
break;
|
break;
|
||||||
case tBlob:
|
case tBlob:
|
||||||
field.set(obj, result.getBlob(column));
|
field.set(obj, result.getBlob(column));
|
||||||
break;
|
break;
|
||||||
case tClob:
|
case tClob:
|
||||||
field.set(obj, result.getClob(column));
|
field.set(obj, result.getClob(column));
|
||||||
break;
|
break;
|
||||||
case tClosure:
|
case tClosure:
|
||||||
try {
|
try {
|
||||||
java.io.InputStream input = result.getBinaryStream(column);
|
java.io.InputStream input = result.getBinaryStream(column);
|
||||||
java.io.ObjectInputStream in =
|
java.io.ObjectInputStream in = new java.io.ObjectInputStream(input);
|
||||||
new java.io.ObjectInputStream(input);
|
field.set(obj, in.readObject());
|
||||||
field.set(obj, in.readObject());
|
in.close();
|
||||||
in.close();
|
} catch(ClassNotFoundException ex) {
|
||||||
} catch(ClassNotFoundException ex) {
|
throw new DataTransferError(ex);
|
||||||
throw new DataTransferError(ex);
|
} catch(java.io.IOException ex) {
|
||||||
} catch(java.io.IOException ex) {
|
throw new DataTransferError(ex);
|
||||||
throw new DataTransferError(ex);
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int inType; // type tag for field input (see constants below)
|
protected int inType; // type tag for field input (see constants below)
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ public class CDDBException extends Exception
|
|||||||
{
|
{
|
||||||
public CDDBException (int code, String message)
|
public CDDBException (int code, String message)
|
||||||
{
|
{
|
||||||
super(message);
|
super(message);
|
||||||
_code = code;
|
_code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCode ()
|
public int getCode ()
|
||||||
{
|
{
|
||||||
return _code;
|
return _code;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int _code;
|
protected int _code;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class CDDBProtocol
|
|||||||
*/
|
*/
|
||||||
public static int codeFamily (int code)
|
public static int codeFamily (int code)
|
||||||
{
|
{
|
||||||
return (code / 100) * 100;
|
return (code / 100) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +54,7 @@ public class CDDBProtocol
|
|||||||
*/
|
*/
|
||||||
public static int codeGenus (int code)
|
public static int codeGenus (int code)
|
||||||
{
|
{
|
||||||
return ((code % 100) / 10) * 10;
|
return ((code % 100) / 10) * 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,6 +63,6 @@ public class CDDBProtocol
|
|||||||
*/
|
*/
|
||||||
public static int codeSpecies (int code)
|
public static int codeSpecies (int code)
|
||||||
{
|
{
|
||||||
return code % 10;
|
return code % 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,70 +27,68 @@ package com.samskivert.net.cddb;
|
|||||||
public class CDDBTest
|
public class CDDBTest
|
||||||
{
|
{
|
||||||
public static void test (String hostname, String cdid)
|
public static void test (String hostname, String cdid)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
CDDB cddb = new CDDB();
|
CDDB cddb = new CDDB();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/* String rsp = */ cddb.connect(hostname);
|
/* String rsp = */ cddb.connect(hostname);
|
||||||
|
|
||||||
// set the timeout to 30 seconds
|
// set the timeout to 30 seconds
|
||||||
cddb.setTimeout(30*1000);
|
cddb.setTimeout(30*1000);
|
||||||
|
|
||||||
// try a test query
|
// try a test query
|
||||||
int[] offsets = { 150, 18130, 48615 };
|
int[] offsets = { 150, 18130, 48615 };
|
||||||
int length = 893;
|
int length = 893;
|
||||||
CDDB.Entry[] entries = cddb.query(cdid, offsets, length);
|
CDDB.Entry[] entries = cddb.query(cdid, offsets, length);
|
||||||
|
|
||||||
if (entries == null || entries.length == 0) {
|
if (entries == null || entries.length == 0) {
|
||||||
System.out.println("No match for " + cdid + ".");
|
System.out.println("No match for " + cdid + ".");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < entries.length; i++) {
|
for (int i = 0; i < entries.length; i++) {
|
||||||
System.out.println("Match " + entries[i].category + "/" +
|
System.out.println("Match " + entries[i].category + "/" +
|
||||||
entries[i].cdid + "/" +
|
entries[i].cdid + "/" +
|
||||||
entries[i].title);
|
entries[i].title);
|
||||||
}
|
}
|
||||||
|
|
||||||
CDDB.Detail detail = cddb.read(entries[0].category,
|
CDDB.Detail detail = cddb.read(entries[0].category,
|
||||||
entries[0].cdid);
|
entries[0].cdid);
|
||||||
System.out.println("Title: " + detail.title);
|
System.out.println("Title: " + detail.title);
|
||||||
for (int i = 0; i < detail.trackNames.length; i++) {
|
for (int i = 0; i < detail.trackNames.length; i++) {
|
||||||
System.out.println(pad(i) + ": " + detail.trackNames[i]);
|
System.out.println(pad(i) + ": " + detail.trackNames[i]);
|
||||||
}
|
}
|
||||||
System.out.println("Extended data: " + detail.extendedData);
|
System.out.println("Extended data: " + detail.extendedData);
|
||||||
for (int i = 0; i < detail.extendedTrackData.length; i++) {
|
for (int i = 0; i < detail.extendedTrackData.length; i++) {
|
||||||
System.out.println(pad(i) + ": " +
|
System.out.println(pad(i) + ": " + detail.extendedTrackData[i]);
|
||||||
detail.extendedTrackData[i]);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
cddb.close();
|
cddb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String pad (int value)
|
protected static String pad (int value)
|
||||||
{
|
{
|
||||||
return ((value > 9) ? "" : " ") + value;
|
return ((value > 9) ? "" : " ") + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main (String[] args)
|
public static void main (String[] args)
|
||||||
{
|
{
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
System.err.println("Usage: CDDBTest cddbhost");
|
System.err.println("Usage: CDDBTest cddbhost");
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
test(args[0], "1b037b03");
|
test(args[0], "1b037b03");
|
||||||
|
|
||||||
} catch (CDDBException ce) {
|
} catch (CDDBException ce) {
|
||||||
System.err.println("Protocol exception: " + ce.getCode() +
|
System.err.println("Protocol exception: " + ce.getCode() + ": " + ce.getMessage());
|
||||||
": " + ce.getMessage());
|
|
||||||
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace(System.err);
|
t.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ public class RedirectException extends Exception
|
|||||||
{
|
{
|
||||||
public RedirectException (String url)
|
public RedirectException (String url)
|
||||||
{
|
{
|
||||||
super(url);
|
super(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRedirectURL ()
|
public String getRedirectURL ()
|
||||||
{
|
{
|
||||||
return getMessage();
|
return getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,6 @@ public class DataValidationException extends FriendlyException
|
|||||||
{
|
{
|
||||||
public DataValidationException (String message)
|
public DataValidationException (String message)
|
||||||
{
|
{
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,57 +77,57 @@ public class ExceptionMap
|
|||||||
*/
|
*/
|
||||||
public static synchronized void init ()
|
public static synchronized void init ()
|
||||||
{
|
{
|
||||||
// only initialize ourselves once
|
// only initialize ourselves once
|
||||||
if (_keys != null) {
|
if (_keys != null) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
_keys = new ArrayList<Class<?>>();
|
_keys = new ArrayList<Class<?>>();
|
||||||
_values = new ArrayList<String>();
|
_values = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// first try loading the properties file without a leading slash
|
// first try loading the properties file without a leading slash
|
||||||
ClassLoader cld = ExceptionMap.class.getClassLoader();
|
ClassLoader cld = ExceptionMap.class.getClassLoader();
|
||||||
InputStream config = ConfigUtil.getStream(PROPS_NAME, cld);
|
InputStream config = ConfigUtil.getStream(PROPS_NAME, cld);
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
log.warning("Unable to load " + PROPS_NAME + " from CLASSPATH.");
|
log.warning("Unable to load " + PROPS_NAME + " from CLASSPATH.");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// otherwise process ye old config file.
|
// otherwise process ye old config file.
|
||||||
try {
|
try {
|
||||||
// we'll do some serious jiggery pokery to leverage the parsing
|
// we'll do some serious jiggery pokery to leverage the parsing
|
||||||
// implementation provided by java.util.Properties. god bless
|
// implementation provided by java.util.Properties. god bless
|
||||||
// method overloading
|
// method overloading
|
||||||
final ArrayList<String> classes = new ArrayList<String>();
|
final ArrayList<String> classes = new ArrayList<String>();
|
||||||
Properties loader = new Properties() {
|
Properties loader = new Properties() {
|
||||||
@Override public Object put (Object key, Object value) {
|
@Override public Object put (Object key, Object value) {
|
||||||
classes.add((String)key);
|
classes.add((String)key);
|
||||||
_values.add((String)value);
|
_values.add((String)value);
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
loader.load(config);
|
loader.load(config);
|
||||||
|
|
||||||
// now cruise through and resolve the exceptions named as
|
// now cruise through and resolve the exceptions named as
|
||||||
// keys and throw out any that don't appear to exist
|
// keys and throw out any that don't appear to exist
|
||||||
for (int i = 0; i < classes.size(); i++) {
|
for (int i = 0; i < classes.size(); i++) {
|
||||||
String exclass = classes.get(i);
|
String exclass = classes.get(i);
|
||||||
try {
|
try {
|
||||||
Class<?> cl = Class.forName(exclass);
|
Class<?> cl = Class.forName(exclass);
|
||||||
// replace the string with the class object
|
// replace the string with the class object
|
||||||
_keys.add(cl);
|
_keys.add(cl);
|
||||||
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.warning("Unable to resolve exception class.", "class", exclass,
|
log.warning("Unable to resolve exception class.", "class", exclass,
|
||||||
"error", t);
|
"error", t);
|
||||||
_values.remove(i);
|
_values.remove(i);
|
||||||
i--; // back on up a notch
|
i--; // back on up a notch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
log.warning("Error reading exception mapping file: " + ioe);
|
log.warning("Error reading exception mapping file: " + ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,15 +142,15 @@ public class ExceptionMap
|
|||||||
*/
|
*/
|
||||||
public static String getMessage (Throwable ex)
|
public static String getMessage (Throwable ex)
|
||||||
{
|
{
|
||||||
String msg = DEFAULT_ERROR_MSG;
|
String msg = DEFAULT_ERROR_MSG;
|
||||||
for (int i = 0; i < _keys.size(); i++) {
|
for (int i = 0; i < _keys.size(); i++) {
|
||||||
Class<?> cl = _keys.get(i);
|
Class<?> cl = _keys.get(i);
|
||||||
if (cl.isInstance(ex)) {
|
if (cl.isInstance(ex)) {
|
||||||
msg = _values.get(i);
|
msg = _values.get(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return StringUtil.replace(msg, MESSAGE_MARKER, ex.getMessage());
|
return StringUtil.replace(msg, MESSAGE_MARKER, ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static List<Class<?>> _keys;
|
protected static List<Class<?>> _keys;
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ public class FriendlyException extends Exception
|
|||||||
{
|
{
|
||||||
public FriendlyException (String message)
|
public FriendlyException (String message)
|
||||||
{
|
{
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static String getParameter (HttpServletRequest req, String name, boolean returnNull)
|
public static String getParameter (HttpServletRequest req, String name, boolean returnNull)
|
||||||
{
|
{
|
||||||
String value = req.getParameter(name);
|
String value = req.getParameter(name);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return returnNull ? null : "";
|
return returnNull ? null : "";
|
||||||
} else {
|
} else {
|
||||||
@@ -88,9 +88,9 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static float requireFloatParameter (
|
public static float requireFloatParameter (
|
||||||
HttpServletRequest req, String name, String invalidDataMessage)
|
HttpServletRequest req, String name, String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
return parseFloatParameter(getParameter(req, name, false), invalidDataMessage);
|
return parseFloatParameter(getParameter(req, name, false), invalidDataMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,9 +100,9 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static int requireIntParameter (
|
public static int requireIntParameter (
|
||||||
HttpServletRequest req, String name, String invalidDataMessage)
|
HttpServletRequest req, String name, String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
return parseIntParameter(getParameter(req, name, false), invalidDataMessage);
|
return parseIntParameter(getParameter(req, name, false), invalidDataMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,11 +112,11 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static int requireIntParameter (HttpServletRequest req, String name,
|
public static int requireIntParameter (HttpServletRequest req, String name,
|
||||||
String invalidDataMessage, ParameterValidator validator)
|
String invalidDataMessage, ParameterValidator validator)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
String value = getParameter(req, name, false);
|
String value = getParameter(req, name, false);
|
||||||
validator.validateParameter(name, value);
|
validator.validateParameter(name, value);
|
||||||
return parseIntParameter(value, invalidDataMessage);
|
return parseIntParameter(value, invalidDataMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +126,7 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static int requireIntParameter (HttpServletRequest req, String name, int low, int high,
|
public static int requireIntParameter (HttpServletRequest req, String name, int low, int high,
|
||||||
String invalidDataMessage)
|
String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
return requireIntParameter(
|
return requireIntParameter(
|
||||||
req, name, invalidDataMessage, new IntRangeValidator(low, high, invalidDataMessage));
|
req, name, invalidDataMessage, new IntRangeValidator(low, high, invalidDataMessage));
|
||||||
@@ -176,7 +176,7 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static String getParameter (HttpServletRequest req, String name, String defval)
|
public static String getParameter (HttpServletRequest req, String name, String defval)
|
||||||
{
|
{
|
||||||
String value = req.getParameter(name);
|
String value = req.getParameter(name);
|
||||||
return StringUtil.isBlank(value) ? defval : value.trim();
|
return StringUtil.isBlank(value) ? defval : value.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,9 +187,9 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static int getIntParameter (
|
public static int getIntParameter (
|
||||||
HttpServletRequest req, String name, int defval, String invalidDataMessage)
|
HttpServletRequest req, String name, int defval, String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
String value = getParameter(req, name, false);
|
String value = getParameter(req, name, false);
|
||||||
if (StringUtil.isBlank(value)) {
|
if (StringUtil.isBlank(value)) {
|
||||||
return defval;
|
return defval;
|
||||||
}
|
}
|
||||||
@@ -203,9 +203,9 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static long getLongParameter (
|
public static long getLongParameter (
|
||||||
HttpServletRequest req, String name, long defval, String invalidDataMessage)
|
HttpServletRequest req, String name, long defval, String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
String value = getParameter(req, name, false);
|
String value = getParameter(req, name, false);
|
||||||
if (StringUtil.isBlank(value)) {
|
if (StringUtil.isBlank(value)) {
|
||||||
return defval;
|
return defval;
|
||||||
}
|
}
|
||||||
@@ -218,13 +218,13 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static String requireParameter (
|
public static String requireParameter (
|
||||||
HttpServletRequest req, String name, String missingDataMessage)
|
HttpServletRequest req, String name, String missingDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
String value = getParameter(req, name, true);
|
String value = getParameter(req, name, true);
|
||||||
if (StringUtil.isBlank(value)) {
|
if (StringUtil.isBlank(value)) {
|
||||||
throw new DataValidationException(missingDataMessage);
|
throw new DataValidationException(missingDataMessage);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,7 +238,7 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static String requireParameter (
|
public static String requireParameter (
|
||||||
HttpServletRequest req, String name, String missingDataMessage, int maxLength)
|
HttpServletRequest req, String name, String missingDataMessage, int maxLength)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
return StringUtil.truncate(
|
return StringUtil.truncate(
|
||||||
requireParameter(req, name, missingDataMessage), maxLength);
|
requireParameter(req, name, missingDataMessage), maxLength);
|
||||||
@@ -251,7 +251,7 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static Date requireDateParameter (
|
public static Date requireDateParameter (
|
||||||
HttpServletRequest req, String name, String invalidDataMessage)
|
HttpServletRequest req, String name, String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
return parseDateParameter(getParameter(req, name, false), invalidDataMessage);
|
return parseDateParameter(getParameter(req, name, false), invalidDataMessage);
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static java.sql.Date requireSQLDateParameter (
|
public static java.sql.Date requireSQLDateParameter (
|
||||||
HttpServletRequest req, String name, String invalidDataMessage)
|
HttpServletRequest req, String name, String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
return new java.sql.Date(requireDateParameter(req, name, invalidDataMessage).getTime());
|
return new java.sql.Date(requireDateParameter(req, name, invalidDataMessage).getTime());
|
||||||
}
|
}
|
||||||
@@ -274,9 +274,9 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static Date getDateParameter (
|
public static Date getDateParameter (
|
||||||
HttpServletRequest req, String name, String invalidDataMessage)
|
HttpServletRequest req, String name, String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
String value = getParameter(req, name, false);
|
String value = getParameter(req, name, false);
|
||||||
if (StringUtil.isBlank(value) ||
|
if (StringUtil.isBlank(value) ||
|
||||||
DATE_TEMPLATE.equalsIgnoreCase(value)) {
|
DATE_TEMPLATE.equalsIgnoreCase(value)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -289,7 +289,7 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static java.sql.Date getSQLDateParameter (
|
public static java.sql.Date getSQLDateParameter (
|
||||||
HttpServletRequest req, String name, String invalidDataMessage)
|
HttpServletRequest req, String name, String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
Date when = getDateParameter(req, name, invalidDataMessage);
|
Date when = getDateParameter(req, name, invalidDataMessage);
|
||||||
return (when == null) ? null : new java.sql.Date(when.getTime());
|
return (when == null) ? null : new java.sql.Date(when.getTime());
|
||||||
@@ -329,7 +329,7 @@ public class ParameterUtil
|
|||||||
*/
|
*/
|
||||||
public static boolean parameterEquals (HttpServletRequest req, String name, String value)
|
public static boolean parameterEquals (HttpServletRequest req, String name, String value)
|
||||||
{
|
{
|
||||||
return value.equals(getParameter(req, name, false));
|
return value.equals(getParameter(req, name, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -339,10 +339,10 @@ public class ParameterUtil
|
|||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(value);
|
return Integer.parseInt(value);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
throw new DataValidationException(invalidDataMessage);
|
throw new DataValidationException(invalidDataMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -352,10 +352,10 @@ public class ParameterUtil
|
|||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return Long.parseLong(value);
|
return Long.parseLong(value);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
throw new DataValidationException(invalidDataMessage);
|
throw new DataValidationException(invalidDataMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -365,25 +365,25 @@ public class ParameterUtil
|
|||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return Float.parseFloat(value);
|
return Float.parseFloat(value);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
throw new DataValidationException(invalidDataMessage);
|
throw new DataValidationException(invalidDataMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal method to parse a date.
|
* Internal method to parse a date.
|
||||||
*/
|
*/
|
||||||
protected static Date parseDateParameter (String value, String invalidDataMessage)
|
protected static Date parseDateParameter (String value, String invalidDataMessage)
|
||||||
throws DataValidationException
|
throws DataValidationException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
synchronized (_dparser) {
|
synchronized (_dparser) {
|
||||||
return _dparser.parse(value);
|
return _dparser.parse(value);
|
||||||
}
|
}
|
||||||
} catch (ParseException pe) {
|
} catch (ParseException pe) {
|
||||||
throw new DataValidationException(invalidDataMessage);
|
throw new DataValidationException(invalidDataMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Makes sure integers are within a range. */
|
/** Makes sure integers are within a range. */
|
||||||
|
|||||||
@@ -101,10 +101,10 @@ public class AbsoluteLayout
|
|||||||
|
|
||||||
Dimension dims = new Dimension(rect.width, rect.height);
|
Dimension dims = new Dimension(rect.width, rect.height);
|
||||||
|
|
||||||
// account for the insets
|
// account for the insets
|
||||||
Insets insets = parent.getInsets();
|
Insets insets = parent.getInsets();
|
||||||
dims.width += insets.left + insets.right;
|
dims.width += insets.left + insets.right;
|
||||||
dims.height += insets.top + insets.bottom;
|
dims.height += insets.top + insets.bottom;
|
||||||
|
|
||||||
return dims;
|
return dims;
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ public class AbsoluteLayout
|
|||||||
// documentation inherited from interface
|
// documentation inherited from interface
|
||||||
public void layoutContainer (Container parent)
|
public void layoutContainer (Container parent)
|
||||||
{
|
{
|
||||||
Insets insets = parent.getInsets();
|
Insets insets = parent.getInsets();
|
||||||
int pcount = parent.getComponentCount();
|
int pcount = parent.getComponentCount();
|
||||||
for (int ii = 0; ii < pcount; ii++) {
|
for (int ii = 0; ii < pcount; ii++) {
|
||||||
Component comp = parent.getComponent(ii);
|
Component comp = parent.getComponent(ii);
|
||||||
|
|||||||
@@ -50,18 +50,18 @@ public class DimenInfo
|
|||||||
@Override
|
@Override
|
||||||
public String toString ()
|
public String toString ()
|
||||||
{
|
{
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append("[count=").append(count);
|
buf.append("[count=").append(count);
|
||||||
buf.append(", totwid=").append(totwid);
|
buf.append(", totwid=").append(totwid);
|
||||||
buf.append(", tothei=").append(tothei);
|
buf.append(", tothei=").append(tothei);
|
||||||
buf.append(", maxwid=").append(maxwid);
|
buf.append(", maxwid=").append(maxwid);
|
||||||
buf.append(", maxhei=").append(maxhei);
|
buf.append(", maxhei=").append(maxhei);
|
||||||
buf.append(", numfix=").append(numfix);
|
buf.append(", numfix=").append(numfix);
|
||||||
buf.append(", fixwid=").append(fixwid);
|
buf.append(", fixwid=").append(fixwid);
|
||||||
buf.append(", fixhei=").append(fixhei);
|
buf.append(", fixhei=").append(fixhei);
|
||||||
buf.append(", maxfreewid=").append(maxfreewid);
|
buf.append(", maxfreewid=").append(maxfreewid);
|
||||||
buf.append(", maxfreehei=").append(maxfreehei);
|
buf.append(", maxfreehei=").append(maxfreehei);
|
||||||
buf.append(", totweight=").append(totweight);
|
buf.append(", totweight=").append(totweight);
|
||||||
return buf.append("]").toString();
|
return buf.append("]").toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,36 +44,33 @@ public abstract class GroupLayout
|
|||||||
*/
|
*/
|
||||||
public static class Constraints
|
public static class Constraints
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructs a new constraints object with the specified weight,
|
* Constructs a new constraints object with the specified weight,
|
||||||
* which is only applicable with the STRETCH policy.
|
* which is only applicable with the STRETCH policy.
|
||||||
*/
|
*/
|
||||||
public Constraints (int weight)
|
public Constraints (int weight) {
|
||||||
{
|
_weight = weight;
|
||||||
_weight = weight;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this Constraints specifying fixed?
|
* Is this Constraints specifying fixed?
|
||||||
*/
|
*/
|
||||||
public final boolean isFixed ()
|
public final boolean isFixed () {
|
||||||
{
|
|
||||||
return (this == FIXED);
|
return (this == FIXED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the weight.
|
* Get the weight.
|
||||||
*/
|
*/
|
||||||
public final int getWeight ()
|
public final int getWeight () {
|
||||||
{
|
|
||||||
return _weight;
|
return _weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The weight of this component relative to the other components
|
* The weight of this component relative to the other components
|
||||||
* in the container. Only valid if the layout policy is STRETCH.
|
* in the container. Only valid if the layout policy is STRETCH.
|
||||||
*/
|
*/
|
||||||
protected int _weight = 1;
|
protected int _weight = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A class used to make our policy constants type-safe. */
|
/** A class used to make our policy constants type-safe. */
|
||||||
@@ -127,108 +124,107 @@ public abstract class GroupLayout
|
|||||||
|
|
||||||
public void setPolicy (Policy policy)
|
public void setPolicy (Policy policy)
|
||||||
{
|
{
|
||||||
_policy = policy;
|
_policy = policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Policy getPolicy ()
|
public Policy getPolicy ()
|
||||||
{
|
{
|
||||||
return _policy;
|
return _policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOffAxisPolicy (Policy offpolicy)
|
public void setOffAxisPolicy (Policy offpolicy)
|
||||||
{
|
{
|
||||||
_offpolicy = offpolicy;
|
_offpolicy = offpolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Policy getOffAxisPolicy ()
|
public Policy getOffAxisPolicy ()
|
||||||
{
|
{
|
||||||
return _offpolicy;
|
return _offpolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGap (int gap)
|
public void setGap (int gap)
|
||||||
{
|
{
|
||||||
_gap = gap;
|
_gap = gap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getGap ()
|
public int getGap ()
|
||||||
{
|
{
|
||||||
return _gap;
|
return _gap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJustification (Justification justification)
|
public void setJustification (Justification justification)
|
||||||
{
|
{
|
||||||
_justification = justification;
|
_justification = justification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Justification getJustification ()
|
public Justification getJustification ()
|
||||||
{
|
{
|
||||||
return _justification;
|
return _justification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOffAxisJustification (Justification justification)
|
public void setOffAxisJustification (Justification justification)
|
||||||
{
|
{
|
||||||
_offjust = justification;
|
_offjust = justification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Justification getOffAxisJustification ()
|
public Justification getOffAxisJustification ()
|
||||||
{
|
{
|
||||||
return _offjust;
|
return _offjust;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLayoutComponent (String name, Component comp)
|
public void addLayoutComponent (String name, Component comp)
|
||||||
{
|
{
|
||||||
// nothing to do here
|
// nothing to do here
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeLayoutComponent (Component comp)
|
public void removeLayoutComponent (Component comp)
|
||||||
{
|
{
|
||||||
if (_constraints != null) {
|
if (_constraints != null) {
|
||||||
_constraints.remove(comp);
|
_constraints.remove(comp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLayoutComponent (Component comp, Object constraints)
|
public void addLayoutComponent (Component comp, Object constraints)
|
||||||
{
|
{
|
||||||
if (constraints != null) {
|
if (constraints != null) {
|
||||||
if (constraints instanceof Constraints) {
|
if (constraints instanceof Constraints) {
|
||||||
if (_constraints == null) {
|
if (_constraints == null) {
|
||||||
_constraints = new HashMap<Component,Constraints>();
|
_constraints = new HashMap<Component,Constraints>();
|
||||||
}
|
}
|
||||||
_constraints.put(comp, (Constraints)constraints);
|
_constraints.put(comp, (Constraints)constraints);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("GroupLayout constraints " +
|
throw new RuntimeException(
|
||||||
"object must be of type " +
|
"GroupLayout constraints object must be of type GroupLayout.Constraints");
|
||||||
"GroupLayout.Constraints");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getLayoutAlignmentX (Container target)
|
public float getLayoutAlignmentX (Container target)
|
||||||
{
|
{
|
||||||
// we don't support alignment like this
|
// we don't support alignment like this
|
||||||
return 0f;
|
return 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getLayoutAlignmentY (Container target)
|
public float getLayoutAlignmentY (Container target)
|
||||||
{
|
{
|
||||||
// we don't support alignment like this
|
// we don't support alignment like this
|
||||||
return 0f;
|
return 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dimension minimumLayoutSize (Container parent)
|
public Dimension minimumLayoutSize (Container parent)
|
||||||
{
|
{
|
||||||
return getLayoutSize(parent, MINIMUM);
|
return getLayoutSize(parent, MINIMUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dimension preferredLayoutSize (Container parent)
|
public Dimension preferredLayoutSize (Container parent)
|
||||||
{
|
{
|
||||||
return getLayoutSize(parent, PREFERRED);
|
return getLayoutSize(parent, PREFERRED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dimension maximumLayoutSize (Container parent)
|
public Dimension maximumLayoutSize (Container parent)
|
||||||
{
|
{
|
||||||
return getLayoutSize(parent, MAXIMUM);
|
return getLayoutSize(parent, MAXIMUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Dimension getLayoutSize (Container parent, int type);
|
protected abstract Dimension getLayoutSize (Container parent, int type);
|
||||||
@@ -237,7 +233,7 @@ public abstract class GroupLayout
|
|||||||
|
|
||||||
public void invalidateLayout (Container target)
|
public void invalidateLayout (Container target)
|
||||||
{
|
{
|
||||||
// nothing to do here
|
// nothing to do here
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -261,52 +257,51 @@ public abstract class GroupLayout
|
|||||||
* Computes dimensions of the children widgets that are useful for the
|
* Computes dimensions of the children widgets that are useful for the
|
||||||
* group layout managers.
|
* group layout managers.
|
||||||
*/
|
*/
|
||||||
protected DimenInfo computeDimens (Container parent, int type)
|
protected DimenInfo computeDimens (Container parent, int type) {
|
||||||
{
|
int count = parent.getComponentCount();
|
||||||
int count = parent.getComponentCount();
|
DimenInfo info = new DimenInfo();
|
||||||
DimenInfo info = new DimenInfo();
|
info.dimens = new Dimension[count];
|
||||||
info.dimens = new Dimension[count];
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Component child = parent.getComponent(i);
|
Component child = parent.getComponent(i);
|
||||||
if (!child.isVisible()) {
|
if (!child.isVisible()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dimension csize;
|
Dimension csize;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MINIMUM:
|
case MINIMUM:
|
||||||
csize = child.getMinimumSize();
|
csize = child.getMinimumSize();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MAXIMUM:
|
case MAXIMUM:
|
||||||
csize = child.getMaximumSize();
|
csize = child.getMaximumSize();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
csize = child.getPreferredSize();
|
csize = child.getPreferredSize();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
info.count++;
|
info.count++;
|
||||||
info.totwid += csize.width;
|
info.totwid += csize.width;
|
||||||
info.tothei += csize.height;
|
info.tothei += csize.height;
|
||||||
|
|
||||||
if (csize.width > info.maxwid) {
|
if (csize.width > info.maxwid) {
|
||||||
info.maxwid = csize.width;
|
info.maxwid = csize.width;
|
||||||
}
|
}
|
||||||
if (csize.height > info.maxhei) {
|
if (csize.height > info.maxhei) {
|
||||||
info.maxhei = csize.height;
|
info.maxhei = csize.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
Constraints c = getConstraints(child);
|
Constraints c = getConstraints(child);
|
||||||
if (c.isFixed()) {
|
if (c.isFixed()) {
|
||||||
info.fixwid += csize.width;
|
info.fixwid += csize.width;
|
||||||
info.fixhei += csize.height;
|
info.fixhei += csize.height;
|
||||||
info.numfix++;
|
info.numfix++;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
info.totweight += c.getWeight();
|
info.totweight += c.getWeight();
|
||||||
|
|
||||||
if (csize.width > info.maxfreewid) {
|
if (csize.width > info.maxfreewid) {
|
||||||
info.maxfreewid = csize.width;
|
info.maxfreewid = csize.width;
|
||||||
@@ -314,12 +309,12 @@ public abstract class GroupLayout
|
|||||||
if (csize.height > info.maxfreehei) {
|
if (csize.height > info.maxfreehei) {
|
||||||
info.maxfreehei = csize.height;
|
info.maxfreehei = csize.height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info.dimens[i] = csize;
|
info.dimens[i] = csize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,33 +28,31 @@ public class GroupLayoutTest
|
|||||||
{
|
{
|
||||||
public static void main (String[] args)
|
public static void main (String[] args)
|
||||||
{
|
{
|
||||||
JFrame frame = new JFrame("GroupLayoutTest");
|
JFrame frame = new JFrame("GroupLayoutTest");
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
GroupLayout layout = new HGroupLayout();
|
GroupLayout layout = new HGroupLayout();
|
||||||
layout.setJustification(GroupLayout.CENTER);
|
layout.setJustification(GroupLayout.CENTER);
|
||||||
layout.setPolicy(GroupLayout.STRETCH);
|
layout.setPolicy(GroupLayout.STRETCH);
|
||||||
layout.setJustification(GroupLayout.RIGHT);
|
layout.setJustification(GroupLayout.RIGHT);
|
||||||
layout.setGap(15);
|
layout.setGap(15);
|
||||||
panel.setLayout(layout);
|
panel.setLayout(layout);
|
||||||
|
|
||||||
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||||
|
|
||||||
JButton butone = new JButton("One");
|
JButton butone = new JButton("One");
|
||||||
panel.add(butone, GroupLayout.FIXED);
|
panel.add(butone, GroupLayout.FIXED);
|
||||||
JButton buttwo = new JButton("Two");
|
JButton buttwo = new JButton("Two");
|
||||||
panel.add(buttwo, GroupLayout.FIXED);
|
panel.add(buttwo, GroupLayout.FIXED);
|
||||||
JButton butthree = new JButton("Three to get ready");
|
JButton butthree = new JButton("Three to get ready");
|
||||||
panel.add(butthree, GroupLayout.FIXED);
|
panel.add(butthree, GroupLayout.FIXED);
|
||||||
|
|
||||||
frame.addWindowListener(new WindowAdapter ()
|
frame.addWindowListener(new WindowAdapter () {
|
||||||
{
|
@Override public void windowClosing (WindowEvent e) {
|
||||||
@Override public void windowClosing (WindowEvent e)
|
|
||||||
{
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,31 +24,30 @@ import java.awt.*;
|
|||||||
|
|
||||||
public class HGroupLayout extends GroupLayout
|
public class HGroupLayout extends GroupLayout
|
||||||
{
|
{
|
||||||
public HGroupLayout (Policy policy, Policy offpolicy, int gap,
|
public HGroupLayout (Policy policy, Policy offpolicy, int gap, Justification justification)
|
||||||
Justification justification)
|
|
||||||
{
|
{
|
||||||
_policy = policy;
|
_policy = policy;
|
||||||
_offpolicy = offpolicy;
|
_offpolicy = offpolicy;
|
||||||
_gap = gap;
|
_gap = gap;
|
||||||
_justification = justification;
|
_justification = justification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HGroupLayout (Policy policy, int gap, Justification justification)
|
public HGroupLayout (Policy policy, int gap, Justification justification)
|
||||||
{
|
{
|
||||||
_policy = policy;
|
_policy = policy;
|
||||||
_gap = gap;
|
_gap = gap;
|
||||||
_justification = justification;
|
_justification = justification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HGroupLayout (Policy policy, Justification justification)
|
public HGroupLayout (Policy policy, Justification justification)
|
||||||
{
|
{
|
||||||
_policy = policy;
|
_policy = policy;
|
||||||
_justification = justification;
|
_justification = justification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HGroupLayout (Policy policy)
|
public HGroupLayout (Policy policy)
|
||||||
{
|
{
|
||||||
_policy = policy;
|
_policy = policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HGroupLayout ()
|
public HGroupLayout ()
|
||||||
@@ -58,126 +57,124 @@ public class HGroupLayout extends GroupLayout
|
|||||||
@Override
|
@Override
|
||||||
protected Dimension getLayoutSize (Container parent, int type)
|
protected Dimension getLayoutSize (Container parent, int type)
|
||||||
{
|
{
|
||||||
DimenInfo info = computeDimens(parent, type);
|
DimenInfo info = computeDimens(parent, type);
|
||||||
Dimension dims = new Dimension();
|
Dimension dims = new Dimension();
|
||||||
|
|
||||||
if (_policy == STRETCH) {
|
if (_policy == STRETCH) {
|
||||||
dims.width = info.maxfreewid * (info.count - info.numfix) +
|
dims.width = info.maxfreewid * (info.count - info.numfix) + info.fixwid;
|
||||||
info.fixwid;
|
|
||||||
} else if (_policy == EQUALIZE) {
|
} else if (_policy == EQUALIZE) {
|
||||||
dims.width = info.maxwid * info.count;
|
dims.width = info.maxwid * info.count;
|
||||||
} else { // NONE or CONSTRAIN
|
} else { // NONE or CONSTRAIN
|
||||||
dims.width = info.totwid;
|
dims.width = info.totwid;
|
||||||
}
|
}
|
||||||
|
|
||||||
dims.width += (info.count - 1) * _gap;
|
dims.width += (info.count - 1) * _gap;
|
||||||
dims.height = info.maxhei;
|
dims.height = info.maxhei;
|
||||||
|
|
||||||
// account for the insets
|
// account for the insets
|
||||||
Insets insets = parent.getInsets();
|
Insets insets = parent.getInsets();
|
||||||
dims.width += insets.left + insets.right;
|
dims.width += insets.left + insets.right;
|
||||||
dims.height += insets.top + insets.bottom;
|
dims.height += insets.top + insets.bottom;
|
||||||
|
|
||||||
return dims;
|
return dims;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void layoutContainer (Container parent)
|
public void layoutContainer (Container parent)
|
||||||
{
|
{
|
||||||
Rectangle b = parent.getBounds();
|
Rectangle b = parent.getBounds();
|
||||||
DimenInfo info = computeDimens(parent, PREFERRED);
|
DimenInfo info = computeDimens(parent, PREFERRED);
|
||||||
|
|
||||||
// adjust the bounds width and height to account for the insets
|
// adjust the bounds width and height to account for the insets
|
||||||
Insets insets = parent.getInsets();
|
Insets insets = parent.getInsets();
|
||||||
b.width -= (insets.left + insets.right);
|
b.width -= (insets.left + insets.right);
|
||||||
b.height -= (insets.top + insets.bottom);
|
b.height -= (insets.top + insets.bottom);
|
||||||
|
|
||||||
int nk = parent.getComponentCount();
|
int nk = parent.getComponentCount();
|
||||||
int sx, sy;
|
int sx, sy;
|
||||||
int totwid, totgap = _gap * (info.count-1);
|
int totwid, totgap = _gap * (info.count-1);
|
||||||
int freecount = info.count - info.numfix;
|
int freecount = info.count - info.numfix;
|
||||||
|
|
||||||
// when stretching, there is the possibility that a pixel or more
|
// when stretching, there is the possibility that a pixel or more
|
||||||
// will be lost to rounding error. we account for that here and
|
// will be lost to rounding error. we account for that here and
|
||||||
// assign the extra space to the first free component
|
// assign the extra space to the first free component
|
||||||
int freefrac = 0;
|
int freefrac = 0;
|
||||||
|
|
||||||
// do the on-axis policy calculations
|
// do the on-axis policy calculations
|
||||||
int defwid = 0;
|
int defwid = 0;
|
||||||
if (_policy == STRETCH) {
|
if (_policy == STRETCH) {
|
||||||
if (freecount > 0) {
|
if (freecount > 0) {
|
||||||
int freewid = b.width - info.fixwid - totgap;
|
int freewid = b.width - info.fixwid - totgap;
|
||||||
defwid = freewid / info.totweight;
|
defwid = freewid / info.totweight;
|
||||||
freefrac = freewid % info.totweight;
|
freefrac = freewid % info.totweight;
|
||||||
totwid = b.width;
|
totwid = b.width;
|
||||||
} else {
|
} else {
|
||||||
totwid = info.fixwid + totgap;
|
totwid = info.fixwid + totgap;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (_policy == EQUALIZE) {
|
} else if (_policy == EQUALIZE) {
|
||||||
defwid = info.maxwid;
|
defwid = info.maxwid;
|
||||||
totwid = info.fixwid + defwid * freecount + totgap;
|
totwid = info.fixwid + defwid * freecount + totgap;
|
||||||
|
|
||||||
} else { // NONE or CONSTRAIN
|
} else { // NONE or CONSTRAIN
|
||||||
totwid = info.totwid + totgap;
|
totwid = info.totwid + totgap;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the off-axis policy calculations
|
// do the off-axis policy calculations
|
||||||
int defhei = 0;
|
int defhei = 0;
|
||||||
if (_offpolicy == STRETCH) {
|
if (_offpolicy == STRETCH) {
|
||||||
defhei = b.height;
|
defhei = b.height;
|
||||||
} else if (_offpolicy == EQUALIZE) {
|
} else if (_offpolicy == EQUALIZE) {
|
||||||
defhei = info.maxhei;
|
defhei = info.maxhei;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the justification-related calculations
|
// do the justification-related calculations
|
||||||
if (_justification == LEFT || _justification == TOP) {
|
if (_justification == LEFT || _justification == TOP) {
|
||||||
sx = insets.left;
|
sx = insets.left;
|
||||||
} else if (_justification == CENTER) {
|
} else if (_justification == CENTER) {
|
||||||
sx = insets.left + (b.width - totwid)/2;
|
sx = insets.left + (b.width - totwid)/2;
|
||||||
} else { // RIGHT or BOTTOM
|
} else { // RIGHT or BOTTOM
|
||||||
sx = insets.left + b.width - totwid;
|
sx = insets.left + b.width - totwid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the layout
|
// do the layout
|
||||||
for (int i = 0; i < nk; i++) {
|
for (int i = 0; i < nk; i++) {
|
||||||
// skip non-visible kids
|
// skip non-visible kids
|
||||||
if (info.dimens[i] == null) {
|
if (info.dimens[i] == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Component child = parent.getComponent(i);
|
Component child = parent.getComponent(i);
|
||||||
Constraints c = getConstraints(child);
|
Constraints c = getConstraints(child);
|
||||||
int newwid, newhei;
|
int newwid, newhei;
|
||||||
|
|
||||||
if (_policy == NONE || c.isFixed()) {
|
if (_policy == NONE || c.isFixed()) {
|
||||||
newwid = info.dimens[i].width;
|
newwid = info.dimens[i].width;
|
||||||
} else {
|
} else {
|
||||||
newwid = freefrac +
|
newwid = freefrac + ((_policy == STRETCH) ? defwid * c.getWeight() : defwid);
|
||||||
((_policy == STRETCH) ? defwid * c.getWeight() : defwid);
|
|
||||||
// clear out the extra pixels the first time they're used
|
// clear out the extra pixels the first time they're used
|
||||||
freefrac = 0;
|
freefrac = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_offpolicy == NONE) {
|
if (_offpolicy == NONE) {
|
||||||
newhei = info.dimens[i].height;
|
newhei = info.dimens[i].height;
|
||||||
} else if (_offpolicy == CONSTRAIN) {
|
} else if (_offpolicy == CONSTRAIN) {
|
||||||
newhei = Math.min(info.dimens[i].height, b.height);
|
newhei = Math.min(info.dimens[i].height, b.height);
|
||||||
} else {
|
} else {
|
||||||
newhei = defhei;
|
newhei = defhei;
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine our off-axis position
|
// determine our off-axis position
|
||||||
if (_offjust == LEFT || _offjust == TOP) {
|
if (_offjust == LEFT || _offjust == TOP) {
|
||||||
sy = insets.top;
|
sy = insets.top;
|
||||||
} else if (_offjust == RIGHT || _offjust == BOTTOM) {
|
} else if (_offjust == RIGHT || _offjust == BOTTOM) {
|
||||||
sy = insets.top + b.height - newhei;
|
sy = insets.top + b.height - newhei;
|
||||||
} else { // CENTER
|
} else { // CENTER
|
||||||
sy = insets.top + (b.height - newhei)/2;
|
sy = insets.top + (b.height - newhei)/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
child.setBounds(sx, sy, newwid, newhei);
|
child.setBounds(sx, sy, newwid, newhei);
|
||||||
sx += child.getSize().width + _gap;
|
sx += child.getSize().width + _gap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,31 +24,30 @@ import java.awt.*;
|
|||||||
|
|
||||||
public class VGroupLayout extends GroupLayout
|
public class VGroupLayout extends GroupLayout
|
||||||
{
|
{
|
||||||
public VGroupLayout (Policy policy, Policy offpolicy, int gap,
|
public VGroupLayout (Policy policy, Policy offpolicy, int gap, Justification justification)
|
||||||
Justification justification)
|
|
||||||
{
|
{
|
||||||
_policy = policy;
|
_policy = policy;
|
||||||
_offpolicy = offpolicy;
|
_offpolicy = offpolicy;
|
||||||
_gap = gap;
|
_gap = gap;
|
||||||
_justification = justification;
|
_justification = justification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VGroupLayout (Policy policy, int gap, Justification justification)
|
public VGroupLayout (Policy policy, int gap, Justification justification)
|
||||||
{
|
{
|
||||||
_policy = policy;
|
_policy = policy;
|
||||||
_gap = gap;
|
_gap = gap;
|
||||||
_justification = justification;
|
_justification = justification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VGroupLayout (Policy policy, Justification justification)
|
public VGroupLayout (Policy policy, Justification justification)
|
||||||
{
|
{
|
||||||
_policy = policy;
|
_policy = policy;
|
||||||
_justification = justification;
|
_justification = justification;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VGroupLayout (Policy policy)
|
public VGroupLayout (Policy policy)
|
||||||
{
|
{
|
||||||
_policy = policy;
|
_policy = policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VGroupLayout ()
|
public VGroupLayout ()
|
||||||
@@ -58,44 +57,43 @@ public class VGroupLayout extends GroupLayout
|
|||||||
@Override
|
@Override
|
||||||
protected Dimension getLayoutSize (Container parent, int type)
|
protected Dimension getLayoutSize (Container parent, int type)
|
||||||
{
|
{
|
||||||
DimenInfo info = computeDimens(parent, type);
|
DimenInfo info = computeDimens(parent, type);
|
||||||
Dimension dims = new Dimension();
|
Dimension dims = new Dimension();
|
||||||
|
|
||||||
if (_policy == STRETCH) {
|
if (_policy == STRETCH) {
|
||||||
dims.height = info.maxfreehei * (info.count - info.numfix) +
|
dims.height = info.maxfreehei * (info.count - info.numfix) + info.fixhei;
|
||||||
info.fixhei;
|
|
||||||
} else if (_policy == EQUALIZE) {
|
} else if (_policy == EQUALIZE) {
|
||||||
dims.height = info.maxhei * info.count;
|
dims.height = info.maxhei * info.count;
|
||||||
} else { // NONE or CONSTRAIN
|
} else { // NONE or CONSTRAIN
|
||||||
dims.height = info.tothei;
|
dims.height = info.tothei;
|
||||||
}
|
}
|
||||||
|
|
||||||
dims.height += (info.count - 1) * _gap;
|
dims.height += (info.count - 1) * _gap;
|
||||||
dims.width = info.maxwid;
|
dims.width = info.maxwid;
|
||||||
|
|
||||||
// account for the insets
|
// account for the insets
|
||||||
Insets insets = parent.getInsets();
|
Insets insets = parent.getInsets();
|
||||||
dims.width += insets.left + insets.right;
|
dims.width += insets.left + insets.right;
|
||||||
dims.height += insets.top + insets.bottom;
|
dims.height += insets.top + insets.bottom;
|
||||||
|
|
||||||
return dims;
|
return dims;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void layoutContainer (Container parent)
|
public void layoutContainer (Container parent)
|
||||||
{
|
{
|
||||||
Rectangle b = parent.getBounds();
|
Rectangle b = parent.getBounds();
|
||||||
DimenInfo info = computeDimens(parent, PREFERRED);
|
DimenInfo info = computeDimens(parent, PREFERRED);
|
||||||
|
|
||||||
// adjust the bounds width and height to account for the insets
|
// adjust the bounds width and height to account for the insets
|
||||||
Insets insets = parent.getInsets();
|
Insets insets = parent.getInsets();
|
||||||
b.width -= (insets.left + insets.right);
|
b.width -= (insets.left + insets.right);
|
||||||
b.height -= (insets.top + insets.bottom);
|
b.height -= (insets.top + insets.bottom);
|
||||||
|
|
||||||
int nk = parent.getComponentCount();
|
int nk = parent.getComponentCount();
|
||||||
int sx, sy;
|
int sx, sy;
|
||||||
int tothei, totgap = _gap * (info.count-1);
|
int tothei, totgap = _gap * (info.count-1);
|
||||||
int freecount = info.count - info.numfix;
|
int freecount = info.count - info.numfix;
|
||||||
|
|
||||||
// when stretching, there is the possibility that a pixel or more
|
// when stretching, there is the possibility that a pixel or more
|
||||||
// will be lost to rounding error. we account for that here and
|
// will be lost to rounding error. we account for that here and
|
||||||
@@ -103,81 +101,80 @@ public class VGroupLayout extends GroupLayout
|
|||||||
int freefrac = 0;
|
int freefrac = 0;
|
||||||
|
|
||||||
// do the on-axis policy calculations
|
// do the on-axis policy calculations
|
||||||
int defhei = 0;
|
int defhei = 0;
|
||||||
if (_policy == STRETCH) {
|
if (_policy == STRETCH) {
|
||||||
if (freecount > 0) {
|
if (freecount > 0) {
|
||||||
int freehei = b.height - info.fixhei - totgap;
|
int freehei = b.height - info.fixhei - totgap;
|
||||||
defhei = freehei / info.totweight;
|
defhei = freehei / info.totweight;
|
||||||
freefrac = freehei % info.totweight;
|
freefrac = freehei % info.totweight;
|
||||||
tothei = b.height;
|
tothei = b.height;
|
||||||
} else {
|
} else {
|
||||||
tothei = info.fixhei + totgap;
|
tothei = info.fixhei + totgap;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (_policy == EQUALIZE) {
|
} else if (_policy == EQUALIZE) {
|
||||||
defhei = info.maxhei;
|
defhei = info.maxhei;
|
||||||
tothei = info.fixhei + defhei * freecount + totgap;
|
tothei = info.fixhei + defhei * freecount + totgap;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
tothei = info.tothei + totgap;
|
tothei = info.tothei + totgap;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the off-axis policy calculations
|
// do the off-axis policy calculations
|
||||||
int defwid = 0;
|
int defwid = 0;
|
||||||
if (_offpolicy == STRETCH) {
|
if (_offpolicy == STRETCH) {
|
||||||
defwid = b.width;
|
defwid = b.width;
|
||||||
} else if (_offpolicy == EQUALIZE) {
|
} else if (_offpolicy == EQUALIZE) {
|
||||||
defwid = info.maxwid;
|
defwid = info.maxwid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the justification-related calculations
|
// do the justification-related calculations
|
||||||
if (_justification == LEFT || _justification == TOP) {
|
if (_justification == LEFT || _justification == TOP) {
|
||||||
sy = insets.top;
|
sy = insets.top;
|
||||||
} else if (_justification == CENTER) {
|
} else if (_justification == CENTER) {
|
||||||
sy = insets.top + (b.height - tothei)/2;
|
sy = insets.top + (b.height - tothei)/2;
|
||||||
} else { // RIGHT or BOTTOM
|
} else { // RIGHT or BOTTOM
|
||||||
sy = insets.top + b.height - tothei;
|
sy = insets.top + b.height - tothei;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the layout
|
// do the layout
|
||||||
for (int i = 0; i < nk; i++) {
|
for (int i = 0; i < nk; i++) {
|
||||||
// skip non-visible kids
|
// skip non-visible kids
|
||||||
if (info.dimens[i] == null) {
|
if (info.dimens[i] == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Component child = parent.getComponent(i);
|
Component child = parent.getComponent(i);
|
||||||
Constraints c = getConstraints(child);
|
Constraints c = getConstraints(child);
|
||||||
int newwid, newhei;
|
int newwid, newhei;
|
||||||
|
|
||||||
if (_policy == NONE || c.isFixed()) {
|
if (_policy == NONE || c.isFixed()) {
|
||||||
newhei = info.dimens[i].height;
|
newhei = info.dimens[i].height;
|
||||||
} else {
|
} else {
|
||||||
newhei = freefrac +
|
newhei = freefrac + ((_policy == STRETCH) ? defhei * c.getWeight() : defhei);
|
||||||
((_policy == STRETCH) ? defhei * c.getWeight() : defhei);
|
|
||||||
// clear out the extra pixels the first time they're used
|
// clear out the extra pixels the first time they're used
|
||||||
freefrac = 0;
|
freefrac = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_offpolicy == NONE) {
|
if (_offpolicy == NONE) {
|
||||||
newwid = info.dimens[i].width;
|
newwid = info.dimens[i].width;
|
||||||
} else if (_offpolicy == CONSTRAIN) {
|
} else if (_offpolicy == CONSTRAIN) {
|
||||||
newwid = Math.min(info.dimens[i].width, b.width);
|
newwid = Math.min(info.dimens[i].width, b.width);
|
||||||
} else {
|
} else {
|
||||||
newwid = defwid;
|
newwid = defwid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine our off-axis position
|
// determine our off-axis position
|
||||||
if (_offjust == LEFT || _offjust == TOP) {
|
if (_offjust == LEFT || _offjust == TOP) {
|
||||||
sx = insets.left;
|
sx = insets.left;
|
||||||
} else if (_offjust == RIGHT || _offjust == BOTTOM) {
|
} else if (_offjust == RIGHT || _offjust == BOTTOM) {
|
||||||
sx = insets.left + b.width - newwid;
|
sx = insets.left + b.width - newwid;
|
||||||
} else { // CENTER
|
} else { // CENTER
|
||||||
sx = insets.left + (b.width - newwid)/2;
|
sx = insets.left + (b.width - newwid)/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
child.setBounds(sx, sy, newwid, newhei);
|
child.setBounds(sx, sy, newwid, newhei);
|
||||||
sy += child.getSize().height + _gap;
|
sy += child.getSize().height + _gap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class MenuUtil
|
|||||||
KeyStroke accel)
|
KeyStroke accel)
|
||||||
{
|
{
|
||||||
JMenuItem item = createItem(name, mnem, accel);
|
JMenuItem item = createItem(name, mnem, accel);
|
||||||
item.addActionListener(l);
|
item.addActionListener(l);
|
||||||
menu.add(item);
|
menu.add(item);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -127,19 +127,16 @@ public class MenuUtil
|
|||||||
* @param name the item name.
|
* @param name the item name.
|
||||||
* @param mnem the mnemonic key for the item.
|
* @param mnem the mnemonic key for the item.
|
||||||
* @param accel the keystroke for the item or null if none.
|
* @param accel the keystroke for the item or null if none.
|
||||||
* @param target the object on which to invoke a method when the menu
|
* @param target the object on which to invoke a method when the menu is selected.
|
||||||
* is selected.
|
* @param callbackName the name of the method to invoke when the menu is selected.
|
||||||
* @param callbackName the name of the method to invoke when the menu
|
|
||||||
* is selected.
|
|
||||||
*
|
*
|
||||||
* @return the new menu item.
|
* @return the new menu item.
|
||||||
*/
|
*/
|
||||||
public static JMenuItem addMenuItem (
|
public static JMenuItem addMenuItem (
|
||||||
JMenu menu, String name, int mnem, KeyStroke accel,
|
JMenu menu, String name, int mnem, KeyStroke accel, Object target, String callbackName)
|
||||||
Object target, String callbackName)
|
|
||||||
{
|
{
|
||||||
JMenuItem item = createItem(name, Integer.valueOf(mnem), accel);
|
JMenuItem item = createItem(name, Integer.valueOf(mnem), accel);
|
||||||
item.addActionListener(new ReflectedAction(target, callbackName));
|
item.addActionListener(new ReflectedAction(target, callbackName));
|
||||||
menu.add(item);
|
menu.add(item);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -152,18 +149,16 @@ public class MenuUtil
|
|||||||
*
|
*
|
||||||
* @param menu the menu to add the item to.
|
* @param menu the menu to add the item to.
|
||||||
* @param name the item name.
|
* @param name the item name.
|
||||||
* @param target the object on which to invoke a method when the menu
|
* @param target the object on which to invoke a method when the menu is selected.
|
||||||
* is selected.
|
* @param callbackName the name of the method to invoke when the menu is selected.
|
||||||
* @param callbackName the name of the method to invoke when the menu
|
|
||||||
* is selected.
|
|
||||||
*
|
*
|
||||||
* @return the new menu item.
|
* @return the new menu item.
|
||||||
*/
|
*/
|
||||||
public static JMenuItem addMenuItem (
|
public static JMenuItem addMenuItem (
|
||||||
JMenu menu, String name, Object target, String callbackName)
|
JMenu menu, String name, Object target, String callbackName)
|
||||||
{
|
{
|
||||||
JMenuItem item = createItem(name, null, null);
|
JMenuItem item = createItem(name, null, null);
|
||||||
item.addActionListener(new ReflectedAction(target, callbackName));
|
item.addActionListener(new ReflectedAction(target, callbackName));
|
||||||
menu.add(item);
|
menu.add(item);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -181,17 +176,15 @@ public class MenuUtil
|
|||||||
*
|
*
|
||||||
* @param menu the menu to add the item to.
|
* @param menu the menu to add the item to.
|
||||||
* @param name the item name.
|
* @param name the item name.
|
||||||
* @param target the object on which to invoke a method when the menu
|
* @param target the object on which to invoke a method when the menu is selected.
|
||||||
* is selected.
|
* @param callbackName the name of the method to invoke when the menu is selected.
|
||||||
* @param callbackName the name of the method to invoke when the menu
|
|
||||||
* is selected.
|
|
||||||
*
|
*
|
||||||
* @return the new menu item.
|
* @return the new menu item.
|
||||||
*/
|
*/
|
||||||
public static JMenuItem addMenuItem (
|
public static JMenuItem addMenuItem (
|
||||||
JPopupMenu menu, String name, Object target, String callbackName)
|
JPopupMenu menu, String name, Object target, String callbackName)
|
||||||
{
|
{
|
||||||
JMenuItem item = createItem(name, null, null);
|
JMenuItem item = createItem(name, null, null);
|
||||||
item.addActionListener(new ReflectedAction(target, callbackName));
|
item.addActionListener(new ReflectedAction(target, callbackName));
|
||||||
menu.add(item);
|
menu.add(item);
|
||||||
return item;
|
return item;
|
||||||
@@ -200,10 +193,9 @@ public class MenuUtil
|
|||||||
/**
|
/**
|
||||||
* Creates and configures a menu item.
|
* Creates and configures a menu item.
|
||||||
*/
|
*/
|
||||||
protected static JMenuItem createItem (
|
protected static JMenuItem createItem (String name, Integer mnem, KeyStroke accel)
|
||||||
String name, Integer mnem, KeyStroke accel)
|
|
||||||
{
|
{
|
||||||
JMenuItem item = new JMenuItem(name);
|
JMenuItem item = new JMenuItem(name);
|
||||||
if (mnem != null) {
|
if (mnem != null) {
|
||||||
item.setMnemonic(mnem.intValue());
|
item.setMnemonic(mnem.intValue());
|
||||||
}
|
}
|
||||||
@@ -218,8 +210,7 @@ public class MenuUtil
|
|||||||
*/
|
*/
|
||||||
protected static class ReflectedAction implements ActionListener
|
protected static class ReflectedAction implements ActionListener
|
||||||
{
|
{
|
||||||
public ReflectedAction (Object target, String methodName)
|
public ReflectedAction (Object target, String methodName) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
// look up the method we'll be calling
|
// look up the method we'll be calling
|
||||||
_method = target.getClass().getMethod(methodName, METHOD_ARGS);
|
_method = target.getClass().getMethod(methodName, METHOD_ARGS);
|
||||||
@@ -231,8 +222,7 @@ public class MenuUtil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void actionPerformed (ActionEvent event)
|
public void actionPerformed (ActionEvent event) {
|
||||||
{
|
|
||||||
if (_method != null) {
|
if (_method != null) {
|
||||||
try {
|
try {
|
||||||
_method.invoke(_target, new Object[] { event });
|
_method.invoke(_target, new Object[] { event });
|
||||||
|
|||||||
@@ -231,26 +231,25 @@ public class ProximityTracker
|
|||||||
*/
|
*/
|
||||||
protected int binarySearch (int x)
|
protected int binarySearch (int x)
|
||||||
{
|
{
|
||||||
// copied from java.util.Arrays which I wouldn't have to have done
|
// copied from java.util.Arrays which I wouldn't have to have done had the provided a
|
||||||
// had the provided a means by which to binarySearch in a subset
|
// means by which to binarySearch in a subset of an array. alas.
|
||||||
// of an array. alas.
|
int low = 0;
|
||||||
int low = 0;
|
int high = _size-1;
|
||||||
int high = _size-1;
|
|
||||||
|
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
int mid = (low + high) >>> 1;
|
int mid = (low + high) >>> 1;
|
||||||
int cmp = (_records[mid].x - x);
|
int cmp = (_records[mid].x - x);
|
||||||
|
|
||||||
if (cmp < 0) {
|
if (cmp < 0) {
|
||||||
low = mid + 1;
|
low = mid + 1;
|
||||||
} else if (cmp > 0) {
|
} else if (cmp > 0) {
|
||||||
high = mid - 1;
|
high = mid - 1;
|
||||||
} else {
|
} else {
|
||||||
return mid; // key found
|
return mid; // key found
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return low; // key not found
|
return low; // key not found
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -143,9 +143,9 @@ public class SwingUtil
|
|||||||
Graphics g, String str, int x, int y, int width, int height)
|
Graphics g, String str, int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
FontMetrics fm = g.getFontMetrics(g.getFont());
|
FontMetrics fm = g.getFontMetrics(g.getFont());
|
||||||
int xpos = x + ((width - fm.stringWidth(str)) / 2);
|
int xpos = x + ((width - fm.stringWidth(str)) / 2);
|
||||||
int ypos = y + ((height + fm.getAscent()) / 2);
|
int ypos = y + ((height + fm.getAscent()) / 2);
|
||||||
g.drawString(str, xpos, ypos);
|
g.drawString(str, xpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -47,14 +47,13 @@ public class TaskMaster
|
|||||||
* subsequent dealings with the task master. The supplied observer (if
|
* subsequent dealings with the task master. The supplied observer (if
|
||||||
* non-null) will be notified when the task has completed.
|
* non-null) will be notified when the task has completed.
|
||||||
*/
|
*/
|
||||||
public static void invokeTask (String name, Task task,
|
public static void invokeTask (String name, Task task, TaskObserver observer)
|
||||||
TaskObserver observer)
|
|
||||||
{
|
{
|
||||||
// create a task runner and stick it in our task table
|
// create a task runner and stick it in our task table
|
||||||
TaskRunner runner = new TaskRunner(name, task, observer);
|
TaskRunner runner = new TaskRunner(name, task, observer);
|
||||||
_tasks.put(name, runner);
|
_tasks.put(name, runner);
|
||||||
// then start the runner up
|
// then start the runner up
|
||||||
runner.start();
|
runner.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,8 +64,7 @@ public class TaskMaster
|
|||||||
* <code>invoke</code> method of the <code>Task</code> interface.
|
* <code>invoke</code> method of the <code>Task</code> interface.
|
||||||
* Aborting tasks run in this way is not supported.
|
* Aborting tasks run in this way is not supported.
|
||||||
*/
|
*/
|
||||||
public static void invokeMethodTask (String name, Object source,
|
public static void invokeMethodTask (String name, Object source, TaskObserver observer)
|
||||||
TaskObserver observer)
|
|
||||||
{
|
{
|
||||||
// create a method task instance to invoke the named method and
|
// create a method task instance to invoke the named method and
|
||||||
// then run that through the normal task invocation mechanism
|
// then run that through the normal task invocation mechanism
|
||||||
@@ -79,29 +77,25 @@ public class TaskMaster
|
|||||||
*/
|
*/
|
||||||
protected static void removeTask (String name)
|
protected static void removeTask (String name)
|
||||||
{
|
{
|
||||||
_tasks.remove(name);
|
_tasks.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class TaskRunner extends Thread
|
protected static class TaskRunner extends Thread
|
||||||
{
|
{
|
||||||
public TaskRunner (String name, Task task, TaskObserver observer)
|
public TaskRunner (String name, Task task, TaskObserver observer) {
|
||||||
{
|
_name = name;
|
||||||
_name = name;
|
_task = task;
|
||||||
_task = task;
|
_observer = observer;
|
||||||
_observer = observer;
|
|
||||||
_mode = INVOKE;
|
_mode = INVOKE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes the task and then reports completion or failure later
|
* Invokes the task and then reports completion or failure later on the swing event
|
||||||
* on the swing event dispatcher thread. We need to ensure that
|
* dispatcher thread. We need to ensure that _mode and _result are visible to the various
|
||||||
* _mode and _result are visible to the various threads that
|
* threads that invoke this runnable so run() is synchronized. Oh how I love Chapter 17.
|
||||||
* invoke this runnable so run() is synchronized. Oh how I love
|
|
||||||
* Chapter 17.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void run ()
|
public synchronized void run () {
|
||||||
{
|
|
||||||
switch (_mode) {
|
switch (_mode) {
|
||||||
default:
|
default:
|
||||||
case INVOKE:
|
case INVOKE:
|
||||||
@@ -139,19 +133,18 @@ public class TaskMaster
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void abort ()
|
public void abort () {
|
||||||
{
|
log.warning("abort() not currently supported.");
|
||||||
log.warning("abort() not currently supported.");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected String _name;
|
protected String _name;
|
||||||
protected Task _task;
|
protected Task _task;
|
||||||
protected TaskObserver _observer;
|
protected TaskObserver _observer;
|
||||||
|
|
||||||
protected int _mode;
|
protected int _mode;
|
||||||
protected Object _result;
|
protected Object _result;
|
||||||
|
|
||||||
protected static final int INVOKE = 0;
|
protected static final int INVOKE = 0;
|
||||||
protected static final int COMPLETED = 1;
|
protected static final int COMPLETED = 1;
|
||||||
@@ -160,22 +153,19 @@ public class TaskMaster
|
|||||||
|
|
||||||
protected static class MethodTask implements Task
|
protected static class MethodTask implements Task
|
||||||
{
|
{
|
||||||
public MethodTask (String name, Object source)
|
public MethodTask (String name, Object source) {
|
||||||
{
|
|
||||||
_name = name;
|
_name = name;
|
||||||
_source = source;
|
_source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object invoke () throws Exception
|
public Object invoke () throws Exception {
|
||||||
{
|
|
||||||
// look up the named method on the source object and invoke it
|
// look up the named method on the source object and invoke it
|
||||||
Method meth = _source.getClass().getMethod(_name, (Class<?>[]) null);
|
Method meth = _source.getClass().getMethod(_name, (Class<?>[]) null);
|
||||||
meth.setAccessible(true);
|
meth.setAccessible(true);
|
||||||
return meth.invoke(_source, (Object[]) null);
|
return meth.invoke(_source, (Object[]) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean abort ()
|
public boolean abort () {
|
||||||
{
|
|
||||||
// aborting not supported
|
// aborting not supported
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -184,6 +174,5 @@ public class TaskMaster
|
|||||||
protected Object _source;
|
protected Object _source;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Hashtable<String,TaskRunner> _tasks =
|
protected static Hashtable<String, TaskRunner> _tasks = new Hashtable<String, TaskRunner>();
|
||||||
new Hashtable<String,TaskRunner>();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class Comparators
|
|||||||
*/
|
*/
|
||||||
public static int compare (byte value1, byte value2)
|
public static int compare (byte value1, byte value2)
|
||||||
{
|
{
|
||||||
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,7 +95,7 @@ public class Comparators
|
|||||||
*/
|
*/
|
||||||
public static int compare (char value1, char value2)
|
public static int compare (char value1, char value2)
|
||||||
{
|
{
|
||||||
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +104,7 @@ public class Comparators
|
|||||||
*/
|
*/
|
||||||
public static int compare (short value1, short value2)
|
public static int compare (short value1, short value2)
|
||||||
{
|
{
|
||||||
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,7 +113,7 @@ public class Comparators
|
|||||||
*/
|
*/
|
||||||
public static int compare (int value1, int value2)
|
public static int compare (int value1, int value2)
|
||||||
{
|
{
|
||||||
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,7 +122,7 @@ public class Comparators
|
|||||||
*/
|
*/
|
||||||
public static int compare (long value1, long value2)
|
public static int compare (long value1, long value2)
|
||||||
{
|
{
|
||||||
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
return (value1 < value2 ? -1 : (value1 == value2 ? 0 : 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -350,9 +350,9 @@ public class Config
|
|||||||
* @exception Exception thrown if any error occurs while loading or instantiating the class.
|
* @exception Exception thrown if any error occurs while loading or instantiating the class.
|
||||||
*/
|
*/
|
||||||
public Object instantiateValue (String name, String defcname)
|
public Object instantiateValue (String name, String defcname)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
return Class.forName(getValue(name, defcname)).newInstance();
|
return Class.forName(getValue(name, defcname)).newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -69,9 +69,9 @@ public class ConfigUtil
|
|||||||
* be found, null otherwise.
|
* be found, null otherwise.
|
||||||
*/
|
*/
|
||||||
public static Properties loadProperties (String path)
|
public static Properties loadProperties (String path)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return loadProperties(path, ConfigUtil.class.getClassLoader());
|
return loadProperties(path, ConfigUtil.class.getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,22 +79,21 @@ public class ConfigUtil
|
|||||||
* than the class loader used to load the <code>ConfigUtil</code> class.
|
* than the class loader used to load the <code>ConfigUtil</code> class.
|
||||||
*/
|
*/
|
||||||
public static Properties loadProperties (String path, ClassLoader loader)
|
public static Properties loadProperties (String path, ClassLoader loader)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
loadProperties(path, loader, props);
|
loadProperties(path, loader, props);
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link #loadProperties(String,ClassLoader)} but the properties are loaded into the
|
* Like {@link #loadProperties(String,ClassLoader)} but the properties are loaded into the
|
||||||
* supplied {@link Properties} object.
|
* supplied {@link Properties} object.
|
||||||
*/
|
*/
|
||||||
public static void loadProperties (
|
public static void loadProperties (String path, ClassLoader loader, Properties target)
|
||||||
String path, ClassLoader loader, Properties target)
|
throws IOException
|
||||||
throws IOException
|
|
||||||
{
|
{
|
||||||
InputStream in = getStream(path, loader);
|
InputStream in = getStream(path, loader);
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
throw new FileNotFoundException(path);
|
throw new FileNotFoundException(path);
|
||||||
}
|
}
|
||||||
@@ -218,9 +217,9 @@ public class ConfigUtil
|
|||||||
* be found, null otherwise.
|
* be found, null otherwise.
|
||||||
*/
|
*/
|
||||||
public static Properties loadInheritedProperties (String path)
|
public static Properties loadInheritedProperties (String path)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return loadInheritedProperties(path, ConfigUtil.class.getClassLoader());
|
return loadInheritedProperties(path, ConfigUtil.class.getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,7 +227,7 @@ public class ConfigUtil
|
|||||||
* target object.
|
* target object.
|
||||||
*/
|
*/
|
||||||
public static void loadInheritedProperties (String path, Properties target)
|
public static void loadInheritedProperties (String path, Properties target)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
loadInheritedProperties(path, ConfigUtil.class.getClassLoader(), target);
|
loadInheritedProperties(path, ConfigUtil.class.getClassLoader(), target);
|
||||||
}
|
}
|
||||||
@@ -238,7 +237,7 @@ public class ConfigUtil
|
|||||||
* rather than the class loader used to load the <code>ConfigUtil</code> class.
|
* rather than the class loader used to load the <code>ConfigUtil</code> class.
|
||||||
*/
|
*/
|
||||||
public static Properties loadInheritedProperties (String path, ClassLoader loader)
|
public static Properties loadInheritedProperties (String path, ClassLoader loader)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
loadInheritedProperties(path, loader, props);
|
loadInheritedProperties(path, loader, props);
|
||||||
@@ -254,7 +253,7 @@ public class ConfigUtil
|
|||||||
* path.
|
* path.
|
||||||
*/
|
*/
|
||||||
public static void loadInheritedProperties (String path, ClassLoader loader, Properties target)
|
public static void loadInheritedProperties (String path, ClassLoader loader, Properties target)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// first look for the files in the supplied class loader
|
// first look for the files in the supplied class loader
|
||||||
Enumeration<URL> enm = getResources(path, loader);
|
Enumeration<URL> enm = getResources(path, loader);
|
||||||
@@ -486,7 +485,7 @@ public class ConfigUtil
|
|||||||
*/
|
*/
|
||||||
public static InputStream getStream (String path)
|
public static InputStream getStream (String path)
|
||||||
{
|
{
|
||||||
return getStream(path, ConfigUtil.class.getClassLoader());
|
return getStream(path, ConfigUtil.class.getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -499,14 +498,14 @@ public class ConfigUtil
|
|||||||
*/
|
*/
|
||||||
public static InputStream getStream (String path, ClassLoader loader)
|
public static InputStream getStream (String path, ClassLoader loader)
|
||||||
{
|
{
|
||||||
// first try the supplied class loader
|
// first try the supplied class loader
|
||||||
InputStream in = getResourceAsStream(path, loader);
|
InputStream in = getResourceAsStream(path, loader);
|
||||||
if (in != null) {
|
if (in != null) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if that didn't work, try the system class loader (but only if it's different from the
|
// if that didn't work, try the system class loader (but only if it's different from the
|
||||||
// class loader we just tried)
|
// class loader we just tried)
|
||||||
try {
|
try {
|
||||||
ClassLoader sysloader = ClassLoader.getSystemClassLoader();
|
ClassLoader sysloader = ClassLoader.getSystemClassLoader();
|
||||||
if (sysloader != loader) {
|
if (sysloader != loader) {
|
||||||
@@ -526,12 +525,12 @@ public class ConfigUtil
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// try the path as is
|
// try the path as is
|
||||||
InputStream in = loader.getResourceAsStream(path);
|
InputStream in = loader.getResourceAsStream(path);
|
||||||
if (in != null) {
|
if (in != null) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
// try toggling the leading slash
|
// try toggling the leading slash
|
||||||
return loader.getResourceAsStream(togglePath(path));
|
return loader.getResourceAsStream(togglePath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Enumeration<URL> getResources (String path, ClassLoader loader)
|
protected static Enumeration<URL> getResources (String path, ClassLoader loader)
|
||||||
@@ -543,21 +542,21 @@ public class ConfigUtil
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// try the path as is
|
// try the path as is
|
||||||
Enumeration<URL> enm = loader.getResources(path);
|
Enumeration<URL> enm = loader.getResources(path);
|
||||||
if (enm.hasMoreElements()) {
|
if (enm.hasMoreElements()) {
|
||||||
return enm;
|
return enm;
|
||||||
}
|
}
|
||||||
// try toggling the leading slash
|
// try toggling the leading slash
|
||||||
return loader.getResources(togglePath(path));
|
return loader.getResources(togglePath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String togglePath (String path)
|
protected static String togglePath (String path)
|
||||||
{
|
{
|
||||||
if (path.startsWith("/")) {
|
if (path.startsWith("/")) {
|
||||||
return path.substring(1);
|
return path.substring(1);
|
||||||
} else {
|
} else {
|
||||||
return "/" + path;
|
return "/" + path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used when parsing inherited properties. */
|
/** Used when parsing inherited properties. */
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class IntIntMap
|
|||||||
|
|
||||||
public IntIntMap (int buckets, float loadFactor)
|
public IntIntMap (int buckets, float loadFactor)
|
||||||
{
|
{
|
||||||
_buckets = new Record[buckets];
|
_buckets = new Record[buckets];
|
||||||
_loadFactor = loadFactor;
|
_loadFactor = loadFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class IntIntMap
|
|||||||
|
|
||||||
public IntIntMap ()
|
public IntIntMap ()
|
||||||
{
|
{
|
||||||
this(DEFAULT_BUCKETS, DEFAULT_LOAD_FACTOR);
|
this(DEFAULT_BUCKETS, DEFAULT_LOAD_FACTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty ()
|
public boolean isEmpty ()
|
||||||
@@ -82,7 +82,7 @@ public class IntIntMap
|
|||||||
*/
|
*/
|
||||||
public int size ()
|
public int size ()
|
||||||
{
|
{
|
||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,28 +96,28 @@ public class IntIntMap
|
|||||||
ensureCapacity(_size + 1);
|
ensureCapacity(_size + 1);
|
||||||
|
|
||||||
int index = Math.abs(key)%_buckets.length;
|
int index = Math.abs(key)%_buckets.length;
|
||||||
Record rec = _buckets[index];
|
Record rec = _buckets[index];
|
||||||
|
|
||||||
// either we start a new chain
|
// either we start a new chain
|
||||||
if (rec == null) {
|
if (rec == null) {
|
||||||
_buckets[index] = new Record(key, value);
|
_buckets[index] = new Record(key, value);
|
||||||
_size++; // we're bigger
|
_size++; // we're bigger
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// or we replace an element in an existing chain
|
// or we replace an element in an existing chain
|
||||||
Record prev = rec;
|
Record prev = rec;
|
||||||
for (; rec != null; rec = rec.next) {
|
for (; rec != null; rec = rec.next) {
|
||||||
if (rec.key == key) {
|
if (rec.key == key) {
|
||||||
rec.value = value; // we're not bigger
|
rec.value = value; // we're not bigger
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prev = rec;
|
prev = rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
// or we append it to this chain
|
// or we append it to this chain
|
||||||
prev.next = new Record(key, value);
|
prev.next = new Record(key, value);
|
||||||
_size++; // we're bigger
|
_size++; // we're bigger
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,12 +206,12 @@ public class IntIntMap
|
|||||||
{
|
{
|
||||||
_modCount++;
|
_modCount++;
|
||||||
|
|
||||||
// abandon all of our hash chains (the joy of garbage collection)
|
// abandon all of our hash chains (the joy of garbage collection)
|
||||||
for (int i = 0; i < _buckets.length; i++) {
|
for (int i = 0; i < _buckets.length; i++) {
|
||||||
_buckets[i] = null;
|
_buckets[i] = null;
|
||||||
}
|
}
|
||||||
// zero out our size
|
// zero out our size
|
||||||
_size = 0;
|
_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -234,12 +234,12 @@ public class IntIntMap
|
|||||||
*/
|
*/
|
||||||
protected Record locateRecord (int key)
|
protected Record locateRecord (int key)
|
||||||
{
|
{
|
||||||
int index = Math.abs(key)%_buckets.length;
|
int index = Math.abs(key)%_buckets.length;
|
||||||
for (Record rec = _buckets[index]; rec != null; rec = rec.next) {
|
for (Record rec = _buckets[index]; rec != null; rec = rec.next) {
|
||||||
if (rec.key == key) {
|
if (rec.key == key) {
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ public class IntIntMap
|
|||||||
*/
|
*/
|
||||||
protected int removeImpl (int key, int defval)
|
protected int removeImpl (int key, int defval)
|
||||||
{
|
{
|
||||||
int index = Math.abs(key)%_buckets.length;
|
int index = Math.abs(key)%_buckets.length;
|
||||||
Record prev = null;
|
Record prev = null;
|
||||||
|
|
||||||
// go through the chain looking for a match
|
// go through the chain looking for a match
|
||||||
@@ -445,15 +445,14 @@ public class IntIntMap
|
|||||||
|
|
||||||
protected static class Record implements IntIntEntry
|
protected static class Record implements IntIntEntry
|
||||||
{
|
{
|
||||||
public Record next;
|
public Record next;
|
||||||
public int key;
|
public int key;
|
||||||
public int value;
|
public int value;
|
||||||
|
|
||||||
public Record (int key, int value)
|
public Record (int key, int value) {
|
||||||
{
|
this.key = key;
|
||||||
this.key = key;
|
this.value = value;
|
||||||
this.value = value;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getKey () {
|
public Integer getKey () {
|
||||||
return Integer.valueOf(key);
|
return Integer.valueOf(key);
|
||||||
@@ -497,29 +496,29 @@ public class IntIntMap
|
|||||||
|
|
||||||
class IntEntryIterator implements Iterator<IntIntEntry>
|
class IntEntryIterator implements Iterator<IntIntEntry>
|
||||||
{
|
{
|
||||||
public IntEntryIterator () {
|
public IntEntryIterator () {
|
||||||
this._modCount = IntIntMap.this._modCount;
|
this._modCount = IntIntMap.this._modCount;
|
||||||
_index = _buckets.length;
|
_index = _buckets.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNext () {
|
public boolean hasNext () {
|
||||||
checkMods();
|
checkMods();
|
||||||
// if we're pointing to an entry, we've got more entries
|
// if we're pointing to an entry, we've got more entries
|
||||||
if (_next != null) {
|
if (_next != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// search backward through the buckets looking for the next non-empty hash chain
|
// search backward through the buckets looking for the next non-empty hash chain
|
||||||
while (_index-- > 0) {
|
while (_index-- > 0) {
|
||||||
if ((_next = _buckets[_index]) != null) {
|
if ((_next = _buckets[_index]) != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// found no non-empty hash chains, we're done
|
// found no non-empty hash chains, we're done
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntIntEntry next () {
|
public IntIntEntry next () {
|
||||||
// if we're not pointing to an entry, search for the next non-empty hash chain
|
// if we're not pointing to an entry, search for the next non-empty hash chain
|
||||||
if (hasNext()) {
|
if (hasNext()) {
|
||||||
_prev = _next;
|
_prev = _next;
|
||||||
_next = _next.next;
|
_next = _next.next;
|
||||||
@@ -545,8 +544,8 @@ public class IntIntMap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _index;
|
private int _index;
|
||||||
private Record _next, _prev;
|
private Record _next, _prev;
|
||||||
private int _modCount;
|
private int _modCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public final class Log
|
|||||||
*/
|
*/
|
||||||
public Log (String moduleName)
|
public Log (String moduleName)
|
||||||
{
|
{
|
||||||
_moduleName = moduleName;
|
_moduleName = moduleName;
|
||||||
|
|
||||||
// try setting our default log level for this package
|
// try setting our default log level for this package
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -56,15 +56,15 @@ public class OneLineLogFormatter extends Formatter
|
|||||||
@Override
|
@Override
|
||||||
public String format (LogRecord record)
|
public String format (LogRecord record)
|
||||||
{
|
{
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
// append the timestamp
|
// append the timestamp
|
||||||
_date.setTime(record.getMillis());
|
_date.setTime(record.getMillis());
|
||||||
_format.format(_date, buf, _fpos);
|
_format.format(_date, buf, _fpos);
|
||||||
|
|
||||||
// append the log level
|
// append the log level
|
||||||
buf.append(" ");
|
buf.append(" ");
|
||||||
buf.append(record.getLevel().getLocalizedName());
|
buf.append(record.getLevel().getLocalizedName());
|
||||||
buf.append(" ");
|
buf.append(" ");
|
||||||
|
|
||||||
if (_showWhere) {
|
if (_showWhere) {
|
||||||
@@ -90,23 +90,23 @@ public class OneLineLogFormatter extends Formatter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// append the message itself
|
// append the message itself
|
||||||
buf.append(formatMessage(record));
|
buf.append(formatMessage(record));
|
||||||
buf.append(FormatterUtil.LINE_SEPARATOR);
|
buf.append(FormatterUtil.LINE_SEPARATOR);
|
||||||
|
|
||||||
// if an exception was also provided, append that
|
// if an exception was also provided, append that
|
||||||
if (record.getThrown() != null) {
|
if (record.getThrown() != null) {
|
||||||
try {
|
try {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
record.getThrown().printStackTrace(pw);
|
record.getThrown().printStackTrace(pw);
|
||||||
pw.close();
|
pw.close();
|
||||||
buf.append(sw.toString());
|
buf.append(sw.toString());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
buf.append("Format failure:").append(ex);
|
buf.append("Format failure:").append(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -70,9 +70,9 @@ public class PropertiesUtil
|
|||||||
public static Properties getSubProperties (
|
public static Properties getSubProperties (
|
||||||
Properties source, String prefix)
|
Properties source, String prefix)
|
||||||
{
|
{
|
||||||
Properties dest = new Properties();
|
Properties dest = new Properties();
|
||||||
extractSubProperties(source, dest, prefix);
|
extractSubProperties(source, dest, prefix);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,7 +89,7 @@ public class PropertiesUtil
|
|||||||
extractSubProperties(source, defs, defaultsPrefix);
|
extractSubProperties(source, defs, defaultsPrefix);
|
||||||
|
|
||||||
// now load up the desired properties
|
// now load up the desired properties
|
||||||
Properties dest = new Properties(defs);
|
Properties dest = new Properties(defs);
|
||||||
extractSubProperties(source, dest, prefix);
|
extractSubProperties(source, dest, prefix);
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
@@ -160,21 +160,21 @@ public class PropertiesUtil
|
|||||||
protected static void extractSubProperties (
|
protected static void extractSubProperties (
|
||||||
Properties source, Properties dest, String prefix)
|
Properties source, Properties dest, String prefix)
|
||||||
{
|
{
|
||||||
// extend the prefix to contain a dot
|
// extend the prefix to contain a dot
|
||||||
prefix = prefix + ".";
|
prefix = prefix + ".";
|
||||||
int preflen = prefix.length();
|
int preflen = prefix.length();
|
||||||
|
|
||||||
// scan the source properties
|
// scan the source properties
|
||||||
Enumeration<?> names = source.propertyNames();
|
Enumeration<?> names = source.propertyNames();
|
||||||
while (names.hasMoreElements()) {
|
while (names.hasMoreElements()) {
|
||||||
String name = (String)names.nextElement();
|
String name = (String)names.nextElement();
|
||||||
// skip unrelated properties
|
// skip unrelated properties
|
||||||
if (!name.startsWith(prefix)) {
|
if (!name.startsWith(prefix)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// insert the value into the new properties minus the prefix
|
// insert the value into the new properties minus the prefix
|
||||||
dest.put(name.substring(preflen), source.getProperty(name));
|
dest.put(name.substring(preflen), source.getProperty(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -173,17 +173,16 @@ public class Queue<T>
|
|||||||
*/
|
*/
|
||||||
public synchronized T get (long maxwait)
|
public synchronized T get (long maxwait)
|
||||||
{
|
{
|
||||||
if (_count == 0) {
|
if (_count == 0) {
|
||||||
try { wait(maxwait); } catch (InterruptedException e) {}
|
try { wait(maxwait); } catch (InterruptedException e) {}
|
||||||
|
|
||||||
// if count's still null when we pull out, we waited
|
// if count's still null when we pull out, we waited ourmaxwait time.
|
||||||
// ourmaxwait time.
|
if (_count == 0) {
|
||||||
if (_count == 0) {
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return get();
|
return get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class QuickSort
|
|||||||
*/
|
*/
|
||||||
public static <T> void sort (T[] a, Comparator<? super T> comp)
|
public static <T> void sort (T[] a, Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
sort(a, 0, a.length - 1, comp);
|
sort(a, 0, a.length - 1, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,7 +41,7 @@ public class QuickSort
|
|||||||
*/
|
*/
|
||||||
public static <T extends Comparable<? super T>> void sort (T[] a)
|
public static <T extends Comparable<? super T>> void sort (T[] a)
|
||||||
{
|
{
|
||||||
sort(a, 0, a.length - 1);
|
sort(a, 0, a.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +49,7 @@ public class QuickSort
|
|||||||
*/
|
*/
|
||||||
public static <T> void rsort (T[] a, Comparator<? super T> comp)
|
public static <T> void rsort (T[] a, Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
rsort(a, 0, a.length - 1, comp);
|
rsort(a, 0, a.length - 1, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,7 +72,7 @@ public class QuickSort
|
|||||||
public static <T> void sort (T[] a, int lo0, int hi0, Comparator<? super T> comp)
|
public static <T> void sort (T[] a, int lo0, int hi0, Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
// bail out if we're already done
|
// bail out if we're already done
|
||||||
if (hi0 <= lo0) {
|
if (hi0 <= lo0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ public class QuickSort
|
|||||||
public static <T> void rsort (T[] a, int lo0, int hi0, Comparator<? super T> comp)
|
public static <T> void rsort (T[] a, int lo0, int hi0, Comparator<? super T> comp)
|
||||||
{
|
{
|
||||||
// bail out if we're already done
|
// bail out if we're already done
|
||||||
if (hi0 <= lo0) {
|
if (hi0 <= lo0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ public class QuickSort
|
|||||||
public static <T extends Comparable<? super T>> void sort (T[] a, int lo0, int hi0)
|
public static <T extends Comparable<? super T>> void sort (T[] a, int lo0, int hi0)
|
||||||
{
|
{
|
||||||
// bail out if we're already done
|
// bail out if we're already done
|
||||||
if (hi0 <= lo0) {
|
if (hi0 <= lo0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ public class QuickSort
|
|||||||
public static <T extends Comparable<? super T>> void rsort (T[] a, int lo0, int hi0)
|
public static <T extends Comparable<? super T>> void rsort (T[] a, int lo0, int hi0)
|
||||||
{
|
{
|
||||||
// bail out if we're already done
|
// bail out if we're already done
|
||||||
if (hi0 <= lo0) {
|
if (hi0 <= lo0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,7 +381,7 @@ public class QuickSort
|
|||||||
public static <T> void sort (List<T> a, int lo0, int hi0, Comparator<T> comp)
|
public static <T> void sort (List<T> a, int lo0, int hi0, Comparator<T> comp)
|
||||||
{
|
{
|
||||||
// bail out if we're already done
|
// bail out if we're already done
|
||||||
if (hi0 <= lo0) {
|
if (hi0 <= lo0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,26 +34,26 @@ public class TerseLogFormatter extends Formatter
|
|||||||
@Override
|
@Override
|
||||||
public String format (LogRecord record)
|
public String format (LogRecord record)
|
||||||
{
|
{
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
// append the message itself
|
// append the message itself
|
||||||
buf.append(formatMessage(record));
|
buf.append(formatMessage(record));
|
||||||
buf.append(FormatterUtil.LINE_SEPARATOR);
|
buf.append(FormatterUtil.LINE_SEPARATOR);
|
||||||
|
|
||||||
// if an exception was also provided, append that
|
// if an exception was also provided, append that
|
||||||
if (record.getThrown() != null) {
|
if (record.getThrown() != null) {
|
||||||
try {
|
try {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
record.getThrown().printStackTrace(pw);
|
record.getThrown().printStackTrace(pw);
|
||||||
pw.close();
|
pw.close();
|
||||||
buf.append(sw.toString());
|
buf.append(sw.toString());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
buf.append("Format failure:").append(ex);
|
buf.append("Format failure:").append(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,6 +30,6 @@ public class DummyLogic implements Logic
|
|||||||
public void invoke (Application app, InvocationContext context)
|
public void invoke (Application app, InvocationContext context)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
// we're such a dummy that we do absolutely nothing.
|
// we're such a dummy that we do absolutely nothing.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ public abstract class CallMethodSpecialRule extends Rule
|
|||||||
public void end (String namespace, String name)
|
public void end (String namespace, String name)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
Object top = digester.peek();
|
Object top = digester.peek();
|
||||||
|
|
||||||
if (digester.getLogger().isDebugEnabled()) {
|
if (digester.getLogger().isDebugEnabled()) {
|
||||||
digester.getLogger().debug(
|
digester.getLogger().debug(
|
||||||
"CallSpecial " + StringUtil.shortClassName(this) +
|
"CallSpecial " + StringUtil.shortClassName(this) +
|
||||||
".parseAndSet(" + StringUtil.shortClassName(top) + ")");
|
".parseAndSet(" + StringUtil.shortClassName(top) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
parseAndSet(_bodyText, top);
|
parseAndSet(_bodyText, top);
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ public class SetNextFieldRule extends Rule
|
|||||||
public void end (String namespace, String name)
|
public void end (String namespace, String name)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
// identify the objects to be used
|
// identify the objects to be used
|
||||||
Object child = digester.peek(0);
|
Object child = digester.peek(0);
|
||||||
Object parent = digester.peek(1);
|
Object parent = digester.peek(1);
|
||||||
Class<?> pclass = parent.getClass();
|
Class<?> pclass = parent.getClass();
|
||||||
|
|
||||||
if (digester.getLogger().isDebugEnabled()) {
|
if (digester.getLogger().isDebugEnabled()) {
|
||||||
digester.getLogger().debug("Set " + pclass.getName() + "." +
|
digester.getLogger().debug("Set " + pclass.getName() + "." +
|
||||||
_fieldName + " = " + child);
|
_fieldName + " = " + child);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public class SetPropertyFieldsRule extends Rule
|
|||||||
|
|
||||||
// iterate over the attributes, setting public fields where applicable
|
// iterate over the attributes, setting public fields where applicable
|
||||||
for (int i = 0; i < attrs.getLength(); i++) {
|
for (int i = 0; i < attrs.getLength(); i++) {
|
||||||
String lname = attrs.getLocalName(i);
|
String lname = attrs.getLocalName(i);
|
||||||
if (StringUtil.isBlank(lname)) {
|
if (StringUtil.isBlank(lname)) {
|
||||||
lname = attrs.getQName(i);
|
lname = attrs.getQName(i);
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ public class SetPropertyFieldsRule extends Rule
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert the value into the appropriate object type
|
// convert the value into the appropriate object type
|
||||||
String valstr = attrs.getValue(i);
|
String valstr = attrs.getValue(i);
|
||||||
FieldParser parser = null;
|
FieldParser parser = null;
|
||||||
Object value;
|
Object value;
|
||||||
|
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ public class SimpleParser extends DefaultHandler
|
|||||||
@Override
|
@Override
|
||||||
public void characters (char ch[], int start, int length)
|
public void characters (char ch[], int start, int length)
|
||||||
{
|
{
|
||||||
_chars.append(ch, start, length);
|
_chars.append(ch, start, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endElement (String uri, String localName, String qName)
|
public void endElement (String uri, String localName, String qName)
|
||||||
{
|
{
|
||||||
finishElement(uri, localName, qName, _chars.toString().trim());
|
finishElement(uri, localName, qName, _chars.toString().trim());
|
||||||
_chars = new StringBuilder();
|
_chars = new StringBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,17 +74,17 @@ public class SimpleParser extends DefaultHandler
|
|||||||
public void parseStream (InputStream stream)
|
public void parseStream (InputStream stream)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// read the XML input stream and construct the scene object
|
// read the XML input stream and construct the scene object
|
||||||
_chars = new StringBuilder();
|
_chars = new StringBuilder();
|
||||||
XMLUtil.parse(this, stream);
|
XMLUtil.parse(this, stream);
|
||||||
|
|
||||||
} catch (ParserConfigurationException pce) {
|
} catch (ParserConfigurationException pce) {
|
||||||
throw (IOException) new IOException().initCause(pce);
|
throw (IOException) new IOException().initCause(pce);
|
||||||
|
|
||||||
} catch (SAXException saxe) {
|
} catch (SAXException saxe) {
|
||||||
throw (IOException) new IOException().initCause(saxe);
|
throw (IOException) new IOException().initCause(saxe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -44,21 +44,21 @@ public class XMLUtil
|
|||||||
* @param in the input stream containing the XML to be parsed
|
* @param in the input stream containing the XML to be parsed
|
||||||
*/
|
*/
|
||||||
public static void parse (DefaultHandler handler, InputStream in)
|
public static void parse (DefaultHandler handler, InputStream in)
|
||||||
throws IOException, ParserConfigurationException, SAXException
|
throws IOException, ParserConfigurationException, SAXException
|
||||||
{
|
{
|
||||||
XMLReader xr = _pfactory.newSAXParser().getXMLReader();
|
XMLReader xr = _pfactory.newSAXParser().getXMLReader();
|
||||||
|
|
||||||
xr.setContentHandler(handler);
|
xr.setContentHandler(handler);
|
||||||
xr.setErrorHandler(handler);
|
xr.setErrorHandler(handler);
|
||||||
|
|
||||||
xr.parse(new InputSource(in));
|
xr.parse(new InputSource(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The factory from whence we obtain XMLReader objects */
|
/** The factory from whence we obtain XMLReader objects */
|
||||||
protected static SAXParserFactory _pfactory;
|
protected static SAXParserFactory _pfactory;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
_pfactory = SAXParserFactory.newInstance();
|
_pfactory = SAXParserFactory.newInstance();
|
||||||
_pfactory.setValidating(false);
|
_pfactory.setValidating(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user