Re: [collections] Name that data structure

2005-07-05 Thread Tim O'Brien
Wendy, you could most certainly use a LRUMap with a fixed size.   Give 
each item a unique key and let the Map take care of uniqueness.  LRUMap 
will take care of discarding the least recently used entry once it 
reached the maximum defined size, and the Iterator returns most recently 
used to least recently used.  This would be the easiest way to do this, 
by far.


Or you could do something that takes more work, but I think it more fun:

Define a Predicate:

import java.util.Collection;
mport org.apache.commons.collections.Predicate;

public class UniqueInCollection implements Predicate {

   private Collection collection;
  
   public UniqueInCollection(Collection collection) {

   this.collection = collection;
   }
  
   public boolean evaluate(Object o) {

   return !collection.contains( o );
   }

}

Then use a CircularFifoBuffer married to the Predicate.  Only downside 
is that you have to catch IllegalArgumentException throw by 
PredicatedBuffer:


import java.util.Iterator;

import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.buffer.CircularFifoBuffer;
import org.apache.commons.collections.buffer.PredicatedBuffer;

public class RecentlyVisited {
  
   public static void main(String[] args) {
  
   Buffer buffer = new CircularFifoBuffer(5);

   Predicate unique = new UniqueInCollection(buffer);
  
   Buffer recentVisited = PredicatedBuffer.decorate(buffer, unique);
  
   add( recentVisited, Page 1 );

   add( recentVisited, Page 2 );
   add( recentVisited, Page 3 );
   add( recentVisited, Page 4 );
   add( recentVisited, Page 1 );
   add( recentVisited, Page 2 );
   add( recentVisited, Page 1 );
   add( recentVisited, Page 21 );
   add( recentVisited, Page 22 );
   add( recentVisited, Page 1 );
  
   Iterator i = buffer.iterator();

   while( i.hasNext() ) {
   String value = (String) i.next();
   System.out.println( value );
   }
  
   }
  
   public static void add(Buffer recentVisited, String page) {

   try {
   recentVisited.add( page );
   } catch( IllegalArgumentException iae ) {
   // do nothing, buffer will complain if predicate fails.
   }
   }

}


Mattias Jiderhamn wrote:


Possibly it could also be a MRU (Most Recently Used) cache.

At 2005-07-03 23:39, you wrote:


I'd say you were looking for an ordinary priority queue, where the
priority=the timestamp. Try the Heap class.

Sincerely,
Silas Snider

On 7/3/05, Wendy Smoak [EMAIL PROTECTED] wrote:
 I'm looking through the Collections API, but not finding exactly 
what I
 want... hoping someone who's more familiar with it can point me in 
the right

 direction.

 What I'm trying to do is more or less what you see on catalog sites 
where
 they'll list the most recent items you've looked at, newest on 
top.  So it's
 ordered (List), but has no duplicates (Set), and I need to have a  
max size.


 ListOrderedSet is almost there, except that it retains the 'old' 
position if

 you add the same item again.  (And has no max length.)

 So... before I either write it myself or extend ListOrderedSet to 
make it do
 what I want, does anyone have another suggestion?  And what would 
_you_ call

 it?

 Thanks,
 Wendy Smoak




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]









-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [collections] Name that data structure

2005-07-05 Thread Tim O'Brien

Tim O'Brien wrote:

Wendy, you could most certainly use a LRUMap with a fixed size.   Give 
each item a unique key and let the Map take care of uniqueness.  
LRUMap will take care of discarding the least recently used entry once 
it reached the maximum defined size, and the Iterator returns most 
recently used to least recently used.  This would be the easiest way 
to do this, by far.


Sorry, hit send too quickly, so that code compared to the LRUMap solution:

   Map map = new LRUMap(5);
  
   map.put( Page 1,  );

   map.put( Page 2,  );
   map.put( Page 3,  );
   map.put( Page 4,  );
   map.put( Page 5,  );
   map.put( Page 6,  );
   map.put( Page 7,  );
   map.put( Page 8,  );
   map.put( Page 9,  );
   map.put( Page 1,  );

   Iterator i = map.keySet().iterator();
   while (i.hasNext()) {
   String value = (String) i.next();
   System.out.println(value);
   }





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



DBCP: jocl and Configuration Parameters for ObjectPools

