Viewing By Category : Java / Main

Why Model with UML?


As you all know by know, ColdFusion is an excellent OO platform for web development and as our systems grew in complexity and maintainability we need to plan REALLY WELL!! The best way we can is UML, the Unified Modeling Language. The purpose of the Unified Modeling Language is to provide a language-independent and platform independent modeling notation. UML tools are as versatile as the UML is foundational.

I am so used to modeling in UML now that it is a REQUIREMENT for any project, no matter how small or how big. In that sense, some of you may be beginning to see the benefits of object modeling and may wonder how in the world to start. Well, I found a great article in the NetBeans website that touches on why to use UML and provides some great samples. Although it is directed to the Java developer, I believe a ColdFusion developer can gain some benefit from it.

Why Model with UML?





Converting structures/arrays to their string representations!


The following is a very useful JAVA tip for ColdFusion developers. Ever wanted to log a structure or array easily into a log file or use it as a string without actually looping and parsing to a string variable? Well, you always had the method right there lurking in the misterious but powerful Java world. The all ecompassing toString() method.

Actually all java.lang.Object inerit a toString() method as you can read in the java docs.

Below is the actual info:

toString

public String toString()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())

Returns: a string representation of the object.

As you can see, this method can be very useful. So how do I use it in Coldfusion? Very easily, jeje. look below:

//Create a structure
myStruct = structNew();
myStruct.today = now();
myStruct.name = "luis majano";
myStruct.url = "www.luismajano.com";

//Convert to string <cfoutput>#myStruct.toString()#</cfoutput>

And there you go ladies and gentleman!! Enjoy this quick tip!!





cfdirectory recurse emulation alternative: the Java Way (For BlueDragon, etc)


As you know, ColdBox is now fully supported for BlueDragon and Railo. However, to port it was a bit tedious when it came to the auto-registration engine for handlers, since I need to traverse the handlers directory recursively and create an array of handlers. This is so easy in Adobe ColdFusion, but BlueDragon and Railo, does not support it (BD 6, railo 1). Here is the Adobe ColdFusion code:

<cfdirectory action="list" recurse="true" directory="#HandlersPath#" name="HandlerListing" filter="*.cfc">

That is awesome!! So easy!! Well, to do it the Java Way, takes some patience and well, some insight into recursion. The following example is using the CF/JAVA hybrid notation, but the end result is the same as above. And with some speed tests, the code actually compares, not that much of a slow down. So :)

Here is my call to the recursion, the entry point:

<!--- Get recursive Array listing --->
<cfset HandlerArray = recurseListing(HandlerArray, HandlersPath, HandlersPath)>

What I do is call my recurseListing method with the handlerArray I want the results in, the handlersPath into the initial directory and the working directory. Why do I send in the HandlerPath again? Well, I do it, to actually clean the path to show me the invocation paths, mumbo jumbo!! Give me the code!! Here it is:

Remember that this code is not to get the query like cfdirectory, it could, but you will have to do that, I am just showing how I solved my problem. This is a great exercise also.

