Wednesday, July 04, 2007

BIRT: BIRT 2.2 has been released

Apparently, BIRT 2.2 has been released on June 29th. I wasn't following along enough with it and missed that little tid bit. But its out, so now I can upgrade from the release candidate's versions I have been using.

Java: Sorting Dates

Had someone ask a simple question in a forum today. They wanted to be able to sort dates in Java. The simple answer is that if you use any of the standard Java collections, you can use the Collection.sort method to do the sort. Or you could use a TreeSet... Below is an example.

package dateSort;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;

public class DateSort {
public static void main(String[] args) {
ArrayList dates = new ArrayList();
DateFormat parser = DateFormat.getDateInstance();

try {
dates.add(new Date());
dates.add(parser.parse("Jan 01, 2005"));
dates.add(parser.parse("Jan 01, 2003"));
} catch (ParseException e) {
e.printStackTrace();
}

for (Iterator i = dates.iterator(); i.hasNext();)
{
Date currentDate = (Date) i.next();
System.out.println(currentDate);
}

Collections.sort(dates);
System.out.println("After Sort:------------------");
for (Iterator i = dates.iterator(); i.hasNext();)
{
Date currentDate = (Date) i.next();
System.out.println(currentDate);
}
}
}


Phone: Hacking the Motorola Razr V3C

Much like the rest of sheep, I was almost caught up in the iPhone madness. Truth be told, it is a really cool device once you get your hands on it. It doesn’t do anything that any other mobile device doesn’t already do, its just that much more intuitive and stylish. I liked it so much, and features that I commonly need are right at my finger tips in such a user friendly way that I almost caved in. However, sanity took hold of my senses again and I reevaluated. Perhaps that spider from the MacBook did bite me and inject me with some sort of Apple loving poison. However, I withheld my impulse buying, and reassessed my mobile needs.

When I broke it down, there are only a few things I do wirelessly with my phone, such as read the news, that I would still like to do. So basic web browsing is needed. This is provided, although poorly, through my phones browser. So it would be nice to use some other browser, such as the one with my PDA or my Laptop. Second is Internet access. Often times I arrive in a city for an assignment, and I need directions, maps, and such, and the ones provided on my phone are piss poor. Having access to Yahoo or Google maps would be really nice. Also, I spend some time in airports, and I sure as hell am not going to pay what most airports are asking for Internet access. It would be nice if I could plug in my laptop to my phone and have Internet access. Make sense since my phone is Internet enabled. Plus, I would like to add custom MP3 Ringtones, just like all those slick little kiddies do with their phones nowadays.

Well, the problem was that my phone is a Motorola Razr V3C provided by Verizon, who after a little research, locks their phones down. My phone has all those features mentioned above, they are just locked out. As fortune would have it, some adventurous phone hackers have figured out how to unlock all those features that I so desire from my phone. These hacks will void the warranty on your phone, and in some cases the legality of these hacks are questionable, or are at least in that fair-use grey area.

First thing first, is I wanted to get Internet access to my phone for my laptop. This was the biggest thing since it would take care of 90 percent of my needs. After a little digging, and thanks to the good folks at HackTheRazr.com, I came across Motorola Driver Installer, which will install the Motorola USB Modem Driver, and clean the USB drivers anytime I change them, which will become important in the next few steps. Once installed, I plug my phone in, and now my phone recognizes as a USB Modem. This replaces phone charger drivers I had been using and adds additional functionality. Following the directions here, I was able to get the dial-up Internet access. This is the only part that is questionable to me in terms of legality, and I wasn’t able to find any definitive information regarding it, except that using the EVDO network was a violation of Verizons Terms of Service, and possibly a theft of service since they charge 60 bucks for their BroadBand over phone service. It seems that using the 1X hack mentioned on their page, however, is in the grey area since it is a service that Verizon provides to all Nation Wide subscribers, called NationalAccess. Its just a violation of the warranty to hack the phone.

