com.oktiva.mogno
Class Component

java.lang.Object
  extended bycom.oktiva.mogno.Component
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
Visual

public class Component
extends java.lang.Object
implements java.lang.Cloneable

This is the base class for all components. It implements the knowledge for owning another components and to save and load its data.

Version:
$Id: Component.java,v 1.1.1.1 2005/01/05 16:52:46 ruoso Exp $

Field Summary
protected  java.util.Hashtable bag
          A bag with extra data for the component.
protected  ComponentFiler componentFiler
           
protected  java.util.Hashtable componentFilerParams
           
protected  boolean designing
          Controls the behavior of the component.
protected  java.util.Vector eventQueue
          Queue of events
 java.lang.String evOnCreate
          Method to be called when the onCreate event is dispatched.
 java.lang.String name
          The name of the component, used to identify an owned component inside its owner.
protected  java.util.Hashtable owned
          A hash table with all the owned components.
protected  java.util.Hashtable ownedClasses
          A hash table with all the owned component's classes .
protected  Component owner
          The owner of this component.
protected  java.lang.String tag
           
protected  java.lang.String xmlFileName
          This variable is used when loading the component.
 
Constructor Summary
Component()
           
 
Method Summary
 java.util.Hashtable attribsHash()
          Return all this component's attributes in a hash.
protected  void createOwnedComponents(java.util.Hashtable owned)
           
 boolean descendentOf(java.lang.String name)
          Verify if this component has an ancestor named name
In Component, this is always false, because there is no parent.
 void dispatch(java.lang.String eventName)
          Dispatch an event from this object.
 void dispatchAll()
          dispatch all the events in the event queue
 void dispatchFunction(java.lang.String function, java.lang.Class[] paramTypes, java.lang.Object[] values)
           
 java.lang.Class[] eventParamTypes(java.lang.String ev)
           
 java.lang.Object[] eventParamValues(java.lang.String ev)
           
 void freeChild(java.lang.String name)
          Removes the component
 Application getApplication()
          Get the Application object from the TopLevel.
 java.util.Hashtable getAttrsTypes()
          Get the Class of the returns of the getters.
 java.util.Hashtable getBag()
          Getter for property bag.
 Component getChild(java.lang.String name)
          Get the component with name "name"
 java.lang.Class getChildClass(java.lang.String name)
          Get the class of the component with name "name"
 Component getClone()
           
 java.lang.String getEvOnCreate()
           
 java.lang.Object getFromBag(java.lang.Object key)
          Put the object in this component's bag.
 java.lang.String getName()
           
protected  java.util.Vector getOrderedChildNames()
           
protected  Component getOwner()
          Getter for property owner.
 void initialize()
          Initialize this component with a custom filer.
 void initialize(java.util.Hashtable params)
          Initialize this component passing the properties.
 void initialize(java.io.InputStream in)
          Initialize this component with a InputStream.
 void initialize(java.lang.String xmlFileName)
          Initialize this component passing the XML file to load.
 boolean isDesigning()
          Getter for property designing.
 java.util.Enumeration listChilds()
           
 java.util.Vector nonAttributeGetters()
          Method used to define what methods started with "get" or "is" are not component attributes getter methods.
 void putInBag(java.lang.Object key, java.lang.Object value)
          Put the object in this component's bag.
 void queue(java.lang.String ev)
          queue an event
 void registerChild(Component obj)
          Register a component as owned of this component
 java.lang.Object removeFromBag(java.lang.Object key)
          Remove the object from this component's bag.
 java.lang.String serializedBag()
           
 void setBag(java.util.Hashtable bag)
          Setter for property bag.
 void setComponentFiler(ComponentFiler filer)
          Set a custom ComponentFiler to use instead of the DefaultComponentFiler.
 void setComponentFilerParams(java.util.Hashtable params)
          Set the params for the custom ComponentFiler.
 void setDesigning(boolean designing)
          Setter for property designing.
 void setEvOnCreate(java.lang.String evOnCreate)
           
 void setName(java.lang.String name)
           
