Getting started with Flex - Setting up Development Environment

September 4th, 2009

The first step in developing an enterprise level flex application is setting up a development environment. Adobe offers an eclipse based development tool called Flex builder that provides a variety of features making Flex development a breeze. This flex builder comes in two flavors: a standalone IDE and an eclipse plugin. Since I will be developing Java based Flex applications, I decided to install the plugin version of the Flex builder in my favorite MyEclipse IDE.

We start with MyEclipse installation.

  1. Download the MyEclipse 7.5 “All in One” installer from MyEclipse site
  2. Once the download is complete, click on the installer file to start the installation

    myeclipse-1
  3. MyEclipse would then prepare and validate the installation.

    myeclipse-3
  4. Upon completion of step 3, you will be presented with the screen below:

    myeclipse-4
  5. Click on Launch to install the software.

    myeclipse-31
  6. After installation is complete, MyEclipse will launch itself. Select the default workspace and hit ok.

Now we are ready to install the Flex Builder Plugin.

  1. Download the Flex Builder 3 Plugin from Adobe site.
  2. Upon completion of the download, double click the installer file to launch the installation.

    1
    2
  3. On the next screen, select the language and hit Ok.

    3
  4. Accept the license agreement and hit Next.
    5
  5. On the next screen you can customize the Flex Builder Plugin location. Just accept the default location and hit Next.

    6
  6. The next screen asks for an Eclipse installation folder. DO NOT SPECIFY AN EXISTING ECLIPSE INSTALLATION LOCATION. Create a new folder called “eclipse” in your file system (in my case I created it under C drive) and provide that location to the installer. Hit Next.

    7
  7. On the next screen click “Proceed with Caution”.
    8
  8. Hit Next and then Install to start the installation.

    9

    10
  9. Wait for the installation to complete.
    11
  10. Upon completion, you should see the following screen.
    12

Integrating MyEclipse 7.5 and Flex Builder Plugin

  1. Go to Add/Remove Software in MyEclipse 7.5.
    13
  2. Select Personal Software and click Add.
    21
  3. On the next screen, click Add Local.
    31
  4. Select “com.adobe.flexbuilder.update.site” folder in your Flex Builder Plugin install folder and click ok.
    4
  5. Select “Flex Builder 3″ and hit Next.
    51
  6. On the following screen hit Apply.
    61
  7. MyEclipse would perform a validation of the install.
    71
  8. Accept the License agreement and hit Next.
    81
  9. Click Update to trigger software update.
    91

    101
  10. Once the update is complete, click Yes to restart MyEclipse.
    111

Changing Flex SDK installation location

  1. Go to “Installed Flex SDKs” in MyEclipse under Window->Preferences->Flex. You should see two SDKs installed with errors next to them.
    121
  2. Select Flex 0.0 and hit Edit. Click Browse in the popup and browse for 2.0.1 SDK located under /sdks/2.0.1. Hit Ok.
    131
  3. Repeat step 2 for Flex 0.0(1) and select the 3.2.0 SDK folder.
  4. This completes the plugin installation. Restart MyEclipse Workbench.

Testing installation

  1. Open the Flex Builder perspective by clicking Window->Open Perspective->Other and then selecting Flex Development.
    14
  2. Create a new Flex Project by going to File->New->Flex Project. Enter the following project details and hit Finish.
    16
  3. Open the Test.mxml file and go to “Design” view. Drag a button on to the canvas and save the file.
    17
  4. Launch the application by right clicking on Test.mxml->Run As->Flex Application.
    18
  5. You should see the application run in your default browser.

Upgrading Flex SDK:

  1. Get the latest version of Flex SDK (3.4.0 at the time of writing this post) from Adobe’s site
  2. Unzip the downloaded file into /sdks/3.4.0 folder.
  3. In MyEclipse go to Installed Flex SDKs and click Add. Browse for the 3.4.0 folder and enter 3.4.0 as the name and hit Ok.
    20
  4. Make sure that 3.4.0 SDK is selected and hit Ok.