So, I needed to setup a few tools to hack the phone to disable EVDO, and make a few other changes. This is called SEEM Editing. The Seem Edits I wanted to do are well documented on the HackTheRazr site, so I won’t duplicate them here. But the next steps I followed were to first learn about how to edit seems. Follow the steps very carefully here. Although it is not noteated in this document, when you install Phone Programmer and PST, and first plug in your phone, you will install new drivers for your phone, removing the USB Modem drivers. This is important to remember since you will not be able to use the dialer for Internet access, and you will also not be able to user certain other programs, such as BitPIM, with the PST drivers installed. In order to get that functionality back, you will need to use the Motorola Driver Installer again and select Clean and ReInstall from the options, which will revert you back to the USB Modem drivers. I suppose this is what the HackTheRazr author meant when he said we would be reinstalling drivers a lot when hacking the phone.

So, following the seem editing guide above, I enabled the Vibrate then Ring feature, which was something that my last cell phone had, that ircked me that this one did not. I also added the following other seem edits, as listed here.

-Enabled USB transfers

-Enabled MultiMedia Studio

-Enabled Dial Up Networking

-Enable File Access with QPST, or enable access to NVM (needed for enabling Dial Up Networking with my BlueTooth enabled PDA, as outlined here).

Then, with the seem edits I wanted out of the way, I followed the remaining steps in a few of the other guides. I tested out the Internet DUN via USB cable which worked great, and I tested out the DUN through Bluetooth with my PDA.

Using the BitPIM to narrow down my MP3’s and resample them, and P2kExplorer tools to install them, I was able to create my custom MP3’s for Ringtons. I was fairly exicted by this, until I ran into an issue. For some annoying reason, my MP3 ringtones wouldn’t play on my phone. The MP3’s played just fine, however when my phone ran, the tones didn’t come out. Turns out there is one extra step. In the root directory of the phone, or /a/ when browsing under P2kExplorer, there are two files that need to be deleted anytime I add a new MP3 to the phone, MyToneDB.db and TmpTneDB.db. Deleting these two files and restarting the phone gave me my MP3 ringtones.

To sum it up, my phone now gives me the mobile Internet access, the MP3 Ringtones, and has added new life to both the phone itself and my PDA, which has pretty much been discarded to the confines of my briefcase to never see the light of day until now. Why Verizon would not enable these features is beyond me. While not nearly as stylish as the iPhone, I now have all the mobile capabilities that I required, and got to get a little hands on to get them, so it has a little more meaning to me now. I can use the Internet for email while waiting in airports, I can use my PDA to pull up maps when I arrive places using my PDA without having to power my laptop up, and its available through BlueTooth, so I don’t need to plug in any wires or anything. With the addition of Opera Mobile to my PDA, the browser is actually usable and viewable. And I don’t need to pay out 500+ dollars to get an iPhone, face the service cancellation fees that Verizon would charge if I switched to AT&T, not to mention not having to put up with AT&T’s horrible service (5 year contract is a little steep, especially after reading some of the horror stories from the AT&T side of the iPhone launch). If Apple decided to expand their carrier base and add Verizon to the mix, I’ll seriously consider making that my next phone. In the meantime, I get the slight raised emotion of knowing I did something a little underhanded to get my phone the way it is, which satisfies the inner rebellious teenager that I refuse to let go of some 9 years after leaving my teens.

Saturday, June 30, 2007

Switcher: The Mac Guys Tried to Kill Me

I've been pretty excited over the past few days about the idea of getting a Mac. I've been a PC user for the past 20 years, so the idea of getting a Mac never really phased me until recently. Having seen some of the cool things, and with Parallels making application compatibility so seamless on the Intel based Macs, the concept of actually getting one has been gnawing at my mind. Well the opportunity finally came into fruition when my fiancee decided to buy a new laptop. After a few days of discussion, I sold her on a Mac. Kind of funny since I'm not a Mac user myself.

So the big day arrived. Not my wedding day, but the actual purchase date. My fiancee was kind enough to point out that I seemed more excited about buying the laptop than our wedding, but thats another story. So we get to the Apple Store, and wouldn't you know it, our timing couldn't have been worse. Turns out that it was also the same day the IPhone was released. So after seeing a line about half a mile long, and having no success convincing the door man to let us in, we decided to wander around the mall and wait for the line to disapait. I wasn't concerned with the media circus and foolish behavior of the IPhone crowd. But I believe some of my choice words must have made an impression on the door man. I mean, why the hell did an Apple Store have a door man anyway?

