fi.hut.tml.xsmiles.mlfc.timesheet
Class TimedElementImpl

java.lang.Object
  extended byorg.apache.xerces.dom.NodeImpl
      extended byorg.apache.xerces.dom.ChildNode
          extended byorg.apache.xerces.dom.ParentNode
              extended byorg.apache.xerces.dom.ElementImpl
                  extended byorg.apache.xerces.dom.ElementNSImpl
                      extended byfi.hut.tml.xsmiles.dom.XSmilesElementImpl
                          extended byfi.hut.tml.xsmiles.mlfc.timesheet.TimedElementImpl
All Implemented Interfaces:
java.lang.Cloneable, org.w3c.dom.Element, EventHandlerService, org.w3c.dom.events.EventTarget, InitializableElement, org.w3c.dom.Node, org.w3c.dom.NodeList, PseudoClassController, ResourceFetcher, java.io.Serializable, StylableElement, TimedElement, org.w3c.dom.TypeInfo
Direct Known Subclasses:
ExclImpl, ItemImpl, ParImpl, SeqImpl, TimesheetImpl

public abstract class TimedElementImpl
extends XSmilesElementImpl
implements TimedElement, EventHandlerService

Implementation of the Timesheets. Subclasses of this class implement all the timesheet elements in the document.

Since:
Mar 5, 2004
Version:
$Revision: 6388 $, $Date: 2006-02-14 15:11:15 +0200 (Tue, 14 Feb 2006) $
Author:
tjjalava
See Also:
Serialized Form

Nested Class Summary
protected  class TimedElementImpl.Schedule
          Inner class that holds all the information for this element's start or stop scheduling
 
Nested classes inherited from class fi.hut.tml.xsmiles.dom.XSmilesElementImpl
XSmilesElementImpl.PseudoNodeList
 
Field Summary
protected  boolean active
          The current active state of this TimedElement instance
protected  TimedElementImpl.Schedule beginSchedule
          Holds the information of when this element is to be started
protected  java.util.Vector childItems
          All children of this element that are instances of TimedElement.
protected  long currentTick
          Current time
protected  boolean elementStarted
          The status of this TimedElement, whether it is started or not
protected  TimedElementImpl.Schedule endSchedule
          Holds the information of when this element is to be stopped
protected  fi.hut.tml.xsmiles.mlfc.timesheet.TimesheetEventListener eventListener
          The event listener of this TimedElement
protected  TimedEventTable eventTable
          Event table for start and end events of the children of this TimedElement
protected static int INFINITY
          Value used for repeat count when repeat attribute is infinite
protected  TimedElementImpl parent
          The parent element of this TimedElement.
protected  boolean paused
          Is this instance paused
protected  int repeatCount
          The value of repeat attribute
static java.lang.String SELECT_FIRST
           
static java.lang.String SELECT_LAST
           
static java.lang.String SELECT_NEXT
           
static java.lang.String SELECT_PREV
           
static int START_EVENT
           
static int START_SCHEDULED
          Event code for the TimedEvent START_SCHEDULED command
static int STOP
          Event code for the TimedEvent STOP command
 
Fields inherited from class fi.hut.tml.xsmiles.dom.XSmilesElementImpl
DESTROYED, elementStatus, INITIALIZED, INITIALIZING, setPseudoClasses, style, UNINITIALIZED, xblpropname
 
Fields inherited from class org.apache.xerces.dom.ElementNSImpl
localName, namespaceURI
 
Fields inherited from class org.apache.xerces.dom.ElementImpl
attributes, name
 
Fields inherited from class org.apache.xerces.dom.ParentNode
firstChild, fNodeListCache, ownerDocument
 
Fields inherited from class org.apache.xerces.dom.ChildNode
nextSibling, previousSibling
 
Fields inherited from class org.apache.xerces.dom.NodeImpl
DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_IS_CONTAINED, DOCUMENT_POSITION_PRECEDING, ELEMENT_DEFINITION_NODE, FIRSTCHILD, flags, HASSTRING, ID, IGNORABLEWS, OWNED, ownerNode, READONLY, SPECIFIED, SYNCCHILDREN, SYNCDATA, TREE_POSITION_ANCESTOR, TREE_POSITION_DESCENDANT, TREE_POSITION_DISCONNECTED, TREE_POSITION_EQUIVALENT, TREE_POSITION_FOLLOWING, TREE_POSITION_PRECEDING, TREE_POSITION_SAME_NODE, UNNORMALIZED
 