References:
http://riawanderer.com/?p=4

Balaji Flex

Reading Operational Attributes using Spring LDAP

September 1st, 2009

Ldap Servers maintain operational attributes (introduced in version 3) for administrative purposes. For example, the Tivoli Directory Server maintains the pwdAccountLockedTime operational attribute to record the time a user’s account got locked.

These operational attributes are unique in the sense that they are not part of an object class and are not returned unless they are explicitly requested by name. Here are two ways of reading operational attributes using Spring Ldap:

Using lookup:

LdapTemplate ldapTemplate = new LdapTemplate(context);
ldapTemplate.lookup("USER_DN", new String[]{"OPERATIONAL_ATTR"}, new ContextMapper(){
		@Override
		public Object mapFromContext(Object ctx)
		{
			DirContextAdapter context = (DirContextAdapter)ctx;
			return context.getStringAttributes("OPERATIONAL_ATTR");
		} });

Using Search:

LdapTemplate ldapTemplate = new LdapTemplate(context);
ldapTemplate.search("SEARCH_BASE", "uid=UNIQUE_USER_NAME", 1, new String[]{"OPERATIONAL_ATTR"}, new ContextMapper(){
		@Override
		public Object mapFromContext(Object ctx)
		{
			DirContextAdapter context = (DirContextAdapter)ctx;
			return context.getStringAttributes("OPERATIONAL_ATTR");
		} });

Balaji Ldap, Spring

Getting started with SNMP4J

August 30th, 2009

The Simple Network Management Protocol (SNMP) is heavily used to manage devices on a network. SNMP4J is an open source SNMP implementation that allows Java programs to create, send and receive SNMP messages. In this post, I will show a simple example to read the raw idle cpu time from a server.

In order to use SNMP4J API, you need to have the following jars in the project classpath:

  • snmp-1.3.jar
  • SNMP4J.jar
  • log4j.jar

The first step is to create a new communication object to connect to the remote host.

InetAddress hostAddress = InetAddress.getByName("remote_host_name");
SNMPv1CommunicationInterface communication = new SNMPv1CommunicationInterface(0, hostAddress, "community_name", 151);

The next step is to query the Management Information Base for the raw idle cpu time.

SNMPVarBindList list = comm.getMIBEntry("1.3.6.1.4.1.2021.11.53.0");
Here 1.3.6.1.4.1.2021.11.53.0 is the OID for the raw idle CPU time.

The final step is to retrieve the value from the returned value. Since we know that the returned list should have only one value, we look up the first item.

SNMPSequence sequence = (SNMPSequence) list.getSNMPObjectAt(0);
String idleCPUTime =  ((SNMPInteger)sequence.getSNMPObjectAt(1)).toString();

Putting it all together:

import java.net.InetAddress;
import snmp.SNMPInteger;
import snmp.SNMPSequence;
import snmp.SNMPVarBindList;
import snmp.SNMPv1CommunicationInterface;

public class SnmpLookup
{
    public String getIdleCpuTime(String name, int port,String community)
    {
        String idleCPUTime = null;
        try
        {
            InetAddress hostAddress = InetAddress.getByName(name);
            SNMPv1CommunicationInterface comm = new SNMPv1CommunicationInterface(0, hostAddress, community, port);
            SNMPVarBindList list = comm.getMIBEntry("1.3.6.1.4.1.2021.11.53.0");
            SNMPSequence sequence = (SNMPSequence) list.getSNMPObjectAt(0);
            idleCPUTime =  ((SNMPInteger)sequence.getSNMPObjectAt(1)).toString();
        }
        catch(Exception e)
        {
           // Purposefully swalloning the exception
        }
        return idleCPUTime;
    }
}

Balaji Getting Started, SNMP4J

Spring not able to retrieve Sybase database metadata

August 29th, 2009