2005-07-05 Thread Mike Starkie
Is there a way to include the various configuration parameters for
GenericObjectPool and GenericKeyedObjectPool directly in a .jocl file?
 For instance, maxActive, timeBetweenEvictionRunsMillis, and
testWhileId.

Must these parameters be set explicitly on the pools or can they be
configured in the .jocl file somehow?

Looking for some example xml on any pool parameters if possible.

thanks,
Mike

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [csv] Creating a CSV component

2005-07-05 Thread Don Seiler
On 10:28 Sun 19 Jun , robert burrell donkin wrote:
 the discussions have moved onto dev but no consensus has been reached as
 yet. 
 
 On Tue, 2005-06-14 at 18:14 +0300, Emmanouil Batsis wrote:
  Just wanted to ask whether you folks have chosen what to use for this.

Is there any more information on this?  My situation has changed and if
anyone else wants to work on something under the cvs4j.sf.net umbrella
feel free to contact me and I'll transfer maintainership over to you.
Personally I'd still prefer to see it under commons.

-- 
Don Seiler
[EMAIL PROTECTED]

Public Key: http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0xFC87F041
Fingerprint: 0B56 50D5 E91E 4D4C 83B7  207C 76AC 5DA2 FC87 F041


pgpPnby6BJAbR.pgp
Description: PGP signature


FileUploadException - the request was rejected because it's size is unknown

2005-07-05 Thread Guhn Chang
I am using the FileUpload 1.1 library in Weblogic 8.1 SP4, and am trying to 
get uploading to work in portlets.  Whenever I try to parse my multipart 
content, I get an exception with the message the request was rejected 
because it's size is unknown.





Here are some relevant code snippets.



