venerdì, aprile 28, 2006

PearlJam - the Artwork

ok, ho visto questa:
Pearl Jam - Avocado Internal Artwork

e sono rimasto attonito...

poi ho visto quest'altro..
alt=

e non vedo l'ora di averlo anche io !!!!! chissà tra quanto mi arriva !

lunedì, aprile 24, 2006

dijon - Japan vs Italy e Crocodile Dunduee

il mio talk è andato bene tutto sommato..
quarto su quattro speakers, mi aspettavo comunque di potermela prendere con calma..e invece il 3° tizio, un japonese che lavora in america, si è dilangato all'inverosimile su formulone matematica assurda..e il track chair gli ha sbroccato!
ci vorrebbe una macchinetta fotografica per farvi capire che soggettone che è: vestito tutto di bianco in tuta, capelli lunghi biondi e fortemente stempiato, occhiali con bordino colorato fantasia e, la chicca, capello cowboy con medaglioni indiani sopra !

dijon - keynote

questo non sta bene oh...
ad un certo punto ha chiesto "non sò se l'audience è familiare con la teoria KD45q.." :-O
ma che eh ???

domenica, aprile 23, 2006

dijon - day 1

dopo una soave sveglia alle 6.30, un gradevole tragitto in bus dove almeno ho visto un po' di più la città, sono arrivato alla facoltà, dove mi hanno fornito di:
- borsetta di ordinanza sac-2006;
- 2 mattoni cartacei (detti proceedings) che avrò problemi a far passare per bagaglio a mano per quanto sono grossi;
- badge per i parametri ad internet (e questo me lo tengo per ricordo :-);
- penne, matite e tutto la cartoleria del mondo;
- la mostarda!!!!! incredibile, non ci volevo credere, eppure dentro la borsetta ci stanno alcuni vasetti di mostarda! :-|

ora parlerà non sò quale dei capoccioni che ha organizzato il tutto, poi ci sarà un keynote (ovvero, un tizio che se la super-scoatta), e poi in tarda mattinata tocca a me :)

viva la mostarda!


in albergo da Dijon, anche dopo aver chiesto un cambio di camera, dove ci sarebbe dovuto essere la rete 'gratuita', scopro che anche qui serve comprare il tempo di accesso alla rete wifi (hotspot Orange..), vabè pazienza.

la prima impressione sulla cittadina è che sia molto più piccola di quanto pensavo, gotico-francese, tetti colorati, case con rinforzi a vista in legno..

le slides per domani sono al 40%, se non le finisco scatta lo show da cabaret..sempre che trovo la sala giusta, visto che non risulta dalla mappina nessun campus o supposto tale!

mercoledì, aprile 19, 2006

blogger o jroller ?

ho aperto un blog tecnico su jroller, dove ci scriverò cose più tecniche più che altro..qui continuerà la narrazione delle mie vicissitudini di altro genere :)

per chi vuole dargli un'occhiata:
il mio blog tecnico

domenica, aprile 16, 2006

Dynamic Pojo generation with ASM

At last, i decided to post something about dynamic pojo generation using a bytecode manipulation tool, ASM.
My need was to be able to declare in an easy and fashionable way the fields, and associated getXXX/setXXX of a java pojo, whitout requiring the programmer to hard-code them into the source code. At this time, I ended up with a solution which still requires the presence of a base, emtpy. java class, which is enhanced at load-time with bytecode instrumentation. In future works, this base class can be generated on the fly, providing at least a name for it.

So, consider the simplest java class you can imagine, BasePojo.java:

public class Empty {

}


Given that class, we want to introduce into it a field, author, without modifying its source code. This is possible through ASM, as stated also in the faqs (unfortunatly, that code didn't worked out of the box, and this is the main reason i'm blogging this).

So, I ended up with the following code, which also includes another portion of the code which actually loads the modified bytecode into the jvm.


import java.io.IOException;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class EntityTransformer implements Opcodes {
/*a class for writing fields and methods*/
ClassWriter cw;
/*the name of the target class*/
String className;

private ClassReader cr;

/**
* The default constructor: it generates bytecode for 1.5 JVM,
* creating a default constructor in the target class.
*/
EntityTransformer(String className) throws IOException {
this.className = className;
this.cr = new ClassReader(className);
this.cw = new ClassWriter(cr, true);

this.cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER,
className.replace('.', '/'), null, "java/lang/Object", null);

MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null,
null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V");
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
....

}


Then, here comes the real interesting stuff, the code that actually introduces setter and getter methods:


void createSetter(String propertyName, String type) {
/*
* Field First
*
* Remind yourself: Object Types are in the form L; <-
* Notice the Comma
*/
FieldVisitor fv = cw.visitField(ACC_PRIVATE, propertyName, "L"
+ type.replace('.', '/') + ";", null, null);
fv.visitEnd();

String methodName = "set" + propertyName.substring(0, 1).toUpperCase()
+ propertyName.substring(1);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "(L"
+ type.replace('.', '/') + ";)V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitFieldInsn(PUTFIELD, className.replace('.', '/'), propertyName,
"L" + type.replace('.', '/') + ";");

mv.visitInsn(RETURN);
mv.visitMaxs(2, 2);
mv.visitEnd();
}

void createGetter(String propertyName, String returnType) {

String methodName = "get" + propertyName.substring(0, 1).toUpperCase()
+ propertyName.substring(1);

MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "()L"
+ returnType.replace('.', '/')+";", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, className.replace('.', '/'), propertyName,
"L"+returnType.replace('.', '/')+";");
mv.visitInsn(ARETURN);

mv.visitMaxs(0, 0);
mv.visitEnd();
}


There can be better ways to do that, especially looking at stuff like "L"+returnType.replace('.', '/')+";": it's almost unreadable, and I could have used the Type class to facilitate that.

Then, the code that loads the produced bytecode into the classloader in-memory repository of loaded classes:

private Class loadClass(byte[] b) {
// override classDefine (as it is protected) and define the class.
Class clazz = null;
try {
ClassLoader loader = ClassLoader.getSystemClassLoader();
Class cls = Class.forName("java.lang.ClassLoader");
java.lang.reflect.Method method = cls.getDeclaredMethod(
"defineClass", new Class[]{String.class, byte[].class,
int.class, int.class});

// protected method invocaton
method.setAccessible(true);
try {
Object[] args = new Object[]{className, b, new Integer(0),
new Integer(b.length)};
clazz = (Class) method.invoke(loader, args);
} finally {
method.setAccessible(false);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
return clazz;
}


At last, the easy part:

public Class transform(String[] properties) throws IOException {
for (String prop : properties) {
//property name, type parameter
createSetter(prop, "java.lang.String");
//property name, return type
createGetter(prop, "java.lang.String");
}
return loadClass(cw.toByteArray());
}


Take care not to load the class you want to transform before invoking the transform method, or you'll probably encounter a ClassLinkageError or stuff like that.
That's all for my first techy-post. I'll post some new stuff while coding on it.

giovedì, aprile 13, 2006

PJ-gCal

dato che non mi veniva sonno, riguardando il post precedente mi sono chiesto come potevo usare calendar per fare qualcosa di utile..
e sono uscito fuori con il calendario pearljam..(e che altro sennò?)

ho fatto girare un po' la voce, http://forums.pearljam.com/showthread.php?t=179588 , http://www.theskyiscrape.com/phpBB2/viewtopic.php?p=1030334 e un paio di mailing-list specializzate, ora vediamo il feedback che ricevo..
per chi se lo vuole aggiungere come feed-rss : rss
sennò per iCal: iCal

speriamo che lo spirito sia costruttivo non distruttivo, sennò va tutto a farsi benedire :)

gCal

tanto perchè non ne avevamo abbastanza, è stato rilasciato
oggi google-calendar http://www.google.com/calendar..
l'ennesima applicazione ajax per stupire gli addetti ai lavori e ingraziarsi i novizi :)
appena trovo il modo di rendere visibile il calendario pubblico dei miei eventi qui sul blog ci provo!

martedì, aprile 11, 2006

imagine a Bu$h

doppio post, nel giro di poco, per volevo condividere questa chicca:



il mondo è in mano a lui...

Grace and the beluga whale 2

Baby Beluga in the deep blue sea,
Swim so wild and you swim so free.
Heaven above, and the sea below,
And a little white whale on the go...

by Raffi and Debi Pike

domenica, aprile 09, 2006

half of..half of a century!


dscf8290.jpg
Originally uploaded by Valerio Schiavoni.
prima o poi arriva per tutti..e quando arriva è giusto celebrare come si deve!

giulia ci ha portato ai bozzi..e qui potete gustarvi lo spettacolo!

sabato, aprile 08, 2006

avocado...leaked

come si sospettava, alcuni giorni prima sono comunque trapelate tutte le restanti traccie...

http://s57.yousendit.com/d.aspx?id=0E1DSDZ0U1DQH3VDP3GURRUY7G

la qualità di qualcuna è pessima..

comunque sia, il nuovo PearlJam è finalmente tra noi!

domenica, aprile 02, 2006

south-parkers


geniale questo sito http://spstudio.elena.hosting-friends.de/spstudio.html
che ne dite, ci assomigliamo ? :)