So after some grumbling, and after seeing how overpriced the Sony Vaios were in the midst of my stubborn reconsideration brought upon by being turned away due to the IPhone celebration, we returned about a half an hour later to a non-existent line. All that for people to play with the IPhone, yet so few bought one. Of course the whole ordeal left me with a bit of a bad taste in my mouth, so even though I was determined to buy a MacBook, I decided to be a little bit of an antagonist towards the Apple Store staff.

Now I wasn't being a prick by any means. I more or less decided to play the part of the ignorant consumer and poke a little fun at the whole Apple counter culture that I had apparently been suckered into. So while the door man was less than customer service friendly, my salesman was more willing to answer such questions as "Whats so special about the IPhone?", "Doesn't Windows Mobile and Blackberrys already do that?", and "Why should I get a Mac, doesn't my PC do all the same things?". Of course, these questions I already knew the answers to, I just wanted to amuse myself before an act that at this point I really felt was selling my soul.

The Apple Store staff did catch on to my ribbing though, so apparently I wasn't as clever as I thought I was. They joked with me a little with such retorts as "Well, a PC guy just couldn't understand", and "Well if you had told them at the door that you were a PC guy, we wouldn't have let you in". Was that salt in the wound?

Long story short, we walked out with a very cool new MacBook, a free IPod Nano since my fiancee is in college for her Masters, a customized Western Spanish keyboard layout, a free photo printer, a copy of Parallels, andthe sense that I had accomplished my goal, gotten some good rebates, and the knowledge that Dell could never match the bang-for-buck factor I had walked out of the store with. Of course, the end of the story comes when I, in my excitement, opened the box in my fiancees truck. Now, Im pinned in the passanger seat by the printer box, the fact that I can't recline due to a lack of a extended cab, and all the remaining doo dads and doo hickeys we came out of the store with. I couldn't wait to open the box and fire up the Mac. So thats exactly what I did. So here I am in her tiny truck, with the printer pinning my feet, the MacBook box wide open, and packaging material all over. I turn on the Mac, and was satisfied. That is until a friggin Brown Recluse Spider came crawling out of the packaging material right on my lap. So between the paralizing fear of one of the most media hyped venomous spiders staring me in the face, and the fact that I couldn't move with all the boxes and packaging material pinning me in my fiancees tiny ass passangers seat, I was pretty much sure my night was going to suck from that point on. Luckily, my fiancee, not having her mobility limited by her enthusiasm for technology, she squashed the dang thing with a card she had laying around. That leaves me to wonder if the Apple Store folks decided to have the last laugh. I'll tell you, in the Mac vs PC Commercials, they sure has hell didn't show the Mac guy trying to kill the PC guy with arachnids.

So with that adventure out of the way, I am very happy with my MacBook.
With all the reviews out there I don't need to repeat. A few assessments however.

1. Parallels does indeed rock. And although it is heavily advertised as working with Windows XP, it works with just about any PC based OS, just like VMWare. In fact, we went with a Windows 2000 install instead.

2. The only distinguishable difference between the VMWare Workstation and VMWare Server instances I can tell are the price tag and the integration of native client OS apps into the Host OS. Otherwise, it works pretty much the same, with you having to install the Tools inthe the client OS in order to get things like clipboard sharing, shared folders, etc.

3. Eclipse runs like crap under OS X. Either Apple or Eclipse needs to fix that. It runs faster with Parallels than it does natively under OS X.

4. The 30 day Microsoft Office for Mac Test Drives is a joke. Theres tons of comparisons between the Mac and PC versions of Microsoft Office, so I won't comment on those.

5. iLife, while being a fairly well rounded suite of applications, just doesn't warrant me ponying up extra money. I find the idea of installing shareware on a new system distasteful. If your going to put software on a new system, put the full version, don't waste my time with time limited trials and trying to sucker me into the .Mac online service.

6. Same goes with iWork. OpenOffice.org for Aqua just had their developer, so we may not be far off from the non-X11 version.

Overall though, the MacBook does rock. I will see how well my fiancee fares with it over the course of the next few months. That will help sway my decision to either buying one, or sticking with a PC and moving back to Ubuntu for my day to day tasks.

Friday, June 15, 2007

Media: Orb Networks

