Java Native Access: Calling kernel32 GetShortPathNameA.

Published Date: January 15th, 2010
Category: General Practice |

Few days ago, my client was frustrated by the application which is not working properly in several cases. After a deep investigation, we find out that somehow, his tablet PC (windows-platform) is converting some paths into DOS 8.3 format. Which makes C:\Documents and Settings\ becomes C:\DOCUME~1\, but funnily also converting some paths in normal full Windows path. It causes some functions are not working because they are trying to match different format.

For example, we have two variables path and folderPath. Somehow, his machine read path in DOS 8.3 format, but read folderPath in full format. So when the line of code here is executed:

path.toLowerCase().contains(folderPath.toLowerCase())

it will always return false. Even though path is actually inside the folderPath.

Since my client was a continent apart from me, it’s not possible to investigate why the inconsistency happens, but the best I can do is trying to compare both ways. So the steps that popped out of my head are:

  1. Read kernel32.dll from Windows Library.
  2. Try to convert full folderPath to short DOS 8.3 format with kernel32 function, GetShortPathName with alias GetShortPathNameA.
  3. Match path with full path folderPath or, match path with short DOS 8.3 folderPath .
  4. If one of them is correct, then returns true.

I decide to use Java Native Access from https://jna.dev.java.net/. This library is LGPL. And so, here are two functions that makes it work:
1st function, matching path and folderPath:

private boolean checkInsideFolder(String path, String folderPath) {

boolean insideFolder = false;

byte[] shortt= new byte[256];

   //Call CKernel32 interface to execute GetShortPathNameA method

int a = CKernel32.INSTANCE.GetShortPathNameA(folderPath, shortt, 256);

   //Just check if platform = windows and CKernel32 returns a result

if(Platform.isWindows() && a !=0) {

String shortPath = Native.toString(shortt);

if(path.toLowerCase().contains(shortPath.toLowerCase()) ||

path.toLowerCase().contains(folderPath.toLowerCase())) {

insideFolder = true;

}

} else {

if(path.toLowerCase().contains(folderPath.toLowerCase())) {

insideFolder = true;

}

}

return insideFolder;

}

2nd function, CKernel32 interface which extends Kernel32 from JNA:

public interface CKernel32 extends Kernel32 {

CKernel32 INSTANCE = (CKernel32)

Native.loadLibrary("kernel32", CKernel32.class);

int  GetShortPathNameA (String LongName, byte[] ShortName, int BufferCount);

}

OK, so I hope it works!

MySQL is Oracle now.

Published Date: November 2nd, 2009
Category: Open Source |

The open source community is starting to hold their grip knowing the acquisition of Oracle for MySQL. Does it mean Oracle will slowly move mySQL into something further than only an open source? Or literally kill it?

For a loyal user of mySQL for many of my website, I certainly hope that it wouldn’t happen soon enough. If it does happen, then welcome PostgreSQL/Firebird. Jihaa!

Web 3.0, Web 2.0, put it all to the machines?

Published Date: July 1st, 2009
Category: General Practice, Rambling |

I write this post after interested on reading a new job opening post in a website that said the applicants should be a Web 2.0 strong believer to apply. This reminds me about the hype of web 3.0 generation, all the articles and people starts shouting, ‘welcome Web 3.0, goodbye web 2.0′. And somehow, reminds me of my final project back in college.

However, I believe that we won’t leave web 2.0 behind while we are going through web 3.0 generation. As web 2.0 is the starting point of breakthrough that men and machines could actually talk! The improvement from web 1.0 can be described as:

Web 1.0 : Static & read only

Web 2.0 : Collaborating, read & write, dynamic data through web services

Web 3.0 : Semantic web with structured metadata

Thanks to Web 2.0, now we could share everything about us, connect to other people, share pictures, and the social life can be broaden to a cyber world more than just chatting and sending file. And surely, this social interaction life should really support the next development of semantic web generation.

A simple example comes from Facebook. Eventhough this may be just a small picture of how we define web 3.0, Facebook has already develop some structured metadata which merged with its function as social network, and in the smarter way, with helps from its users! Let’s say the applications to choose your favourite artists or to rate movies. As users start to rate a movie, or choosing their favourite artists, we can gather these data:

1. How many females/males like this movie?

2. What range of age likes this movie the most?

3. Define relation between artists they like and their high rated movie.

4. The relation between their interests, musics and high rated movie.

