Archive

Archive for the ‘Uncategorized’ Category

Yoxos eclipse distrib

February 14, 2009 Leave a comment

Just a quick entry to tell how exited I’am with the Yoxos “Eclipse on demand”
Creating your initial Eclipse distrib install has never been so easy with this tool :

First step : in their web application you just select all the plugins you need then click on “Start Download” and that’s it ! you are downloading your own eclipse distrib in a minute !
When I think how painfull it is without this great tools to get each plugin separatly, having to check that you have the needed dependencies …

yoxos_screenshot_02

But wait there’s more ! Once you are using the yoxos distrib their is a yoxos plugin embeded in eclipse which add a new perspective. From this perspective you can choose to add new plugins and yoxos will check for you all the needed dependencies and download them !

Yoxos eclipse perspective

Adding new plugins has never been so easy!

🙂

Yoxos finding dependenciesYoxos dependencies found

Yoxos features that will be installedYoxos installing features

Advertisements
Categories: Uncategorized Tags:

Two way binding with Flex

January 28, 2009 1 comment

Having a good api for binding ui components to the data model has became a must have feature. Since I’m playing with Flex lately I’ve quickly test how to use its binding feature.

Let say you have a VO object like this one :


package org.test.vo {

    [Bindable]
    public class PersonVO  {

        public var age:int;
        public var firstName:String;
        public var lastName:String;
    }
}

Notice the [Bindable] annotation added before the class definition, this is telling the compiler that all the public attribut inside the class should be able to dispatch an event when their value are changed so that they can be used as the source of data binding.

Solution 1 :

The following Flex code can be used to display the PersonVO data :


    <mx:Form>
        <mx:FormItem label="First Name">
            <mx:TextInput id="firstNameId"/>
        </mx:FormItem>       
        <mx:FormItem label="Last Name">
            <mx:TextInput id="lastNameId"/>
        </mx:FormItem>
        <mx:FormItem label="Age">
            <mx:TextInput id="ageId"/>
        </mx:FormItem>
    </mx:Form>

If you want a “two way” binding between the UI and the model you need to write the following


    <mx:Binding source="personVO.firstName" destination="firstNameId.text" />
    <mx:Binding source="firstNameId.text" destination="personVO.firstName" />

    <mx:Binding source="personVO.lastName" destination="lastNameId.text" />
    <mx:Binding source="lastNameId.text" destination="personVO.lastName" />

    <mx:Binding source="personVO.age.toString()" destination="ageId.text" />
    <mx:Binding source="int(ageId.text)" destination="personVO.age" />

Note : since age is an int type we need to write some extra code to tell flex how to cast from String to int and vice versa.

Solution 2 :

The binding can also be described the following way :


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:local="*">

    <mx:Script>
        <!&#91;CDATA&#91;
            import mx.controls.Alert;
            private function showPersonValue():void {
                Alert.show(    "firstName = " + aPerson.firstName + "\n" +
                             "lastName = " + aPerson.lastName + "\n"+
                             "age = " + aPerson.age , "Info");
            }
        &#93;&#93;>
    </mx:Script>

    <local:PersonVO id="aPerson">
        <local:firstName>{firstNameId.text}</local:firstName>
        <local:lastName>{lastNameId.text}</local:lastName>
        <local:age>{int(ageId.text)}</local:age>
    </local:PersonVO>

    <mx:Form>
        <mx:FormItem label="First Name">
            <mx:TextInput id="firstNameId" text="{aPerson.firstName}"/>
        </mx:FormItem>
        <mx:FormItem label="Last Name">
            <mx:TextInput id="lastNameId" text="{aPerson.lastName}"/>
        </mx:FormItem>
        <mx:FormItem label="Age">
            <mx:TextInput id="ageId" text="{aPerson.age}"/>
        </mx:FormItem>
    </mx:Form>

    <mx:Button label="Show Person Value" click="showPersonValue()"/>

</mx:Application>

twowaysmappingsolution2

Another solution for creating a two way binding using a “in-house utility api” found here

This solution gives the following to describe the two way binding :

...
<mx:Script>
	<!&#91;CDATA&#91;
		public var userModel : UserModel;
	&#93;&#93;>
</mx:Script>
<mx:Form>
	<mx:FormItem label="First Name">
		<mx:TextInput id="txtFirstName"/>
	</mx:FormItem>
</mx:Form>
<ModelBinding model="{userModel}" field="firstName" target="{txtFirstName}"/>
...