Recently I have been hearing a lot from various people about Orb Networks. Orb is a small utility that you run off of your PC that streams, or "MyCasts" the various media files you have on your system, such as movies, photos, music, etc. Whats really cool about this is that it lets you access your media anywhere in the world. So if you keep an MP3 collection on a home system, if its running orb, you can access it no matter where you are, assuming you have Internet connectivity. It also gives you access to file shares remotely, which in my opinion is a bit of a security hole. What really got me interested was a forwarded link talking about using a home console gaming system for streaming. So I decided to try it out.

For my experiment, I have the entire first season of Heros, which I have been meaning to catch up on, recorded onto my laptop. The original plan was to convert them to IPod video and watch them on the go, however I do enjoy evenings with the Mrs. on the couch watching shows. I have the Memorex portable monitor I use with my IPod video, and that has video out, but thats a pain to set up. So streaming directly from my laptop to one of my gaming systems became an attractive option. This was a feature of the hacked XBox's, so I wanted to give the XBox 360 built in media player a test.

First, I had to install the Orb client onto my laptop. After installing it, I configured it to not startup on Windows bootup. I also added my media folder to the list of folders for Orb to search that contains media files. After I installed it, I ran a virus scan and a malware scan using AdAware to make sure no spyware was installed with this application. I also did a quick packet capture while the service is running to see who the Orb client is phoning home to, like I do with other apps (and found some surprising results, which phone home to sites that are now blocked at my firewall). After a few minutes, I was convinced I wasn't seeing any bizarre connections, of course further investigation might be required.

Once installed, I had to sign up for an account. And that was all there was to it.

Once the Orb client was set up, from my XBox 360, I went to the Media/Video option, told it to connect to my system, and it displayed my folders.

A few things came up though. Performance was dismally bad over a 10Mbps network and using my wireless adaptor on my laptop. I had to move the 360 and my laptop over to my 100 Mbps switch. Once there, performance was acceptable. So apparently the adaptive feature doesn't quite work as advertised. Also, from the XBox 360, the fast forward and rewind buttons did not work. Not sure if this was an issue with Orb or with the Xbox. Additionally, I tried it out using the Wii. This worked fairly well also. But since I was accessing it using the Opera browser, the browser navigation bars never disappeared. That detracted from the viewing experience. Plus I had to connect to the Orb servers using the Wii, where as with the XBox 360 it connected directly to my laptop. So I think I'll be watching these from my 360 for the time being.

Some other features that I did not test were the ability to record TV using a TV Tuner card. When I set up ORB, it asked me my location and cable channel, and pulled up a TV Guide. Apparently I can watch my cable TV remotely also, just like with a Slingbox. Not sure if the hardware cost for a TV Tuner card and a dedicated machine is cheaper than a Slingbox, but I do like the added abilities of Orb.

Overall, I am impressed. Where as I was a little suspicious of this software at first, I found no evidence of spyware with it. So I am not sure how Orb stays in business or who pays for their servers. It did exactly what I needed for media streaming to my home entertainment system via my XBox 360, which opens new avenues for me. So, I can honestly say that I will be using Orb regularly.

Monday, June 11, 2007

Eclipse/Java: Using Hibernate for Data Access

I have been wanting to do a little work with Hibernate for some time now. I finally have a project that has come up where I can get the excuse to do so. The first step, however, was to get myself familiar with how Hibernate works.

For the better part of a few hours I have been messing around with getting Hibernate Synchronizer to work with Eclipse. There are quite a few annoying bugs, but so far it has been the best of the Hibernate Eclipse plugins. And I also used Hibernate version 3 as my library in my project. Since my test database is a SQL Server database, I also used jTDS JDBC Driver for Sql Server. I used this instead of the Microsoft driver since the Microsoft driver just plain didn’t work with Hibernate. For the record, I am using Eclipse 3.3 since the project I am working with uses BIRT 2.2 M6 reports, and I wanted my development under one roof, and its using JDK 1.5 R11.

The first step of my process was to create a regular Java project under Eclipse. I am sure to include the Hibernate Jar file and the jTDS Jar file in my classpath/included libraries.

Once created, I go to New, Other, and select Hibernate Configuration File. This will bring up the Hibernate Configuration File Utility as shown in Figure 1. Be sure you get your configuration right since this is the last time you will see this screen once you Finish. I have yet to figure out how to bring this back up. I enter the relevant information as shown.

Figure 1. The Hibernate Config Wizard