By all the collaborations of all applications and process it to structured metadata, that gathered from users all over the internet, when a new user comes in, we have all the information to define what this user interested in, what she/he would like by seeing the similarity on our metadata database.

This is a very small example.

Imagine when all websites wrap their data on this structured metadata. Maybe all hotels in the world could give data of their availability, budget to spend, favorite breakfast menu, etc. So when we input ‘I have 300$ and would like 5 days holiday in Bali. My favorite meal is steak‘. And our sweet machine here will give exact information gathered from all over Bali hotels website and give the best recommendation to user.

This seems possible to do one day, and maybe, when web 3.0 is many steps ahead, you will be able to put ‘I’m a 28 yrs old female, looking for 30 yrs old man with a rolls royce or lamborghini, living in private villa, still single, available and good looking, maybe has a private jet and not a drug dealer’ and the computer will answer ‘please consider your option, look at the mirror and go to hell‘. :P

a bit cynical in this bright sunny day.

Published Date: April 15th, 2009
Category: General Practice |

Our first phase of the project is going to end in May. This can be the end of the project if it’s no longer funded, or it will be the end of our job if foundation will move the project to other vendor(s).

It’s already 7 months I’m working on this project. There are bore, tiredness, hatred, craziness, every wicked feelings because there are too many mysteries to solve, too many puzzles to arrange! It’s quite an interesting project, but really occupy your mind and exploit all abilities and space in our brain. This is funny cos I still work 8 hours a day, always go home on time (which is a very great culture in the history of IT company) but it feels like I have dealt with this project a whole time. It’s like hypnotizing.

Not being sentimental, but our IDE probably is feeling the same. It starts to not working properly, sometimes it’s showing everything is okay even though it’s not. Our CVS doesn’t working too good. Now it’s always error when we are updating from server which everybody is too lazy to find out why and fix it.

Me said to my friend “Now we’ll see, who’ll stands still in the end? The IDE ? The CVS ? The Foundation? The Project? or Us??”

the desk tag. finally!

Published Date: April 13th, 2009
Category: General Practice, Rambling |

After being tagged by Sasha on this post, and promised to post it many weeks ago (haha!), finally I come up with a private time to get pictures of my messy full ornaments desk!

Well… full ornaments ? Not really. Many ornaments ? Yes, indeed.

this side is almost \'untouch\' This is what I called the wall of shame :P

Let’s see those pins closer. Some of them given by friends, especially this one, here :

well… and this one, mmm… don’t believe it, it’s just a pin :

Well… more things in my desk, mostly unnecessary stuffs, nothing really related to work. I have this card handler, I put it there because I never remember our office address and even my office phone! A reminder from bible, Proverb 17:22, Laughter is a tranquilizer with no side effects, and there is also my figure collectibles which I put aside with birthday card from my office friends. Never forget, there must be food here in my desk *chuckles :

Moreover, post its. I do love post-it, but now I reduce usage of paper to support the life of trees. Do you know how many tree you cut just for printing unnecessary things. So now, I do use post it for important stuff, and for my work notes, I use desktop post-it!

There is one thing I hate from my desk, though. It’s when I always tangled with my headset wire (!x_x)

Ssh, please keep all stuffs in my desk confidential, there are maybe people who want it! Hihihihi…

It was when this project first initiated,I got the responsible to prepare architecture for it, I start to learn more about EJB and Web Services. I do believe that using EJB and Web Services are the right choice.

A glimpse about the architecture:

Frankly, designing architecture is a new thing for me, and it’s such a hard, long-thought, and breath-taking experience.

Basically, I will need a tool that will ease a bit of configurations job for Web Service, I read that eclipse can use WTP plug-in to create web service.

After I downloaded Eclipse Ganymede 3.4.1, and all the plug-ins needed for WTP (needs EMF, GEF, DTP, ouch!), as you can see here .

Before I actually can use the web service feature, I have to update SOA plug-in. I’m not really sure about this, but it surely makes a difference.

Alright, then I created a very simple EJB called EJBTest. Typical name for testing an EJB, hehee. When I try to create dynamic web project and add Web Service.

There is always this error:

IWAB03398E Error in generating WSDL from Java: java.lang.ClassNotFoundException: com.attempt.AttemptBean

After googling and stuck around the whole day, I finally found this site, and it’s saying:

There’s no plan to implement this enhancement given the current resource on the Web services
team. Please note that we now have support for Axis2 (the next generation SOAP runtime).
Even though the Axis2 tool in WTP currently does not support EJB Web service either, future
enhancement to support the creation of EJB Web service would likely be for the Axis2 runtime
rather than the Axis1 runtime.