protected  void setOwner(Component owner)
          Setter for property owner.
 void setProperties(java.util.Hashtable mine)
           
 void store()
          Store the current component into the file defined by the xmlFileName property
protected  void unserializeBag(java.lang.String data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlFileName

protected java.lang.String xmlFileName
This variable is used when loading the component. Specifies the location of the XML file with the data for this component.


name

public java.lang.String name
The name of the component, used to identify an owned component inside its owner.


evOnCreate

public java.lang.String evOnCreate
Method to be called when the onCreate event is dispatched.


owner

protected Component owner
The owner of this component. The component that owns other components is always the listener for its owned component's events.


designing

protected boolean designing
Controls the behavior of the component. If desiging, no event will be dispatched.


owned

protected java.util.Hashtable owned
A hash table with all the owned components. The owned components are that registered inside this one, that has this one as his listener for the events. It has no relation with the parent attribute.


ownedClasses

protected java.util.Hashtable ownedClasses
A hash table with all the owned component's classes .


tag

protected java.lang.String tag

eventQueue

protected java.util.Vector eventQueue
Queue of events


componentFiler

protected ComponentFiler componentFiler

componentFilerParams

protected java.util.Hashtable componentFilerParams

bag

protected java.util.Hashtable bag
A bag with extra data for the component.

See Also:
setBag(Hashtable), getBag(), getFromBag(Object), putInBag(Object,Object)
Constructor Detail

Component

public Component()
Method Detail

getName

public java.lang.String getName()

setName

public void setName(java.lang.String name)

getEvOnCreate

public java.lang.String getEvOnCreate()

setEvOnCreate

public void setEvOnCreate(java.lang.String evOnCreate)

initialize

public void initialize(java.util.Hashtable params)
                throws InitializeException
Initialize this component passing the properties. Used when creating components at run-time.

Parameters:
params - A key-value hashtable with the properties.
Throws:
InitializeException
See Also:
initialize()

initialize

public void initialize(java.lang.String xmlFileName)
                throws InitializeException
Initialize this component passing the XML file to load.

Parameters:
xmlFileName - The path to the XML file to load.
Throws:
InitializeException
See Also:
initialize()

initialize

public void initialize(java.io.InputStream in)
                throws InitializeException
Initialize this component with a InputStream. If using DefaultComponentFiler, the component is read-only, can't perform a store(). Useful for components with this own XML to read from a resource other then a file.

Throws:
InitializeException
See Also:
initialize()

initialize

public void initialize()
                throws InitializeException
Initialize this component with a custom filer. You need to use setComponentFiler and setComponentFilerParams, if you want to use something different from DefaultComponentFiler.

Throws:
InitializeException
See Also:
initialize(String), initialize(Hashtable), initialize(InputStream), DefaultComponentFiler

setProperties

public void setProperties(java.util.Hashtable mine)

getAttrsTypes

public java.util.Hashtable getAttrsTypes()
Get the Class of the returns of the getters. This is usefull in finding the setters.

Returns:
Hashtable with its key being the name of the atribute with the first letter upercase, and the value being the class of the return type.

nonAttributeGetters

public java.util.Vector nonAttributeGetters()
Method used to define what methods started with "get" or "is" are not component attributes getter methods.
This method in all subclasses of Component must start with the following line:
Vector v = super.nonAttributeGetters();
and end with the following:
return v;

Returns:
Vector with the name of the methods that starts with "get" or "is", but shoud not be used to set or get attributes automatically for this component.
See Also:
setProperties(Hashtable), attribsHash(), store()

createOwnedComponents

protected void createOwnedComponents(java.util.Hashtable owned)
                              throws InitializeException
Throws:
InitializeException

setComponentFiler

public void setComponentFiler(ComponentFiler filer)
Set a custom ComponentFiler to use instead of the DefaultComponentFiler.

Parameters:
filer - The ComponentFiler to use.
See Also:
setComponentFilerParams(Hashtable), initialize()

setComponentFilerParams

public void setComponentFilerParams(java.util.Hashtable params)
Set the params for the custom ComponentFiler.

Parameters:
params - The params to pass to the filer.
See Also:
setComponentFiler(ComponentFiler), initialize()

store

public void store()
           throws java.io.IOException
Store the current component into the file defined by the xmlFileName property

Throws:
java.io.IOException

getOrderedChildNames

protected java.util.Vector getOrderedChildNames()

attribsHash

public java.util.Hashtable attribsHash()
Return all this component's attributes in a hash.

Returns:
Hashtable with this component's attributes and this values as Strings.

registerChild

public void registerChild(Component obj)
Register a component as owned of this component

Parameters:
obj - The object itself

freeChild

public void freeChild(java.lang.String name)
Removes the component

Parameters:
name - The name of the component

getChild

public Component getChild(java.lang.String name)
Get the component with name "name"

Parameters:
name - the name of the component to get
Returns:
the component. You must typecast it.

getChildClass

public java.lang.Class getChildClass(java.lang.String name)
Get the class of the component with name "name"

Parameters:
name - The name of the component to get
Returns:
The class of the component or null if a child with this name is not found.

listChilds

public java.util.Enumeration listChilds()
Returns:
An enumeration with the name of the owned children of this component.

dispatch

public void dispatch(java.lang.String eventName)
              throws java.lang.Exception
Dispatch an event from this object. Does nothing if the component is designing.

Parameters:
eventName -
Throws:
java.lang.Exception
See Also:
designing

eventParamTypes

public java.lang.Class[] eventParamTypes(java.lang.String ev)

eventParamValues

public java.lang.Object[] eventParamValues(java.lang.String ev)

dispatchFunction

public void dispatchFunction(java.lang.String function,
                             java.lang.Class[] paramTypes,
                             java.lang.Object[] values)
                      throws java.lang.reflect.InvocationTargetException,
                             java.lang.NoSuchMethodException,
                             java.lang.IllegalAccessException
Throws:
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.IllegalAccessException

queue

public void queue(java.lang.String ev)
queue an event

Parameters:
ev - the name of the event

dispatchAll

public void dispatchAll()
                 throws java.lang.Exception
dispatch all the events in the event queue

Throws:
java.lang.Exception

getApplication

public Application getApplication()
Get the Application object from the TopLevel.

See Also:
TopLevel.getApplication()

getClone

public Component getClone()
                   throws java.lang.CloneNotSupportedException
Throws:
java.lang.CloneNotSupportedException

isDesigning

public boolean isDesigning()
Getter for property designing.

Returns:
Value of property designing.
See Also:
designing

setDesigning

public void setDesigning(boolean designing)
Setter for property designing.

Parameters:
designing - New value of property designing.
See Also:
designing

getBag

public java.util.Hashtable getBag()
Getter for property bag.

Returns:
The bag of data.
See Also:
bag, setBag(Hashtable)

setBag

public void setBag(java.util.Hashtable bag)
Setter for property bag.

Parameters:
bag - The new bag to overwrite the current one.
See Also:
bag, getBag()

putInBag

public void putInBag(java.lang.Object key,
                     java.lang.Object value)
Put the object in this component's bag.

Parameters:
key - The key.
value - The object to put.
See Also:
bag, getFromBag(Object)

getFromBag

public java.lang.Object getFromBag(java.lang.Object key)
Put the object in this component's bag.

Parameters:
key - The key.
Returns:
The object in the bag.
See Also:
bag, putInBag(Object,Object)

removeFromBag

public java.lang.Object removeFromBag(java.lang.Object key)
Remove the object from this component's bag.

Parameters:
key - The key.
Returns:
The value in which the key had been mapped in the bag or null if the key did not have a mapping.
See Also:
bag, putInBag(Object,Object)

descendentOf

public boolean descendentOf(java.lang.String name)
Verify if this component has an ancestor named name
In Component, this is always false, because there is no parent.

Parameters:
name - The name of the ancestor component
Returns:
boolean always false

getOwner

protected Component getOwner()
Getter for property owner.

Returns:
Value of property owner.

setOwner

protected void setOwner(Component owner)
Setter for property owner.

Parameters:
owner - New value of property owner.

serializedBag

public java.lang.String serializedBag()

unserializeBag

protected void unserializeBag(java.lang.String data)