Next, I need to create the mapping file so Hibernate can generate my proxy classes to handle communication with the database and provide general getters, setters, and other classes. So I go to File/New/Other/Hibernate/Hibernate Mapping File. Assuming everything is OK with my connection, on the next screen I can click on the refresh button to get a list of the tables available for mapping. In my case, I ran into a bug using the Microsoft JDBC drivers here that wouldn’t let me connect. From my list of tables, I want a class to handle Opportunities, so I select the appropriate table from the list. Once done, I move over to the properties tab. Since this is SQL Server, I need to change the ID generator over from Sequences to Identity. Not sure exactly why this is necessary, but I’m not going to argue the point either. With Derby I was able to use Sequences, and I’d imagine Oracle would work just fine with this as well. If you use the wrong type, you will get an error when you run your resulting program complaining that the generator type is not supported in that database.

Figure 2. The Mapping Screen

Figure 3. The Mapping Properties

With the mapping file complete, now I can go through the motions of finishing up the configuration and generating the classes. First, I right mouse click on .hbm.xml file that gets creating with the mapping, and I select Add Mapping Reference. I encountered a bug here where when adding the mapping, it deletes the XML version and DOCTYPE tags from the hibernate.cfg.xml file, so be sure you have those handy just in case. If not, you will encounter an error when your finished program tries to access the hibernate configuration. Next, I open up the hbm.xml file, and change the value of the meta attribute=”sync-DAO” tag to true. This will generate the DAO objects for my test program. I am not sure why this defaults to false. Once done, I can save the file, then right mouse click on the hbm.xml file, and under the Hibernate Synchronizer menu, I select Synchronize Files. This will generate the needed classes.

That’s pretty much it. Now, I can use Hibernate to access my database. This saves me a lot of time. Instead of having to generate all the ORM classes myself, I can let Hibernate do the leg work for me. There is also a version of Hibernate for .Net. A few notes of bugs I came across. Like I mentioned above, the add Mapping Reference wipes out the XML header from the hibernate.cfg.xml file. I didn’t realize this until I went to run my program and Hibernate couldn’t recognize the format. The error I got was:

Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource TableOpportunity.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:98)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:88)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:79)
at com.digiassn.blogspot.TestHibernate.main(TestHibernate.java:13)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 10 more
Caused by: org.xml.sax.SAXParseException: Document is invalid: no grammar found.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
... 11 more


I also got errors when I didn’t include all of the necessary LIB files for Hibernate. This one confused me, since I thought the necessary files would be in the Hibernate3.jar file. However, I was mistaken. So be sure to include those. The exact error I got was:

Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.getNewConfiguration(_BaseRootDAO.java:192)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:90)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:79)
at com.digiassn.blogspot.TestHibernate.main(TestHibernate.java:13)



The third main issue I ran into was the fact that Hibernate refused to find my hibernate.cfg.xml file. This was pretty annoying. The error looked like so:


Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:98)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:88)
at com.digiassn.blogspot.HibernateClasses.base._BaseRootDAO.initialize(_BaseRootDAO.java:79)
at com.digiassn.blogspot.TestHibernate.main(TestHibernate.java:13)

What I ended up having to do was under the run configuration for my project, I had to specifically add the Project folders root, where my hibernate.cfg.xml file was located, to my classpath. I did this under the Classpath tab, clicking on User Entries, then advanced, Add Folder, and pointed to the root of my project.

Figure 4. Adding the path for the hibernate.cfg.xml

Now, for the example program I used to test the configuration. Basically I just want to to get all Opportunities from my table and display a couple of fields for them. My test program ends up looking like so:

package com.digiassn.blogspot;

import java.util.Iterator;
import java.util.List;

import com.digiassn.blogspot.HibernateClasses.TableOpportunity;
import com.digiassn.blogspot.HibernateClasses.dao.TableOpportunityDAO;
import com.digiassn.blogspot.HibernateClasses.dao._RootDAO;

public class TestHibernate {
public static void main(String[] args) {
_RootDAO.initialize();

TableOpportunityDAO td = new TableOpportunityDAO();
List opps = td.findAll();

for (Iterator i = opps.listIterator(); i.hasNext();) {
TableOpportunity t = (TableOpportunity) i.next();
System.out.println(t.getName() + " - " + t.getFrcstClsAmount()
+ " - " + t.getServiceStartDate() + " - "
+ t.getServiceBranch());
}

}
}