public void processAction(ActionRequest request, ActionResponse
response) throws PortletException
{
if (PortletFileUpload.isMultipartContent(request))
{

DiskFileItemFactory factory = new DiskFileItemFactory();
PortletFileUpload upload = new PortletFileUpload(factory);

try
{
List fileItems = upload.parseRequest(request);
FileItem item = (FileItem)fileItems.iterator().next();
File uploadedFile = new File(type + item.getName());
item.write(uploadedFile);
}
catch (Exception ex)
{
System.out.println(EXCEPTION: File upload request error:
 + ex.getMessage());
//ex.printStackTrace();
return;
}

...



My jsp file contains:

form action=portlet:actionURL / method=post
enctype=multipart/form-data
table width=100% cellspacing=0 cellpadding=3 
tr
tdTitle/td
td input type=text name=title/td
/tr
tr
tdDescription/td
td input type=text name=description/td
/tr
tr



tdFile/td
td input type=file name=upfile /td



/tr
/table
input type=submit name=doUpload value=upload/
input type=submit name=cancel value=cancel/
/form



I have tried this with size set and unset in  the input type=file 
section.


I have tried several forums already and gotten no responses.  Any 
direction/help would be appreciated.




-Guhn Chang
[EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [betwixt] NullPointerException in 0.7RC1

2005-07-05 Thread Glenn Goldenberg
i tried the test out on RC2 and it still looks good...

glenn

-Original Message-
From: robert burrell donkin
[mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 28, 2005 3:43 PM
To: Jakarta Commons Users List
Subject: RE: [betwixt] NullPointerException in 0.7RC1


On Mon, 2005-06-27 at 10:13 -0500, Glenn Goldenberg wrote:
 hi robert:
 
 I updated my local version of Betwixt with the patch and rebuilt.  The test 
 works fine now.
 
 Thanks for the fix!  

and thank you for finding the problem and testing the fix!

i'm going to go ahead and roll an RC2 very soon. i'd be grateful if you
would verify that it's ok (when it's cut).

- robert


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Transaction API, ReadWriteLock

2005-07-05 Thread LeRoy . Yanta




I'm trying to use the ReadWriteLock class to acquire a write lock on a file
in a servlet.  When I generate multiple threads of the servlet using a WTE
5.1 server in the WSAD 5.1 IDE, I'm not able to get ReadWriteLock to block
other servlet threads after the first servlet thread obtains the lock.  I'm
using two IE browser windows to generate the two servlet threads.  Below is
ReadWriteLock code I have in the servlet followed by the System.out.println
statements that are generated in the server log file during my test.

ReadWriteLock fileLock = new ReadWriteLock(new File(c:/logRec.txt,
loggerFacade);
try {
  System.out.println(before acquiring a lock  +
Thread.currentThread());
  boolean result =
fileLock.acquireWrite(Thread.currentThread(),Long.MAX_VALUE);
  System.out.println(lock result:  + result +   +
Thread.currentThread());
  Thread.sleep(2);
  System.out.println(after sleeping  + Thread.currentThread());
  FileWriter recFile = new FileWriter(c:/logRec.txt, true);
  recFile.write(text from testFileTran);
  recFile.close();
} catch (InterruptedException e) {
  e.printStackTrace(System.err);

} catch (IOException e) {
  e.printStackTrace(System.err);

} finally {
  fileLock.release(Thread.currentThread());
}

[7/5/05 8:26:03:326 CDT]  7c1477e SystemOut O before acquiring a lock
Thread[Servlet.Engine.Transports : 0,5,main]
[7/5/05 8:26:03:326 CDT]  7c1477e SystemOut O lock result: true
Thread[Servlet.Engine.Transports : 0,5,main]
[7/5/05 8:26:08:384 CDT] 24c3477d SystemOut O before acquiring a lock
Thread[Servlet.Engine.Transports : 1,5,main]
[7/5/05 8:26:08:384 CDT] 24c3477d SystemOut O lock result: true
Thread[Servlet.Engine.Transports : 1,5,main]
[7/5/05 8:26:23:335 CDT]  7c1477e SystemOut O after sleeping
Thread[Servlet.Engine.Transports : 0,5,main]
[7/5/05 8:26:28:382 CDT] 24c3477d SystemOut O after sleeping
Thread[Servlet.Engine.Transports : 1,5,main]


From reviewing the Transaction documentation and mailing list archives, I'm
not able to determine what I'm doing wrong.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [betwixt] NullPointerException in 0.7RC1

2005-07-05 Thread robert burrell donkin
great 

thanks

- robert

On Tue, 2005-07-05 at 11:11 -0500, Glenn Goldenberg wrote:
 i tried the test out on RC2 and it still looks good...
 
 glenn
 
 -Original Message-
 From: robert burrell donkin
 [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, June 28, 2005 3:43 PM
 To: Jakarta Commons Users List
 Subject: RE: [betwixt] NullPointerException in 0.7RC1
 
 
 On Mon, 2005-06-27 at 10:13 -0500, Glenn Goldenberg wrote:
  hi robert:
  
  I updated my local version of Betwixt with the patch and rebuilt.  The test 
  works fine now.
  
  Thanks for the fix!  
 
 and thank you for finding the problem and testing the fix!
 
 i'm going to go ahead and roll an RC2 very soon. i'd be grateful if you
 would verify that it's ok (when it's cut).
 
 - robert
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [DBUtils] BeanHandler has problem retrieving Dates ?

2005-07-05 Thread David Graham
It doesn't need to specifically check for Date because the first thing the
method does is an instanceof check.  So, if your bean property is a
java.util.Date and the JDBC driver returns a java.sql.Date or
java.sql.Timestamp the property should get set.

David


--- Henry Voyer [EMAIL PROTECTED] wrote:

 Hi everyone
 
 I just used DBUtils for a date retreival. And to my astonishement it
 doesnt
 get the Dates.
 I looked in the BasicRowProcessor.isCompatibleType() method, there is no
 Date reference.
 
 Is this normal ? and why?
 
 Regards
 
 Henry


Get Firefox!
http://www.mozilla.org/firefox/



 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Expressions, Collections, Filtering oh my..

2005-07-05 Thread Poppe, Troy

I've got a collection of a JavaBeans, it could be a plain-old-Java collection or
a Commons-Collection... Not really a concern...

I'm trying to find a way to provide the ability to write a JEXL-like expression
that would be applied against the collection of JavaBeans, and be able to
retrieve all of the JavaBeans that match that JEXL-like expression.

So far, looking at JEXL, it looks like it requires a JexlContext, but I don't 
see
or know how I would adapt my JavaBean properties to this.

Is there an out-of-the-binary way of filtering through my JavaBeans, and giving
me access to those that match some expression?

Thanks.

Troy


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Expressions, Collections, Filtering oh my..

2005-07-05 Thread Bernard, Shawn
JXPath allows you to write XPath expressions and run them against a Collection.

-Shawn

-Original Message-
From: Poppe, Troy [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 05, 2005 4:02 PM
To: 'commons-user@jakarta.apache.org'
Subject: Expressions, Collections, Filtering oh my..



I've got a collection of a JavaBeans, it could be a plain-old-Java collection or
a Commons-Collection... Not really a concern...

I'm trying to find a way to provide the ability to write a JEXL-like expression
that would be applied against the collection of JavaBeans, and be able to
retrieve all of the JavaBeans that match that JEXL-like expression.

So far, looking at JEXL, it looks like it requires a JexlContext, but I don't 
see
or know how I would adapt my JavaBean properties to this.

Is there an out-of-the-binary way of filtering through my JavaBeans, and giving
me access to those that match some expression?

Thanks.

Troy


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Expressions, Collections, Filtering oh my..

2005-07-05 Thread Stephen Colebourne

Poppe, Troy wrote:

I've got a collection of a JavaBeans, it could be a plain-old-Java collection or
a Commons-Collection... Not really a concern...

I'm trying to find a way to provide the ability to write a JEXL-like expression
that would be applied against the collection of JavaBeans, and be able to
retrieve all of the JavaBeans that match that JEXL-like expression.

So far, looking at JEXL, it looks like it requires a JexlContext, but I don't 
see
or know how I would adapt my JavaBean properties to this.

Is there an out-of-the-binary way of filtering through my JavaBeans, and giving
me access to those that match some expression?


With commons-collections, the best approach is to write a Predicate 
instance (typcially an inner class), and use CollectionUtils.filter or 
PredicateCollection to do the filtering. No specific JEXL handling though.


Stephen

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[DBUtils] QueryRunner.fillStatement is not static

2005-07-05 Thread Elifarley
The method 'QueryRunner.fillStatement' is not static even though no
instance state is referenced. Could it be officially changed into a static
method ?

(I need to use this functionality but I don't want to instantiate this
class just to use this method).

Regards,
Elifarley




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[Net] SocketException - Connection reset

2005-07-05 Thread David Leangen

Hello!

I keep coming across this problem when using FTP. I am able to successfully
retrieve a file from a remote server in passive mode, but afterwards, when I
try to logout, I get an IOError caused by a SocketException: Connection
reset.

There are several ways to work around this problem, but I am wondering if
anybody can tell me WHY this happens? Why would a remote server reset the
connection after the completion of a get? (Or IS it the remote server that's
causing the reset?) Also, why does this happen only sometimes, and not
consistently?


Any explanation or even a link to relevant doc would be very much
appreciated.


Cheers,
Dave




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[digester] Digester pinning objects in memory

2005-07-05 Thread Matt Goodwin
I am using commons-digester for creating some objects from some xml 
files.  When I look at this with JProbe Digester (and some other 
internal stuff are still referencing the object that is parsed.  The 
code is as follows, any help would be greatly appreciated: 


Digester digester = initializeDigester();
CommissionStatement commissionStatement = 
(CommissionStatement)digester.parse(new 
StringReader(FileUtils.readFile(file.getAbsolutePath(;

digester.clear();
digester=null;
...snip
clearCommissionStatement(commissionStatement);

private Digester initializeDigester() {
   Digester digester = new Digester();
   digester.setValidating(false);
   
digester.addObjectCreate(CommissionStatementVO,CommissionStatement.class);
   
digester.addObjectCreate(CommissionStatementVO/AgentStatementVO,AgentStatement.class);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/StatementDate,statementDate);
   
digester.addObjectCreate(CommissionStatementVO/AgentStatementVO/AgentInfoVO,AgentInfo.class);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/FirstName,firstName);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/Name,lastName);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/AgentId,agentId);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/Address1,address1);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/Address2,address2);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/City,city);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/State,state);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/Zip,zip);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/AgentType,agentType);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentInfoVO/DisbursementSource,disbursementSource);
   