Fields inherited from interface fi.hut.tml.xsmiles.timesheet.TimedElement
BEGIN_ATTR, DURATION_ATTR, ELEMENT_BEGIN_EVENT, ELEMENT_END_EVENT, ELEMENT_NOT_PAUSED_EVENT, ELEMENT_PAUSED_EVENT, EXCL_ELEM, INDEFINITE_VALUE, ITEM_ELEM, PAR_ELEM, PREFETCH_ATTR, REPEAT_ATTR, SELECT_ATTR, SEQ_ELEM, TIMESHEET_ELEM
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
protected TimedElementImpl(org.apache.xerces.dom.DocumentImpl owner, java.lang.String namespace, java.lang.String tag)
          Creates a new TimedElement instance.
 
Method Summary
 void activate(org.w3c.dom.events.Event evt)
          Activate this element
protected  void addPauseListener(TimedElement elem)
          Informs the timesheet that the argument should know the changes in pause-state.
protected  void addPrefetchedMedia(MediaElement media)
          Informs the timesheet that the argument should be prefetched before the timing is started.
protected static org.w3c.dom.events.Event createEvent(java.lang.String event)
          Creates a new dom event.
protected abstract  void doRepeat()
          Subclasses must implement this to handle the repeating
protected  void doSetPaused()
          Subclasses should implement this method for the actions caused by the change in pause status
protected abstract  void doStartElement()
          Subclasses must implement this to make it ready to be started
protected abstract  void doStopElement()
          Subclasses must implement this to take care of all things needed for this element to stop
protected  void elementEnded(TimedElementImpl elem)
          Informs this TimedElement instance that the argument has ended
protected abstract  void elementStarting(TimedElementImpl elem)
          Called by a child element of this element to notify that the child is going to start due to some dom event it was listening to.
protected  java.util.Hashtable getCache()
          Returns a Hashtable that is common to all the elements in current timesheet.
protected abstract  boolean handleElementEnded(TimedElementImpl elem)
          Checks whether this element should take some specific action when a child element notifies it's going to end.
protected  void handleEvent(org.w3c.dom.events.Event evt)
          Handle the DOMEvent targeted to this element.
protected  boolean hasEventScheduled(int event)
           
 void init()
          Initialize this element.
 boolean isActive()
          Is element active right now
 boolean isPaused()
          Is element paused right now
protected  void notifyEnd()
          Notifies the parent element that this element is about to end
protected  void notifyStart()
          Notifies the parent element that this element is about to start
protected static int parseRepeatCount(TimedElementImpl elem)
          Parses the repeat count of the argument
protected  TimedElementImpl.Schedule parseTimeAttribute(java.lang.String attr)
          Parses the attribute containing schedule information of this element, ie.
 void schedule()
          Schedules the element, sets the time when the element should be set active.
protected  void scheduleEnd()
          Schedule the time when this element should stop
protected  void scheduleEvent(long tick, int event)
          Schedules a new event.
 void setActive(boolean active)
          Sets the element active or non-active.
 void setEnabled(boolean enabled)
          Enables or disables the timesheet.
protected  void setEventListeners()
          Sets this element to listen to the selected custom DOMEvents.
 void setPaused(boolean paused)
          Sets the pause status of the element
protected  boolean shouldRepeat()
          Should this element still repeat itself
protected  void startElement()
          Called by the Timer thread when eventTable has START_SCHEDULED event scheduled for the argument on current update round.
protected  void stopElement()
          Called by the Timer thread when eventTable has STOP event scheduled for the argument on current update round.
 java.lang.String toString()
           
protected  void unSchedule()
          Unschedules all the children of this element and clears the event table
 void update()
          Called by the Timer instance of this element every tick.
 
Methods inherited from class fi.hut.tml.xsmiles.dom.XSmilesElementImpl
addBinding, addUndistributedChild, clone, clonePseudoElements, cloneSubtree, debugNode, debugNode, destroy, dispatchEventInMainThread, get, getApplyBindingSheets, getAuthorSheets, getChildNodes, getElementStatus, getId, getOriginalClone, getPseudoClass, getResourceReferencer, getRuleNode, getStyle, getStyleAttrValue, getText, getText, getUndistributedChildNodes, getXblImplementations, hasBinding, hasStyle, initFinalFlattenedTree, initStyle, isInitedForReset, isPseudoClass, removeBinding, removeUndistributedChild, replaceNode, resetFinalFlattenedTree, resolveURI, searchElementWithId, searchElementWithId, setApplyBindingSheets, setAuthorSheets, setPseudoClass, setRuleNode, setStyle, updateStyle
 
Methods inherited from class org.apache.xerces.dom.ElementNSImpl
getBaseURI, getLocalName, getNamespaceURI, getPrefix, getTypeName, getTypeNamespace, setPrefix, setType, setValues
 