Eclipse doesn’t support it. And why? I don’t know.

So then I download NetBeans IDE 6.1, and it’s completely solved.

set date format on java header template : netbeans.

Published Date: February 26th, 2009
Category: Java Practice |

Everytime I wish to create header template on netbeans, I always forget this small syntax : changing date format! And then got confused for the correct keyword on Google.

Basically to show date, simply put ${date} on header, and it will display : Feb 26, 2009.

To change this date format, e.g I want to change it to 26-Feb-2009, simply do the following :

${date?date?string(”dd-MMM-yyyy”)}

Voila!

in a new dimension…

Published Date: January 16th, 2009
Category: Rambling |

Well that title was too much. It’s maybe right when I said there is a new dimension in my head. A new kinda crazy way to think and contemplate.It’s a new year, and I don’t know why I felt like I was left so far behind from my imagination and my dream…

I hope this year is gonna be the year I can smile satisfied and understand why I run so slow in a while.

What’s the dream, actually? Well it’s a past dream which I have sacrificed for good. I know that whatever turns me 3.5 years ago, I would give up that dream because I had more important thing to do, and I’m not regret that. But this year, it’s amazing how I think differently. Life has been good to me lately, and it makes me wonder if I once again can catch that dream.

I know. I know. That will mean that I must leave this great life I already have, but it’s for a greater good, and it’s important to me.

So help me God :).

Scrum in one minute.

Published Date: November 5th, 2008
Category: General Practice |

Scrum is an approach of agile development concept.

Let says there are pigs and chickens. Based on this joke:

A pig and a chicken are walking down a road. The chicken looks at the pig and says, “Hey, why don’t we open a restaurant?” The pig looks back at the chicken and says, “Good idea, what do you want to call it?” The chicken thinks about it and says, “Why don’t we call it ‘Ham and Eggs’?” “I don’t think so,” says the pig, “I’d be committed but you’d only be involved.”

Now we see: Pigs are people which are committed and fully involved. They are so ‘dead’ if this project fails. But Chickens are interested on the project but not really affected since they are not committed but only involved.

Who are pigs?

  1. Product Owner
  2. Scrum Master (coach, fixer, gatekeeper -similar to project manager)
  3. Developer/Team

Who are chickens?

  1. Users
  2. Stakeholders
  3. Managers

And what do we do in Scrum. Take a look at this figure:

Scrum Overview

Let starts with what pigs do. Product owner will simply administer product backlog, which will contains list of requirement or maybe ‘wish-lists’ and the priority level of it.

Sprint backlog is a list of tasks for current sprint. It will be how and what to do for current sprint not more than 16 hours. If it is more than 16 hours it should be broken down further. Sprint is usually within period of 15-30 days.

Each day, there will be daily sprint burn down to list down the remaining tasks.

Why sprinting and why Scrum-ing?

By creating deliverable on each sprint stage, risk and possible problems can be seen at the early stage, and customer can be involved on development stage.

If there is any requirement changes, it can be done from early stage with reducing risk and minimal losses.

Okay pig, let’s get started!

*footnote of a struggling small pig in the end of the year.

The Padang-Padang.

Published Date: July 22nd, 2008
Category: Journey |

I was planning to conquer Blue Point on Sunday, but because the comfort Padang-Padang gave me, I stopped at Padang-Padang and not continuing my journey to Blue Point (Even a lot of people said , ‘o you stupid, it’s just a few step ahead!’).

Padang-padang is located after Dreamland beach, after passing Pecatu Resort (gate to dreamland), go straight until you find an Uluwatu temple, and go right to Labuan Sait road. Simply follow the road (where you might find several ‘bule’ with their surfboard heading the same way), and you will find the parking lot for padang-padang on the left side of the road.

Well, I followed an American with his surfboard riding a bike actually, I didn’t really know where Blue point was!

And I found this paradise :

Just like a paradise

In padang-padang you will feel the ultimate escape. With the purity of its beach, some natural caves, soft sands, it’s just a heaven! At some point, you’ll forget that you are in Indonesia, it’s like a place where all nationalities merge into one place.

Am I in Indonesia ?

And last, I take my time to enjoy the sun, the view, the wind…. just almost everything… especially those surfing boys. Teeheeehehehehe.

I take my time sun-bathing and playing sands :p

So, If you are visiting Bali, just go to this beach. You will amazed by its beauty :)