digester.addSetNex(CommissionStatementVO/AgentStatementVO/AgentInfoVO,setAgentInfo,com.equitrust.commissionloader.beans.AgentInfo);
   
digester.addObjectCreate(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO,AgentStatementDetail.class);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/AgentNumber,agentNumber);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/ProductType,productType);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/FirstName,firstName);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/Name,lastName);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/EffectiveDate,effectiveDate);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/ProcessDate,processDate);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/OwnerName,ownerName);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/PolicyNumber,policyNumber);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/InitialPremium,initialPremium);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/CommissionRate,commissionRate);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/CommissionPremium,commissionPremium);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/Type,commissionType);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/AmountDue,amountDue);
   
digester.addSetNext(CommissionStatementVO/AgentStatementVO/AgentStatementLineVO,addAgentStatementDetail,com.equitrust.commissionloader.beans.AgentStatementDetail);
   
digester.addObjectCreate(CommissionStatementVO/AgentStatementVO/AgentEarningsVO,AgentEarning.class);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentEarningsVO/TaxableIncome,taxableIncome);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentEarningsVO/TaxableIncomeYTD,taxableIncomeYTD);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentEarningsVO/PositivePolicyEarnings,positiveEarnings);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentEarningsVO/NegativePolicyEarnings,negativeEarnings);
   