Methods inherited from class org.apache.xerces.dom.ElementImpl
cloneNode, getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getDefaultAttributes, getElementsByTagName, getElementsByTagNameNS, getNodeName, getNodeType, getSchemaTypeInfo, getTagName, getXercesAttribute, hasAttribute, hasAttributeNS, hasAttributes, isEqualNode, normalize, reconcileDefaultAttributes, removeAttribute, removeAttributeNode, removeAttributeNS, setAttribute, setAttributeNode, setAttributeNodeNS, setAttributeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS, setReadOnly, setupDefaultAttributes, setXercesAttributeNode, synchronizeData
 
Methods inherited from class org.apache.xerces.dom.ParentNode
getChildNodes, getChildNodesUnoptimized, getFirstChild, getLastChild, getLength, getOwnerDocument, getTextContent, hasChildNodes, insertBefore, item, removeChild, replaceChild, setTextContent, synchronizeChildren
 
Methods inherited from class org.apache.xerces.dom.ChildNode
getNextSibling, getParentNode, getPreviousSibling
 
Methods inherited from class org.apache.xerces.dom.NodeImpl
addEventListener, appendChild, changed, changes, compareDocumentPosition, compareTreePosition, dispatchEvent, getContainer, getFeature, getNodeNumber, getNodeValue, getReadOnly, getUserData, getUserData, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, needsSyncChildren, removeEventListener, setNodeValue, setUserData, setUserData
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Element
getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getElementsByTagName, getElementsByTagNameNS, getTagName, hasAttribute, hasAttributeNS, removeAttribute, removeAttributeNode, removeAttributeNS, setAttribute, setAttributeNode, setAttributeNodeNS, setAttributeNS
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, insertBefore, isSupported, normalize, removeChild, replaceChild, setNodeValue, setPrefix
 

Field Detail

START_SCHEDULED

public static final int START_SCHEDULED
Event code for the TimedEvent START_SCHEDULED command

See Also:
Constant Field Values

START_EVENT

public static final int START_EVENT
See Also:
Constant Field Values

STOP

public static final int STOP
Event code for the TimedEvent STOP command

See Also:
Constant Field Values

SELECT_NEXT

public static final java.lang.String SELECT_NEXT
See Also:
Constant Field Values

SELECT_PREV

public static final java.lang.String SELECT_PREV
See Also:
Constant Field Values

SELECT_FIRST

public static final java.lang.String SELECT_FIRST
See Also:
Constant Field Values

SELECT_LAST

public static final java.lang.String SELECT_LAST
See Also:
Constant Field Values

INFINITY

protected static final int INFINITY
Value used for repeat count when repeat attribute is infinite

See Also:
Constant Field Values

active

protected boolean active
The current active state of this TimedElement instance


eventTable

protected TimedEventTable eventTable
Event table for start and end events of the children of this TimedElement


currentTick

protected long currentTick
Current time


paused

protected boolean paused
Is this instance paused


parent

protected TimedElementImpl parent
The parent element of this TimedElement. TimesheetElement doesn't have a parent.


repeatCount

protected int repeatCount
The value of repeat attribute


elementStarted

protected boolean elementStarted
The status of this TimedElement, whether it is started or not


beginSchedule

protected TimedElementImpl.Schedule beginSchedule
Holds the information of when this element is to be started


endSchedule

protected TimedElementImpl.Schedule endSchedule
Holds the information of when this element is to be stopped


childItems

protected java.util.Vector childItems
All children of this element that are instances of TimedElement. Helps enumerating them.


eventListener

protected fi.hut.tml.xsmiles.mlfc.timesheet.TimesheetEventListener eventListener
The event listener of this TimedElement

Constructor Detail

TimedElementImpl

protected TimedElementImpl(org.apache.xerces.dom.DocumentImpl owner,
                           java.lang.String namespace,
                           java.lang.String tag)
Creates a new TimedElement instance. Initialized the eventTable *

Method Detail

parseRepeatCount

protected static int parseRepeatCount(TimedElementImpl elem)
Parses the repeat count of the argument

Parameters:
elem - the element which repeat count is to be parsed
Returns:
repeat count or

parseTimeAttribute

protected TimedElementImpl.Schedule parseTimeAttribute(java.lang.String attr)
                                                throws java.lang.NumberFormatException
Parses the attribute containing schedule information of this element, ie. either begin or dur attributes

Parameters:
attr - the value of the attribute
Returns:
an instance of inner class Schedule containing all the scheduling information of the attribute
Throws:
java.lang.NumberFormatException - if attribute cannot be parsed

