Features
- serialization to / from formats XML, CSV and Resource bundle
- UJO object can be simplify manipulated by an application builder tool
- UJO object itself recommends the availability of its attributes for different actions
- there is possible to implement a listener to only one place for each properties include children
- direct support of JavaBeans and the JTable component
- small source code of your UJO objects
- most features are checked by unit tests
- tiny framework without further dependencies
Architecture
- UjoProperty.setValue(Ujo, VALUE) - to write the value into the object and
- UjoProperty.getValue(Ujo) - to read the value.
- MapUjo - easy for developers to implement with a sufficient performance for common applications based on the object HashMap
- ArrayUjo - high performance objects are comparable to the speed of the JavaBeans, implemented by the object array
- PojoUjo - the implementation maps properties directly to the methods of JavaBean object using Java reflection
Sample of usage:
import org.ujoframework.implementation.map.*; public class Person extends MapUjoExt<Person> { public static final MapProperty<Person, String > NAME = newProperty("Name", String.class); public static final MapProperty<Person, Boolean> MALE = newProperty("Male", Boolean.class); public static final MapProperty<Person, Double > CASH = newProperty("Cash", 0d); public void addCash(double cash) { double newCash = get(CASH) + cash; set(CASH, newCash); } }
Note that a result of the method get(CASH) needs no casting to Double type and the Java compiler disallows improper parameter types in the statement set(CASH, newCash). The CASH property have got a default zero value to all Person instances similar like a primitive type do it.
The sample uses an extended API for more conventional property access in a source code that's available since the UJO release 0.80. The new solution allows to you to chain more properties according to a model of a some new popular languages. The extended API is a child of the original API so you can mix both types because all internal tools are handling the original API still .
Sometimes it is not possible to extend an abstract class so you can implements the Ujo interface by four methods only. Note the implementation is valid for all subclasses of the Person class too. The sample:
import java.util.HashMap; import org.ujoframework.*; import org.ujoframework.core.UjoManager; import org.ujoframework.implementation.map.*; @SuppressWarnings("unchecked") public class Person implements Ujo { public static final MapProperty<Person, String > NAME = new MapProperty("Name", String.class); public static final MapProperty<Person, Boolean> MALE = new MapProperty("Male", Boolean.class); public static final MapProperty<Person, Double > CASH = new MapProperty("Cash", 0d); // --- The start of the map Ujo implementation --- private HashMap map = new HashMap(); public Object readValue(UjoProperty property) { Object result = map.get(property); return result!=null ? result : property.getDefault(); } public void writeValue(UjoProperty property, Object value) { map.put(property, value); } public UjoProperty[] readProperties() { return UjoManager.getInstance().readProperties(getClass()); } public boolean readAuthorization(int action, UjoProperty property, Object value, Object context) { return true; } // --- The end of UJO implementation --- /** A solution for the Ujo implementation */ public void addCash(double cash) { double newPrice = CASH.of(this) + cash; CASH.setValue(this, newPrice); } }
Compare the both samples with a sample code of a JavaBean object. If we exclude all imports from the code then the Ujo implementation have got slightly less code lines in compare to JavaBeans. However the more properties gives significantly the better effect in favour of the Ujo implementation.
Reference project
There are some characteristics of jWorkSheet:
- persistence is made by UJO Framework include application parameters.
- all table model are a child of UjoTable class.
- very small size: 180 kB include the UJO Framework library.
- the jWorkSheet have used features of UJO release 0.7x (hard core).
Licence:
Copyright 2007-2008 Paul Ponec
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contact:
- You can write some suggestions or questions on blog http://ujoframework.blogspot.com/
- Support: ujoframework@gmail.com
- See homepage http://ponec.net/ for more applications of the author.