In my opinion the main drawback for this solution is that we are losing the error warning during compilation time : if you change field name from “firstname” to “fname” for example you won’t be informed of this error.
Finally
I would like to point out this feature request posted at adobe asking for indicating two way binding in mx:binding tag and the following solution :  Two-way Data Binding – Functional and Design Specification.

Categories: Uncategorized Tags:

Ponzi scheme

December 17, 2008 Leave a comment

Following the Bernard Madoff case I’ve been told that what he has done is called a Ponzi scheme.

A Ponzi scheme is a fraudulent investment operation that involves paying abnormally high returns to investors out of the money paid in by subsequent investors, rather than from the profit from any real business.

Categories: Uncategorized

Simple call to a Web Service with Excel

December 17, 2008 Leave a comment
I've made a basic test calling a web service using excel vba.
The xml data sent by the service is the following :
<Toto>
  <Titi val='2'/>
</Toto>

Looking on the net for some examples I've found this first one :

Public Sub wsCall_test1()

Dim objIE As Object
Dim Anymore As Boolean
Dim Found As Boolean

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False
objIE.Navigate "http://localhost:8182/"
Do While objIE.Busy: DoEvents: Loop
Do While objIE.readystate <> 4: DoEvents: Loop

MsgBox objIE.document.documentElement.innerText

Dim docXML As String
docXML = objIE.document.documentElement.innerText

Dim doc As DOMDocument
Set doc = New DOMDocument
MsgBox doc.loadXML(docXML)

MsgBox doc.selectSingleNode("Toto/Titi").Attributes(0).Text

End Sub

Finally it has turn out that it can be simplified to this :

</pre>
Public Sub wscall_test2()

Dim doc As DOMDocument
Set doc = New DOMDocument

MsgBox doc.Load("http://localhost:8182/")

MsgBox doc.XML

MsgBox doc.selectSingleNode("Toto/Titi").Attributes(0).Text

End Sub

In both test the msgbox used to output information are the following :

excelvba1

excelvba2excelvba3

Categories: Uncategorized Tags: , ,

Synchronizing threads

December 10, 2008 Leave a comment

To synchronize thread, use the monitoring methods.

Warning : the monitoring methods are available on all the java classes in any conditions albeit calling these method outside synchronied code will throw an exception. The following example describes it :

public static void main(String[] args) throws InterruptedException {
  Object lock = new Object();

  synchronized (lock) {
    System.out.println("calling a monitor method inside a synchronized block");
    lock.wait(1000);
  }

  System.out.println("calling a monitor method outside a synchronized block");
  lock.wait(1000);
}

This will lead to the following output :

calling a monitor method inside a synchronized block
calling a monitor method outside a synchronized block
Exception in thread “main” java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.wait(Native Method)
at TestThreadMonitor.main(TestThreadMonitor.java:15)

Categories: Uncategorized Tags: ,

Thread basics

December 10, 2008 Leave a comment

First of all the thread life cycle :

Thread Life Cycle

Thread Life Cycle

(Source reference: http://www.witscale.com/scjp_studynotes/chapter8.html)

There is two wayq to create a thread an run it :

Directly by extending the Thread class:

public class MyThread extends Thread {
  @Override
  public void run() {
  // do some stuff here
  }
}

To call it somewhere in you java code :

new MyThread().start();

Or by implementing the Runnable interface:

public class MyRunnable implements Runnable {
  Public void run() {
  // do some stuff here
  }
}

To call it somewhere in you java code :

new Thread(new MyRunnable()).start();

The best practice is to use the Runnable interface, this allows you to extends a business class or other if needed and its offers a better separation (than being stuck with the Thread class).

Categories: Uncategorized Tags: ,

Retreiving annotation data using introspection and dynamic proxy

December 10, 2008 Leave a comment

Just trying a simple test to retreive the annotation data during runtime using introspection.

Here’s the classes created for the test:

annotationsandproxy

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
    String value();
}

public class MyProxy implements InvocationHandler {

    private Object impl;

    private MyProxy(Object impl) {
        this.impl = impl;
    }

    public static Object newInstance(Object impl, Class[] interfaces) {
        return Proxy.newProxyInstance(impl.getClass().getClassLoader(), interfaces, new MyProxy(impl));
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // get the implementation object method on which the annotation has been setted
        Method implObjectMethod = impl.getClass().getMethod(method.getName(), method.getParameterTypes());

        // print the annotation in output
        Annotation[] annotations = implObjectMethod.getAnnotations();
        for (int i=0;i