createEvent

protected static org.w3c.dom.events.Event createEvent(java.lang.String event)
Creates a new dom event. Events created have argument "can bubble" and "cancelable"

Parameters:
event - the type of event
Returns:
new Event instance

doRepeat

protected abstract void doRepeat()
Subclasses must implement this to handle the repeating


elementStarting

protected abstract void elementStarting(TimedElementImpl elem)
Called by a child element of this element to notify that the child is going to start due to some dom event it was listening to. Subclasses must implement this to handle the waking up of one of it's children

Parameters:
elem - the TimedElement that is starting

doStartElement

protected abstract void doStartElement()
Subclasses must implement this to make it ready to be started


doStopElement

protected abstract void doStopElement()
Subclasses must implement this to take care of all things needed for this element to stop


handleElementEnded

protected abstract boolean handleElementEnded(TimedElementImpl elem)
Checks whether this element should take some specific action when a child element notifies it's going to end. If nothing special is needed to be done, the method should return false.

Parameters:
elem - the element that is about to end
Returns:
true if something special is done, false for the default action

setEventListeners

protected void setEventListeners()
Sets this element to listen to the selected custom DOMEvents. Subclasses provide the implementation if needed.


handleEvent

protected void handleEvent(org.w3c.dom.events.Event evt)
Handle the DOMEvent targeted to this element.

Parameters:
evt - the catched DOM event

elementEnded

protected final void elementEnded(TimedElementImpl elem)
Informs this TimedElement instance that the argument has ended

Parameters:
elem - the element instance that has ended

startElement

protected final void startElement()
Called by the Timer thread when eventTable has START_SCHEDULED event scheduled for the argument on current update round.


stopElement

protected final void stopElement()
Called by the Timer thread when eventTable has STOP event scheduled for the argument on current update round.


doSetPaused

protected void doSetPaused()
Subclasses should implement this method for the actions caused by the change in pause status


addPauseListener

protected void addPauseListener(TimedElement elem)
Informs the timesheet that the argument should know the changes in pause-state.

Parameters:
elem - TimedElement needing the pause information

getCache

protected java.util.Hashtable getCache()
Returns a Hashtable that is common to all the elements in current timesheet. Can be used to save information commonly needed.

Returns:
Hashtable

addPrefetchedMedia

protected void addPrefetchedMedia(MediaElement media)
Informs the timesheet that the argument should be prefetched before the timing is started.

Parameters:
media - TimedElement needing prefetch

scheduleEvent

protected void scheduleEvent(long tick,
                             int event)
Schedules a new event.

Parameters:
tick - time when event should happen
event - the event code, from TimedElementinterface

unSchedule

protected void unSchedule()
Unschedules all the children of this element and clears the event table


notifyStart

protected void notifyStart()
Notifies the parent element that this element is about to start


notifyEnd

protected void notifyEnd()
Notifies the parent element that this element is about to end


scheduleEnd

protected void scheduleEnd()
Schedule the time when this element should stop


shouldRepeat

protected boolean shouldRepeat()
Should this element still repeat itself

Returns:
true if repeat count is still more that zero

hasEventScheduled

protected boolean hasEventScheduled(int event)

init

public void init()
Description copied from class: XSmilesElementImpl
Initialize this element.

Specified by:
init in interface InitializableElement
Overrides:
init in class XSmilesElementImpl

setActive

public final void setActive(boolean active)
Sets the element active or non-active. For visual elements this propably means to set it visible or hidden

Parameters:
active - true to set element active, false otherwise

setPaused

public final void setPaused(boolean paused)
Sets the pause status of the element

Parameters:
paused - pause status

setEnabled

public void setEnabled(boolean enabled)
Enables or disables the timesheet. For timecontainers this method will recursively call the setEnabled-method of its children. The actual enabling/disabling happens in ItemImpl.

Parameters:
enabled -

isActive

public boolean isActive()
Is element active right now

Returns:
the active status

schedule

public void schedule()
Schedules the element, sets the time when the element should be set active. If element has children, this should propably also schedule them somehow.


isPaused

public boolean isPaused()
Is element paused right now

Returns:
pause status

update

public void update()
Description copied from interface: TimedElement
Called by the Timer instance of this element every tick. Do all the actions corresponding to the current ticknumber here.

Specified by:
update in interface TimedElement

activate

public void activate(org.w3c.dom.events.Event evt)
Description copied from interface: EventHandlerService
Activate this element

Specified by:
activate in interface EventHandlerService

toString

public java.lang.String toString()


X-Smiles 1.2