| Aktuell - Seminare - Homepage - Reports - Software - (back) |
| postindustr.CC - XML/Ti Report - pTA StudienArbeit - . - sch_llf study - Geschichte des PC - TechDocs - Perl Objects - Installing Oracle - shell cmds in python - Using css for xml - Unsafe mono - Docbook Manpages - [ Java Bean ] - schema-mapping - java problems - boot - grub-netboot - grub-gtk - partclone freshmeat - partimage links - releaseuploader |
| Code - rpm-suse |
http://java.sun.com/products/javabeans/ a.k.a. "JavaBeans Activation FrameWork (JAF)". That documentation is all misleading for concentrating on the server side i.e. how to write a GUI engine that can use the JAF to inspect virtual objects with their virtual properties. Many other tuturials concentrate on GUI beans with the virtual properties relating to "size", "height", "color" and the framework allowing to hibernate the graphical object.
public Foo getFoo(); public void setFoo(Foo value);
It is possible to only use Read or Write but that would not allow to use any of the persistance support.
public boolean isFoo(); public void setFoo(boolean value);
A boolean property is-a value property with the additional sugar of allowing "is" as a synonym to "get". Repeat, you may declare both "is" and "get" but you shall not make them behave different.
public Foo[] getFoo(); public void setFoo(Foo[] value);
It is allowed to (ab)use a Value Property for an Array by just defining get/set of a native array. In most cases you want an indexed property.
public Foo getFoo(int item); public void setFoo(int item, Foo[] value);
In reality you must implement 4 methods (!!!) to get an indexed property as the two array value property methods must be defined as well. Remember to use "throws ArrayIndexOutOfBoundsException".
public void addSomeListener(SomeListener); public void removeSomeListener(SomeListener);Allows any Listener List to be constructed. This is usually a MultiCast event system. One can constrain the number by using "throws java.util.TooManyListenersException" which is easy for UniCast event. Note: add/removeXxxxxListener(XxxxListener) is a strict naming convention.
private PropertyChangeSupport changes = new PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChangeListener p) {
changes.addPropertyChangeListener(p); }
public void removePropertyChangeListener(PropertyChangeListener p) {
changes.removePropertyChangeListener(p); }
To be fired when any property does change. Any "bound property" must call "firePropertyChange" when it finds itself being modified. The listeners will each see a "propertyChange(PropertyChangeEvent)" call.
public void setFoo(int foo) {
int old = this.foo;
this.foo = foo;
repaint();
changes.firePropertyChange("foo", new Integer(old), new Integer(foo));
}
Allows an attempt for a property change to be vetoed. Such a "set" method will support the "PropertyVetoException". There is again helper support for this scheme:
private VetoableChangeSupport vetoes = new VetoableChangeSupport(this);
public void addVetoableChangeListener(VetoableChangeListener v) {
vetoes.addVetoableChangeListener(v); }
public void removeVetoableChangeListener(VetoableChangeListener v) {
vetoes.removeVetoableChangeListener(v); }
public void setFoo(int foo) throws PropertyVetoException {
vetoes.fireVetoableChange("foo", new Integer(this.foo), new Integer(foo));
int old = this.foo;
this.foo = foo;
repaint();
changes.firePropertyChange("foo", new Integer(old), new Integer(foo));
}
The term "Bound Properties" is another name for simple properties that are connected to change events. Just like in the glue code above one has a VetoableChange event before the virtual property is being changed and a PropertyChange event after the virtual property is being set. Using the PropertySupport member one can inherit the signal event framework - using add/remove one can bind objects as being emitters and listeners. Note: PropertyChange uses a "name" for the change-event subtyping which must be switchcased in the (anonymous) listener.
class Client implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent event) {
String thePropName = event.getPropertyName();
Object oldPropValue = event.getOldValue();
Object newPropValue = event.getNewValue();
}
}
package.tmp : GNUmakefile */*.java echo "Manifest-Version: 1.0" > $@ echo "Created-By: $(PACKAGE) make" >> $@ echo "Main-Class: $(MAINCLASS)" >> $@ echo "Implementation-Title: $(TITLE) " >> $@ echo "Implementation-Version: $(PACKAGE) $(VERSION)" >> $@ echo "Implementation-Vendor: $(AUTHOR)" >> $@ echo "Implementation-Time: `date`" >> $@ @ for f in */*.java ; do if grep "@javabean" "$$f" >/dev/null ; then :\ ; F=`echo "$(subdir)/$$f" | sed -e "s/\\.java/.class/"` ; echo "" >> $@ \ ; echo "echo 'Name: $$F' >> $@ ; echo 'Java-Bean: true' >> $@" \ ; echo "Name: $$F" >> $@ ; echo "Java-Bean: true" >> $@ \ ; fi doneWhen the files "MyFooObject.java" and "myFooBar.java" do contain a comment hint like "@javabean" then execution results in something like:
Manifest-Version: 1.0 Created-By: MyProject make Main-Class: de.draheim.myproject.MainCommand Implementation-Title: MyProject ShowCase Implementation-Version: MyProject 0.5 Implementation-Vendor: Guido Draheim Implementation-Time: Sam Nov 6 18:00:38 CET 2004 Name: de/draheim/myproject/MyFooObject.class Java-Bean: true Name: de/draheim/myproject/MyFooBar.class Java-Bean: true
The "@javabean" tag is best used to rename the documentation when there are both an "interface MyFoo" and "class MyFooObject" around. In that case just mark the "MyFooObject" to be responsible to read and write persistance files containing "MyFoo" nodes. The declaration of that "rename" or "aliasing" looks like this:
package de.draheim.myproject;
/* MyProject Foo.
*
* @javabean.class name="MyFoo"
* @author (C) 2005 Guido Draheim, All rights reserved.
*/
public class MyFooObject implements MyFoo {
}
The "@javabean.*" hints can be seen by an doclet extension of the javadoc step. Here is a list of class-level tags:
Here is a list of method.level tags:
Starting with Java5 it is possible to set additional attributes as annotations instead of special comment. That looks like this:
import java.lang.annotation.*;
@Copyright("2005 Guido Draheim");
public class MyClass {
Standard annotations: @Depracated, @Overrides, @Inherited (i.e. attributes are inherited from base), @Retention (hint not for runtime objects), @Target (another target for the hint). You can easily define your own annotations by declaring it like "public @interface MyHint" in a MyHint.class.
There are framework tools to represent a bean object to other services. A widely used method is to dump the object tree as an xml file. The other is used to present it as html.
The "java.beans.XMLEncoder" is a helper that can store an entire tree of AOP objects to a file - and read it back later. Each object class must have a default constructor of course. The writer-code looks like this boilerplate:
import java.beans.XMLEncoder;
import java.beans.ExceptionListener;
public class MyTreeRoot {
public static void printXml() throws IOException {
XMLEncoder output = new XMLEncoder(System.out);
output.setExceptionListener(new ExceptionListener() {
public void exceptionThrown(Exception e) {
System.err.println("RECOVERING"); e.printStackStrace(); }});
output.writeObject(self); output.flush(); } }
http://java.sun.com/products/javabeans/software/bdk_download.html offsers a simple GUI designer mainly for graphically oriented beans. There is a draw canvas where beans can be placed and interconnected with event signal paths.
Extra note: originally the whole javabeans stuff was meant to plugged into an IDE - which is the reason for all this "icons" and "shortDescr" attributes. The XMLEncoder/XMLDecoder is actually a new thing that can be used easily and successfully in a non-gui environment.
http://jakarta.apache.org/commons/beanutils/ has only a dependency on the jakarta commons collection types but gives us a number of data beans and helpers. For example the BeanUtils class has a "copyProperties" call that "Copy property values from the origin bean to the destination bean for all cases where the property names are the same." Nice.
ecolosim.beans
www.codeproject.com/cpp/JavaBeanInMFCDialog.asp
An editor for a bean object must implement the PropertyEditor. There is an "PropertyEditorSupport" class that can be subclassed or used as an inner class (due to lack of multiple inheritance).