digester.addBeanPropertySetter(CommissionStatementVO/AgentStatementVO/AgentEarningsVO/NetPolicyEarnings,netEarnings);
   
digester.addSetNext(CommissionStatementVO/AgentStatementVO/AgentEarningsVO,setAgentEarning,com.equitrust.commissionloader.beans.AgentEarning);
   

[CLI] two different versions of commons-cli-1.0.jar?

2005-07-05 Thread Hansine Jensen

When you download from
http://jakarta.apache.org/site/downloads/downloads_commons-cli.cgi
you get cli-1.0.zip which is the original distribution from November 2002
containing commons-cli-1.0.jar corresponding to
http://svn.apache.org/repos/asf/jakarta/commons/proper/cli/tags/CLI_1_0/

But if you download
http://www.ibiblio.org/maven/commons-cli/jars/commons-cli-1.0.jar
or e.g. 
http://apache.usp.br/java-repository/commons-cli/jars/commons-cli-1.0.jar
you get a different archive containg two more classes, OptionValidator and 
Util.

This versions seems to be the one described at
http://jakarta.apache.org/commons/cli/apidocs/org/apache/commons/cli/package-summary.html
also claiming to be Commons CLI 1.0.

Can someone please explain what is going on here?

I wonder if there is a tag in svn for the maven version or if it is a 
snapshot of  
http://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk/


thanks,
Jesper

_
Log på MSN Messenger direkte på nettet  http://webmessenger.msn.com/


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [digester] Digester pinning objects in memory

2005-07-05 Thread Simon Kitching
On Tue, 2005-07-05 at 16:48 -0500, Matt Goodwin wrote:
 I am using commons-digester for creating some objects from some xml 
 files.  When I look at this with JProbe Digester (and some other 
 internal stuff are still referencing the object that is parsed.  The 
 code is as follows, any help would be greatly appreciated: 

Digester does keep a reference to the root object it creates. You can
clear this via a call to:
  Digester.resetRoot (since 1.7 only).

I don't see any other way that Digester could retain references to
created objects.

However this shouldn't be relevant; after you use the Digester object,
there shouldn't be any references to it. So the Digester will get
garbage-collected and therefore the root object isn't prevented from
being garbage-collected. It would therefore appear that your code is
holding on to the Digester reference after it has been used; if you fix
this then your problem should go away anyway.

Regards,

Simon


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Expressions, Collections, Filtering oh my..

2005-07-05 Thread Tim O'Brien
Here are two ways to do this, JXPath is easier as you won't have to 
write your own Predicate.


Say you have a collection of Person objects that you created with this code:

   Person person1 = new Person();
   person1.setName( Bill );
   person1.setAge( 12 );

   Person person2 = new Person();
   person2.setName( Amy );
   person2.setAge( 18 );

   Person person3 = new Person();
   person3.setName( Doug );
   person3.setAge( 25 );

   List personList =
   Arrays.asList( new Person[] { person1, person2, person3 } );

You can filter this collection using JXPath and an XPath expression that 
references the age property AS IF it were an XML attribute:


   JXPathContext context = JXPathContext.newContext( personList );
   Iterator iterator = context.iterate([EMAIL PROTECTED] = 18]);
   while( iterator.hasNext() ) {
   Object o  = (Object) iterator.next();
   System.out.println( Person:  + ((Person) o).getName());
   }