<cffunction name="recurseListing" access="private" output="false" returntype="array">
   <cfargument name="fileArray" type="array" required="true">
   <cfargument name="Directory" type="string" required="true">
   <cfargument name="HandlersPath" type="string" required="true">
   <cfscript>
   //Init the oDirectory object with the initial working directory (Java File Object)
   var oDirectory = CreateObject("java","java.io.File").init(arguments.Directory);
   //Get an array listing of the objects in the directory
   var Files = oDirectory.list();
   //My Index.
   var i = 1;
   //My temp File Object
   var tempfile = "";
   //My clean handler string.
   var cleanHandler = "";

   //Loop Through listing if any files found.
   for ( i=1; i lte arrayLen(Files); i=i+1 ){
      //get first File reference as a File Object
      tempFile = CreateObject("java","java.io.File").init(oDirectory,Files[i]);
      //Directory Check for recursion, if directory, then recurse.
      if ( tempFile.isDirectory() ){
         //recurse, directory found, send in the new directory path.
         arguments.fileArray = recurseListing(arguments.fileArray,tempFile.getPath(), arguments.HandlersPath);
      }
      else{
         //File found          //Filter only cfc's, I could have used a Filter Java object, but was lazy.
         if ( listlast(tempFile.getName(),".") neq "cfc" )
            continue;
         //Clean entry by using Handler Path (For my specific purposes)
         cleanHandler = replacenocase(tempFile.getAbsolutePath(),arguments.handlersPath,"","all");
         //Clean OS separators accordingly
         if ( getSetting("OSFileSeparator",1) eq "/")
            cleanHandler = removeChars(replacenocase(cleanHandler,"/",".","all"),1,1);
         else
            cleanHandler = removeChars(replacenocase(cleanHandler,"\",".","all"),1,1);
         //Clean Extension right off baby
         cleanHandler = getPlugin("fileUtilities").ripExtension(cleanhandler);
         //Add data to array, a cleaned Handler, thank you GOD, bless you.
         ArrayAppend(arguments.fileArray,cleanHandler);
      }
   }
   //else return the empty array or filled array.
   return arguments.fileArray;
   </cfscript>
</cffunction>

There you go, you can follow the comments to tell you what I did. This is an awesome exercise and shows you how ColdFusion is really powerful by leveraging its Java backbone. When things like this just work, it just amazes me of how ColdFusion has evolved and how EASY it is to overcome problems by leveraging Java. Viva Java Mis Amigos!! Viva!! Viva!!

Hope you enjoy this little java/cf/recursion tutorial. This example shows potential of how you can build your own recursion methods.





Java 6 is out and its open source!!


If you have not heard this, SUN just launched Java SE 6 and made it open source!!!

WOW!!!

Open java Feature

Java SE 6

So please check it out.





Argo UML a great UML documentation Tool


If you like documentation like me!! Well, I guess I am kinda in the dark here since not many people like documentation. This is the tool for you. I am now using it more and more. It is called ArgoUML and you can find it here:

http://argouml.tigris.org/

It can be used either through Java Web Start or a full package download. Give it a try and please DOCUMENT!!!

If you want people to use your software to build software, then document. Make it easy!!





Netbeans on MAC, cvs over ssh connection problems


I need help trying to make netbeans 5.0 connect to my CVS repository via SSH. I have created my ssh keygen pairs on my laptop and on the server, so when I go into the terminal and type:

ssh -l luis www.domain.com

I get logged in directly without any challenge. My key pairs work. I then go to Netbeans to the CVS module and click checkout.

I fill out the EXT part of the repository and for ssh connection I choose external shell and type:

ssh -l luis www.domain.com

Then click on next and it says "Checking network connection...."

It stays there forever.....

I am not behind a firewall or proxy. So I have no clue whatsoever, what wuold be wrong. Under Eclipse, cvs just connects fine!! So its not my connection.

Please help!!! Netbeans is my IDE of choice for JAVA development, but I need to start verisoning using CVS and I cannot make this work. Thanks





Oracle's SQL Developer, Better than Toad


Finally Oracle came up with their own graphical tool for creating and browsing database objects. This is the perfect companion to Oracle XE. The look and feel is great and the responsiveness of the application is amazing. It has all the tools that I need as an Oracle developer to finally develop on any platform. Yep, totally JAVA!!! This is amazing!! The tool has SQL worksheets, SQL formatting, PL/SQL snippets, a great help system, a great PL/SQL editor, which will keep beign improved on. Overall, the application is great, and best of all, I can finally run this on my Mac and get rid of my DB PC. Ohh, and did I mention that it is also free!! Thank you Oracle!!

Oracle SQL Developer is a new, free graphical tool that enhances productivity and simplifies database development tasks. With SQL Developer, you can browse database objects, run SQL statements and SQL scripts, and edit and debug PL/SQL statements. You can also run any number of provided reports, as well as create and save your own. SQL Developer can connect to any Oracle Database version 9.2.0.1 and later. We support SQL Developer running on Windows, Linux and Mac OSX.

Link: http://www.oracle.com/technology/products/database/sql_developer/index.html

Anyways, here are some good screenshots for you:





Java's gettickcount(), How to get the current time in milliseconds


Coldfusion has a great function called "gettickcount()" which basically gives you the current time in milliseconds. This is a great function to time code. Look at the example below:

<cfset stime = getTickCount()>
<!--- All my code to time here --->
<cfloop from="1" to="100" index="i">
<cfoutput>testing #i#</cfoutput>
<!--- Make a call here --->
</cfloop>
<cfset totalTime = getTickCount() - stime>
<cfoutput>The total time of execution for the code was: #totalTime#</cfoutput>

This utility is great. The question is, how do I do this in Java?? Well very simple, we use the System class. The following is a simple snippet of how to time in java.

double stime = System.currentTimeMillis();
//My Code Here
for(int i=0;i< 1000; i++){
System.out.println(i);
}
double TotalTime = System.currentTimeMillis() - stime;
//Display Total Time
System.out.println("Total Time of Execution: " + TotalTime + "ms.");

There you go!! Now you can time your java code.





Coldfusion-Java Snippet: Get your Operating System's File Separator.


Every wonder a nice, quick and easy way of getting your Operating System's file separator character??

Well, I have several times. Thanks to our collaborator Ariel Gonzalez, and his java expertise. We take a look at the java.lang.System class and its getProperty() Method.

There are several useful properties that you can get from this class, some of them are listed below:

[More]





Coldfusion Snippet: Make a sleep timer using Java


This snippet utilizes the power of java to create an execution sleep timer. There are various applications for this snippet, but the purpose of the snippet is to provide you with a mechanism of making the coldfusion thread sleep for a period of time. Please be careful when setting the timer variable since it might just lock the execution thread.

I have also included a copy-paste snippet of my actual CFC function.

The snippet is actually very simple:

<cfset thread = CreateObject("java", "java.lang.Thread")>
<cfset thread.sleep(arguments.milliseconds)>

[More]




More Entries

 


ColdBox 2.6.3 : RENEWED