
org.refcodes.observer.impls.MetaDataEventImpl Maven / Gradle / Ivy
Show all versions of refcodes-observer Show documentation
// /////////////////////////////////////////////////////////////////////////////
// REFCODES.ORG
// =============================================================================
// This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
// under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
// licenses:
// =============================================================================
// GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
// together with the GPL linking exception applied; as being applied by the GNU
// Classpath ("http://www.gnu.org/software/classpath/license.html")
// =============================================================================
// Apache License, v2.0 ("http://www.apache.org/licenses/LICENSE-2.0")
// =============================================================================
// Please contact the copyright holding author(s) of the software artifacts in
// question for licensing issues not being covered by the above listed licenses,
// also regarding commercial licensing models or regarding the compatibility
// with other open source licenses.
// /////////////////////////////////////////////////////////////////////////////
package org.refcodes.observer.impls;
import org.refcodes.observer.ActionEvent;
import org.refcodes.observer.EventMatcherByDeclaration;
import org.refcodes.observer.EventMetaData;
import org.refcodes.observer.MetaDataEvent;
import org.refcodes.observer.Observer;
import org.refcodes.runtime.RuntimeUtility;
/**
* Ready to use {@link ActionEvent} storing a defined set of
* {@link EventMetaData}.
*
* TIPP: In order to distinguish {@link MetaDataEventImpl} instances from each
* other, create an actions enumeration, enumerating the various event actions
* you support. Pass the actual action you intend to notify upon to the
* according constructor, as an {@link Observer} you may use the declarative
* method {@link EventMatcherByDeclaration#actionEqualWith(Object)} to test
* whether your action was notified (or a simple switch case statement).
*
* @param The type of the source in question.
*/
public class MetaDataEventImpl extends AbstractEvent implements MetaDataEvent {
// /////////////////////////////////////////////////////////////////////////
// VARIABLES:
// /////////////////////////////////////////////////////////////////////////
private EventMetaData _eventMetaData;
// /////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS:
// /////////////////////////////////////////////////////////////////////////
/**
* Constructs an event with the given meta Data.
*
* @param aEventMetaData The meta data to by supplied by the event.
* @param aSource The source from which this event originated.
*/
public MetaDataEventImpl( EventMetaData aEventMetaData, SRC aSource ) {
super( aSource );
_eventMetaData = aEventMetaData;
}
/**
* Constructs an event with the given meta Data.
*
* @param channel The value for {@link EventMetaData#getChannel()}
* attribute.
* @param aSource The source from which this event originated.
*/
public MetaDataEventImpl( String channel, SRC aSource ) {
super( aSource );
_eventMetaData = new EventMetaDataImpl( channel, RuntimeUtility.getCallerStackTraceElement( MetaDataEventImpl.class ) );
}
/**
* Constructs an event with the given meta Data.
*
* @param The type of the action stored in the event. CAUTION: The
* drawback of not using generic generic type declaration on a class
* level is no granted type safety, the advantage is the ease of use:
* Sub-classes can be used out of the box.
*
* @param aEventMetaData The meta data to by supplied by the event.
*
* @param aAction The action which the {@link ActionEvent} represents.
*
* @param aSource The source from which this event originated.
*/
public MetaDataEventImpl( SRC aSource ) {
super( aSource );
_eventMetaData = new EventMetaDataImpl( RuntimeUtility.getCallerStackTraceElement( MetaDataEventImpl.class ) );
}
// /////////////////////////////////////////////////////////////////////////
// METHODS:
// /////////////////////////////////////////////////////////////////////////
@Override
public EventMetaData getMetaData() {
return _eventMetaData;
}
}