Or, you can write a custom JexlPredicate that takes an expression and 
evaluates each element in a Collection.  Here's code that filters a 
collection of Person beans and returns only those instances that have an 
age = 18:


  Predicate predicate = new JexlPredicate( object, object.age = 
18 );
 
  Collection canVote = CollectionUtils.select( personList, predicate );
  
   for( Object o : canVote ) {

   System.out.println( Person:  + ((Person) o).getName() );
   }

The JexlPredicate from this example would be the following class:

JexlPredicate.java

import org.apache.commons.collections.Predicate;
import org.apache.commons.jexl.Expression;
import org.apache.commons.jexl.ExpressionFactory;
import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.JexlHelper;

public class JexlPredicate implements Predicate {

   private String variable;
   private Expression e;

   public JexlPredicate(String variable, String expression) {
   this.variable = variable;
   try {
   this.e = ExpressionFactory.createExpression(expression);
   } catch (Exception e) {
   throw new RuntimeException(Error creating JEXL expression, e);
   }
   }

   public boolean evaluate(Object o) {
   JexlContext jc = JexlHelper.createContext();
   jc.getVars().put(variable, o);
  
   Boolean b;

   try {
   b = (Boolean) e.evaluate(jc);
   } catch (Exception e) {
   throw new RuntimeException(Error evaluating JEXL 
expression, e);

   }
   return b.booleanValue();
   }

}

/JexlPredicate.java

Poppe, Troy wrote:


I've got a collection of a JavaBeans, it could be a plain-old-Java collection or
a Commons-Collection... Not really a concern...

I'm trying to find a way to provide the ability to write a JEXL-like expression
that would be applied against the collection of JavaBeans, and be able to
retrieve all of the JavaBeans that match that JEXL-like expression.

So far, looking at JEXL, it looks like it requires a JexlContext, but I don't 
see
or know how I would adapt my JavaBean properties to this.

Is there an out-of-the-binary way of filtering through my JavaBeans, and giving
me access to those that match some expression?

Thanks.

Troy


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




 






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [CLI] two different versions of commons-cli-1.0.jar?

2005-07-05 Thread Simon Kitching
On Tue, 2005-07-05 at 23:43 +0200, Hansine Jensen wrote:
 When you download from
 http://jakarta.apache.org/site/downloads/downloads_commons-cli.cgi
 you get cli-1.0.zip which is the original distribution from November 2002
 containing commons-cli-1.0.jar corresponding to
 http://svn.apache.org/repos/asf/jakarta/commons/proper/cli/tags/CLI_1_0/
 
 But if you download
 http://www.ibiblio.org/maven/commons-cli/jars/commons-cli-1.0.jar
 or e.g. 
 http://apache.usp.br/java-repository/commons-cli/jars/commons-cli-1.0.jar
 you get a different archive containg two more classes, OptionValidator and 
 Util.
 This versions seems to be the one described at
 http://jakarta.apache.org/commons/cli/apidocs/org/apache/commons/cli/package-summary.html
 also claiming to be Commons CLI 1.0.
 
 Can someone please explain what is going on here?

I can confirm the above info is correct. It sure looks like a cock-up to
me.

It would appear that after the 1.0 release no-one updated the
currentVersion tag in project.xml and that at some later time someone
compiled the trunk code and published it on ibiblio as commons-cli-1.0
when it was actually a snapshot of trunk.

 
 I wonder if there is a tag in svn for the maven version or if it is a 
 snapshot of  
 http://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk/

It sure looks to me like the version on ibiblio (which Maven will
download) is a snapshot of some unknown state of trunk. The file on
ibiblio is dated 29 jan 2004 so I guess that's the date that the code is
from. The version# in project.xml was updated on 22 april 2004, so the
snapshot is certainly before that date.

I think the best thing to do would be to publish a cli-1.0.1 which is
identical to 1.0, ie copy tags/CLI_1_0 to CLI_1_0_1 then update the
version# and build a new release. The 1.0 release on ibiblio should then
be deleted. Yes this will break a whole bunch of existing projects that
depend on 1.0 - but I can't see any better way out of this.

Is there anyone from the CLI team willing to do this?

NB: This problem isn't anything to do with Maven.

Regards,

Simon



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]