Recently, when trying to execute a Sybase stored procedure using SimpleJdbcCall, I found that the Spring framework could not read the database metadata. SimpleJdbcCall uses the metadata to intelligently figure out the parameters and their types and just makes stored procedure invocation painless.

After going through Spring’s source code, I found that Spring uses the database product name to determine how the metadata should be loaded. Turns out that the commonDatabaseName method in the JdbcUtils that is used to get the product name does a string comparison against “sql server” and our Sybase server is named “SQL Server”.

I submitted a patch to do this comparison with out taking considering the case. Hopefully this gets considered in the 3.0 release.

Balaji Spring

Mousefeed Eclipse Plugin

July 30th, 2009

Today, I ran into a really cool eclipse plugin called Mousefeed. Once installed, this plugin will popup a reminder with shortcut information every time a button or a menu item is clicked using mouse.

I find this a great way to quickly learn Eclipse shortcuts and becoming productive with the IDE.

Balaji Solutions Log

Unobtrusive JavaScript using JQuery

March 7th, 2009

I feel that an important advantage of using JQuery is its ability to separate behavior from structure. Consider the case where you want to trigger a JavaScript method when a link is clicked. A common implementation would be:



Click Me

Even though this mixing of behavior (JavaScript) and structure (HTML) looks straight forward, it can become a maintenance issue in large projects. This is where JQuery shines. Using JQuery, the above code can be rewritten in a cleaner way:



Click Me

Now, consider a slightly trickier case where context specific parameters need to be passed to the JavaScript method:



Click Me 1
Click Me 2
Click Me 3
Click Me 4
Click Me 5

Here is the refactored version using JQuery:



Click Me 1
Click Me 2
Click Me 3
Click Me 4
Click Me 5

Balaji JQuery, Uncategorized

JQuery - Five useful tips

March 7th, 2009
  1. Selectors
    Before an element can be manipulated using JQuery, it needs to be identified. JQuery provides a powerful syntax for selecting a one or more elements. Here are some simple selectors (notice similarity to CSS element selection):

    • Selecting by id: $(’#yourelementid’)
    • Selecting by class name: $(’.yourclassname’)
    • Selecting by tag name: $(’p') selects all the

      elements in the page

    Other useful selectors:

    • div > a will select all the links present directly inside a div tag
    • tag[attribute=value] will select all the elements of type tag with the given attribute name and value. For example input[type='text'] will select all the text tags
    • :checkbox, :radio, :file are shortcuts to select checkboxes, radio buttons and file elements.
    • :hidden selects all the elements that are hidden (such as head and base tags). This DOES NOT select all the form hidden fields.
  2. Reading and Modifying attribute values
    Once a element is selected, its value can be read and modified using attr method, Here are examples:

    • $(’base’).attr(”href”) reads the href attribute of the base tag
    • $(”#formTextId”).attr(”value”, ‘Test Value’);
  3. Document ready handler
    The document ready handler provides a convenient location to place all the document’s initialization code. JQuery executes this handler right after the browser finishes converting HTML into DOM tree. Here is the syntax for handler:

    $(document).ready(function() {
       // Your code
    });
    

    A shortcut syntax for this:

     $(function() {
          // Your code
     });
    

    It is possible to chain the several handlers and JQuery will execute them in the order in which they are declared.

  4. live() method
    JQuery’s live() method binds a handler to an event for current and future matched elements. This is extremely useful when elements are loaded dynamically (using AJAX for example) and need to have their behavior controlled by JQuery. For example the following code will display a “Print” window when a link of class printLink is clicked.

     $(".printLink").live("click", function(){
    	window.print();
    	return false;
    });
    

    A JQuery plugin called Live Query provides a similar but more robust functionality

  5. load() method
    Provides a simple and convenient way to inject html content into an element (or set of elements) using Ajax. For example the following code injects html code of a

    element with id ‘paragraphId’ inside test.html page into div with id ’someDivId’.
    $(’#someDivId’).load(’/test.html #paragraphId’);

Balaji JQuery, Uncategorized