In relazione al pattern, java fornisce delle API già pronte all’uso:
Mitico
http://mirrors.ibiblio.org/pub/mirrors/maven2/
https://repository.sonatype.org/index.html#welcome
http://mvnrepository.com/
http://repository.jboss.org/maven2/
http://search.maven.org/
import java.lang.reflect.Method; import java.lang.reflect.Proxy; public class TraceProxy implements java.lang.reflect.InvocationHandler { private Object object; public static Object createProxyFor(Object object) { final TraceProxy traceProxy = new TraceProxy(object); System.out.println("\ntraceProxy = " + traceProxy); return Proxy.newProxyInstance( object.getClass().getClassLoader(), object.getClass().getInterfaces(), traceProxy ); } private TraceProxy(Object object) { this.object = object; } @Override public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { System.err.println("traceProxy = " + this); System.err.println("m = " + m); System.err.println("args = " + args); if (args != null) { for (Object object : args) { System.err.println(object); } } return m.invoke(object, args); } public static void main(String[] args) { CharSequence cs = (CharSequence) TraceProxy.createProxyFor("abcdefghilmnopqrstuvz"); System.out.println("\ncall charAt"); System.out.println("charAt result is '" + cs.charAt(2) + "'\n"); //sleep ... altrimenti l'output non è chiaro try { Thread.sleep(10); } catch (InterruptedException e) { } System.out.println("call length"); System.out.println("length result is '" + cs.length() + "'"); } }
Ecco un mitico software che aiuta in fase di creazione del nostro applicativo … Glade
getClass().getResourceAsStream(File)
getClass().getClassLoader().getResourceAsStream(File)
Thread.currentThread().getContextClassLoader().getResourceAsStream(File)
quante alternative !!?
> http://stackoverflow.com/questions/309495/windows-shortcut-lnk-parser-in-java
> http://kac-repo.xt.pl/cgi-bin/gitweb.cgi?p=jshortcut.git;a=blob;f=src/org/kac/Shortcut.java;hb=HEAD
ho trovato queata fantastica definizione …
The JDK is a subset of what is loosely defined as a software development kit (SDK) in the general sense. In the descriptions which accompany their recent releases for Java SE, EE, and ME, Sun acknowledge that under their terminology, the JDK forms the subset of the SDK which is responsible for the writing and running of Java programs. The remainder of the SDK is composed of extra software, such as Application Servers, Debuggers, and Documentation.
Applica costantemente i seguenti concetti per mantenere il codice pulito …
sicuramente può essere rifinita ed aggiornata … ma questa breve lista dovrebbe essere un buon punto di partenza.
Non voglio riscrivere quello che già è spiegato molto bene sul web:
dbus
dbus-tutorial
wikipedia
Ho fatto un piccolo esempio in Python. Avendo usato rmi in Java mi sono trovato molto a mio agio.
Service
#!/usr/bin/env python import dbus import dbus.service import dbus.glib import gobject class SomeObject(dbus.service.Object): def __init__(self, bus_name, object_path="/SomeObject"): dbus.service.Object.__init__(self, bus_name, object_path) @dbus.service.method("org.designfu.SampleInterface") def HelloWorld(self, hello_message): print (str(hello_message)) return ["Hello", " from example-service.py"] @dbus.service.method("org.designfu.SampleInterface") def GetTuple(self): return ("Hello Tuple", " from example-service.py") @dbus.service.method("org.designfu.SampleInterface") def GetDict(self): return {"first": "Hello Dict", "second": " from example-service.py"} session_bus = dbus.SessionBus() name = dbus.service.BusName("org.designfu.SampleService", bus=session_bus) SomeObject(name) mainloop = gobject.MainLoop() mainloop.run()
Client
#!/usr/bin/env python import dbus bus = dbus.SessionBus() remote_object = bus.get_object("org.designfu.SampleService", "/SomeObject") hello_reply_list = remote_object.HelloWorld( "Hello from example-client.py!", dbus_interface = "org.designfu.SampleInterface") print "1)", hello_reply_list, "\n" iface = dbus.Interface(remote_object, "org.designfu.SampleInterface") print "2)", str(iface.GetTuple()), "\n" print "3)", str(iface.GetDict()), "\n" print remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")
Da poco meno di un mese mi sono concentrato su questo simpatico linguaggio il cui nome deriva da una commedia Monty Python andata in onda nel corso degli anni 70.
Tutto quello che serve … sito ufficiale della comunità italiana
Le caratteristiche che mi hanno fatto puntare questo prodotto open source
NOTA PER I JAVISTI
jython
semplice e molto ben spiegato … ecco qui
è proprio vero … nella semplicità si trova la bellezza
Ho particolarmnte gustato questa presentazione … queste tipologie di servizi mi intrigano non poco
ed un bel articolo firmato ibm.
Funziona con WordPress