Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Regular expressions on blackberry

http://harmony.apache.org/

 

It can be used with j2me just fine if you port what you need.

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Regular expressions on blackberry

It cannot be compiled (I mean 1.2 version) because of J2ME incompatible Character class.

 

 

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Regular expressions on blackberry

It is not as easy as copy, paste, compile. Port what you need and alter the incompatible classes and then it will work fine.
Highlighted
Developer
Posts: 146
Registered: ‎11-05-2008
My Device: Not Specified

Re: Regular expressions on blackberry

if you have face any problem,just p.m. me with email.I will send you the code.
Developer
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Regular expressions on blackberry

Not sure what's being suggested regarding Apache Harmony...
Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ
Developer
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Regular expressions on blackberry

Ok... novice java programmer here (very experienced with oo, c++, other languages) so bear with me...

 

Just need a little guidance. I downloaded the regex java code from harmony as directed. Looking through what appear to be the most critical source files (Pattern.java, Matcher.java, a couple others) it looks like the following imports are required but not present in j2me:

 

java.io.Serializable;
java.util.ArrayList;
java.util.Arrays;
java.util.Iterator;
java.util.BitSet;
java.util.ListResourceBundle;

org.apache.harmony.regex.internal.nls.Messages;

 

Looks like I can easily replace the last one... it just looks up internationalized messages.

 

Regarding Serializable, my guess is that I can just remove "implements Serializable" where it appears and delete the serialization support functions (I see readObject() in Pattern.java) since I don't think I'll be needing them. Correct?

 

Regarding the others, they're clearly essential building blocks of the regex package so I'm guessing I'll need to find them somewhere else in the harmony source code and build them. How likey is this approach to work?

 

Thanks!

Nicholas

Developer
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Regular expressions on blackberry

Started to dig in a bit and already it's not looking good. Started with java.util.ArrayList, which imports java.lang.reflect.Array. Well java.lang.reflect.Array uses generics and other features that aren't supported by the blackberry rapc.

 

Array.java:41: generics are not supported in -source 1.3
(try -source 1.5 to enable generics)
    private static native Object multiNewArrayImpl(Class<?> componentType,

 

The suggestion to try -source 1.5 gives me hope even though everything I'm reading says 1.3 is the limit. Any hope here or should I look to a different regexp library? Rewriting everything to not use generics seems like too big a task...

 

Nicholas

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Regular expressions on blackberry

Cutting out the generics isn't too difficult. Remove the <?> usage, and cast where necessary.
Developer
Posts: 111
Registered: ‎12-16-2008
My Device: Not Specified

Re: Regular expressions on blackberry

SUCCESS! I tried getting Jakarta Oro to compile and with fairly minimal effort I was able to get it to work. I'm amazed myself actually.... I'll come back later and post more details after I clean things up but basically I had to do the following:

 

Replace some missing methods of the java.lang.Character class (isWhitespace(), isLetterOrDigit(), etc aren't supported).

Remove references to Serializable and Cloneable.

Remove code that uses java.util.HashMap (can be easily replaced later).

Remove some code that uses the missing Character.getType() method (can be easily replaced later).

 

Doing this all elegantly is going to be another challenge but I do have it working!

 

Thanks to all who offered advice. Probably wouldn't have tried this without your prompting.

 

Happy holidays,

Nicholas