BeeSoft®
Since 1992
 

Content

 Welcome
 Products
       Abeona
       Gaia
             News
             Documentation
                   Introduction
                   Swing support
                   Server application
                   Validation
                   XML
                   Logging
                   Utilities
                   Launcher
             License
             Download
       Hephaistos
       JavaGantt
 Services
       Promote your software
 Contact Us
 Links
      
  GaiaI®
© 2012 BeeSoft ®
 

Utilities

There is a set utility classes in Gaia library. They are implemented in eu.beesoft.gaia.util package:


AbstractBean

This class was developed to replace java.beans.PropertyChangeSupport class functionality. If you use it as parent class for your beans

  • you don't need to write addPropertyChangeListener and removePropertyChangeListener methods or accessors to the PropertyChangeSupport
  • your memory requirements are noticeably lower, especially if you have a lot of beans in memory

Language and LanguageListener

Encapsulates the work with resource bundles and language dependent texts. LanguageListener is the listener interface to receive language changed events.


Miner

Miner is a class dedicated to support the data binding. From external perspective it has two simple methods:

  • getValue(propertyName, object) - gets value from the property of the object
  • setValue(value, propertyName, object)} - sets value to the property of the object

Property name can be a simple property name, or you can use the dot-convention to chain objects referenced from properties. For example, if object A has property a that references object B, and object B has property b that references object C, and object C has property c you want to get, you can use as property name text a.b.c to get / set this property.

Miner prioritizes a method access (via getters / setters), but if the method for the property cannot be found, it uses the field access.

You can use this class "as is". But you have to subclass it if

  • some property you request is virtual (it is not a name of property, it is derived)
  • somewhere in the objects chain can be null object and you need to set value at the end of the chain - you need override the method createObject(String, Object)}

ObjectBuilder and ObjectBuilderFactory

This factory is designed to reading a XML stream of descriptors and to create an appropriate ObjectBuilder instance for each parsed element. Then it manages initializing of builders and creating and initializing objects in builders. There is one or collection of objects created and initialized at the end of this process.

This implementation is abstract enough to let you free to design the form of XML (tags for elements, attributes, ...) and to program your own ObjectBuilder implementations. There is one implementation for building Swing components from XML file in package eu.beesoft.gaia.swing.builder.

Regardless of the high abstract level of the basic implementation, there are a few XML element attributes supported by ObjectBuilderFactory and ObjectBuilder:

  • id - unique identifier of the builder (or its object) in XML, it is used to reference the builder
  • class - class of created object (instances of the same builder class can create different objects, but they should be derived one from other)
  • as - a value of this attribute should be an identifier of the other builder (element); the created builder loads properties from referenced builder and then loads its own properties from XML

ObjectBuilder class is an abstract superclass of all builders. A builder serves as a factory for the creation and initialization of the created object. The building process is managed by ObjectBuilderFactory. This implementation does not dictate relationships between builder, created object and XML element - it is your responsibility.

Each builder is managed by ObjectBuilderFactory instance that created it. ObjectBuilderFactory loads a XML description and for each element creates a new appropriate builder. This is done in these steps:

  1. this builder's instance is created
  2. references to instance of ObjectBuilderFactory and builder's parent are stored to this builder
  3. attributes from XML element are stored to this builder as properties
  4. builder invokes method createObject() or createObject(String), if the class property was found

When ObjectBuilderFactory processed all XML elements and for each executed steps described above, it walks each builder again and invokes method initObjectProperties() on it. Builder for each property invokes method initObjectProperty(String, String). This method in current implementation searches for initialization method for given property and invokes it.

When all builders were requested to initiaze their properties, the ObjectBuilderFactory notifies each builder about its hierarchy position. On each builder with children is invoked method addChild(ObjectBuilder). This is done from bottom to top in the builder hierarchy, so parent is notified about its children when each its child was notified about its children.

After that is builder and its object fully initialized and object can be used in application.


Reflection

Utility class for Java reflection. Implements a set of the methods to get field or method from the class (and its superclasses), get or set value to a field, invoke methods, etc.


Streams

Utility class for the stream I/O operations. Returns an input stream or reader for given name, it is looking for it in classpath or in filesystem, closes streams.

Exceptions are wrapped by RuntimException, so there is no need for try-catch blocks in your code.

This is an example to copy file with this class:

	InputStream is = Streams.getInputStream ("..."); // resource name
	OutputStream os = Streams.getOutputStream ("..."); // target file name
	Streams.copy (is, os);
	Streams.close(os);
	Streams.close(is);

ValueObject

General value object that holds its values as properties in the internal map. This object has no getters / setters for individual properties, there is one getProperty(String)} method and one setProperty(String, Object)} method. The setProperty() method generates property change event (in parent class AbstractBean).


SystemProcess

It encapsulates functionality of the java.lang.Process, java.lang.ProcessBuilder and some methods from java.lang.Runtime classes. It supports to:

  • create a new system process
  • complete command and or arguments in more steps
  • change system environment variables
  • change working directory
  • merge input and error stream to the one
  • execute process and wait while it is not finished
  • obtain process exit value
  • obtain input, error and output stream for the process

There is also a set of the static exec() methods to simplify starting of the system process.

This implementation solves the problem of the Process.waitFor() method, which hangs when are not read the process streams.