All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.refcodes.observer.impls.EventMetaDataImpl Maven / Gradle / Ivy

Go to download

Artifact for event handling purposes according to the observer (observable) pattern.

There is a newer version: 1.1.1
Show newest version
// /////////////////////////////////////////////////////////////////////////////
// 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.generator.impls.UniqueIdGeneratorSingleton;
import org.refcodes.observer.EventMetaData;
import org.refcodes.runtime.RuntimeUtility;

/**
 * Straight forward implementation of the minimal {@link EventMetaData}
 * interface. You might work in your domain driven framework with according
 * sub-types of the {@link EventMetaData} interface and the according
 * implementations of those.
 */
public class EventMetaDataImpl implements EventMetaData {

	// /////////////////////////////////////////////////////////////////////////
	// VARIABLES:
	// /////////////////////////////////////////////////////////////////////////

	private String _uid;
	private String _name;
	private String _group;
	private String _channel;
	private Class _publisherType;

	// /////////////////////////////////////////////////////////////////////////
	// CONSTRUCTORS:
	// /////////////////////////////////////////////////////////////////////////

	/**
	 * Constructs an instance of the {@link EventMetaData} with predefined
	 * values for the according properties retrieved from the caller's class.
	 * 
	 * The name property is set to the caller's plain class name. The group
	 * property is set to the caller's fully qualified package name without the
	 * class name. The UID is set by a generated UID. The publisher type is set
	 * to be the caller's class.
	 */
	public EventMetaDataImpl() {
		this( RuntimeUtility.getCallerStackTraceElement( EventMetaDataImpl.class ) );
	}

	/**
	 * Constructs an instance of the {@link EventMetaData} with predefined
	 * values for the according properties retrieved from the caller's class.
	 * 
	 * The name property is set to the caller's plain class name. The group
	 * property is set to the caller's fully qualified package name without the
	 * class name. The UID is set by a generated UID.
	 * 
	 * @param aPublisherType The type of the event publisher.
	 */
	public EventMetaDataImpl( Class aPublisherType ) {
		this( RuntimeUtility.getCallerStackTraceElement( EventMetaDataImpl.class ), aPublisherType );
	}
	
	/**
	 * Constructs an instance of the {@link EventMetaData} with predefined
	 * values for the according properties retrieved from the caller's class.
	 * 
	 * The name property is set to the caller's plain class name. The group
	 * property is set to the caller's fully qualified package name without the
	 * class name. The UID is set by a generated UID. The publisher type is set
	 * to be the caller's class.
	 * 
	 * @param aChannel The channel name on which the event is receivable.
	 */
	public EventMetaDataImpl( String aChannel ) {
		this( RuntimeUtility.getCallerStackTraceElement( EventMetaDataImpl.class ) );
		_channel = aChannel;
	}

	/**
	 * Constructs an instance of the {@link EventMetaData} with the given values
	 * for the according properties.
	 * 
	 * @param aName The name property.
	 * @param aGroup The group property.
	 * @param aChannel The channel property.
	 * @param aUid The UID (universal ID) property.
	 * @param aPublisherType The type of the event publisher.
	 */
	public EventMetaDataImpl( String aName , String aGroup , String aChannel , String aUid , Class aPublisherType  ) {
		_name = aName;
		_group = aGroup;
		_channel = aChannel;
		_publisherType = aPublisherType;
		_uid = aUid;
	}
	
	/**
	 * Constructs an instance of the {@link EventMetaData} with predefined
	 * values for the according properties retrieved from the caller's class
	 * (retrieved from the {@link StackTraceElement}; the assumed caller
	 * relative to the stack trace element and not this instance is taken).
	 * 
	 * The name property is set to the caller's plain class name. The group
	 * property is set to the caller's fully qualified package name without the
	 * class name. The UID is set by a generated UID.
	 * 
	 * @param aStackTraceElement The {@link StackTraceElement} from which to get
	 *        the caller's meta data.
	 */
	public EventMetaDataImpl( StackTraceElement aStackTraceElement ) {
		_name = RuntimeUtility.toClassName( aStackTraceElement );
		_group = RuntimeUtility.toFullyQualifiedPackageName( aStackTraceElement );
		_publisherType = RuntimeUtility.toClass( aStackTraceElement );
		_uid = UniqueIdGeneratorSingleton.getInstance().next();
	}
	
	/**
	 * Constructs an instance of the {@link EventMetaData} with predefined
	 * values for the according properties retrieved from the caller's class
	 * (retrieved from the {@link StackTraceElement}; the assumed caller
	 * relative to the stack trace element and not this instance is taken).
	 * 
	 * The name property is set to the caller's plain class name. The group
	 * property is set to the caller's fully qualified package name without the
	 * class name. The UID is set by a generated UID.
	 * 
	 * @param aChannel The channel property.
	 * @param aStackTraceElement The {@link StackTraceElement} from which to get
	 *        the caller's meta data.
	 */
	public EventMetaDataImpl( String aChannel, StackTraceElement aStackTraceElement ) {
		this( aStackTraceElement );
		_channel = aChannel;
	}

	/**
	 * Constructs an instance of the {@link EventMetaData} with predefined
	 * values for the according properties retrieved from the caller's class
	 * (retrieved from the {@link StackTraceElement}; the assumed caller
	 * relative to the stack trace element and not this instance is taken).
	 * 
	 * The name property is set to the caller's plain class name. The group
	 * property is set to the caller's fully qualified package name without the
	 * class name. The UID is set by a generated UID.
	 * 
	 * @param aStackTraceElement The {@link StackTraceElement} from which to get
	 *        the caller's meta data.
	 * 
	 * @param aPublisherType The type of the publisher not being set from the
	 *        {@link StackTraceElement}.
	 */
	public EventMetaDataImpl( StackTraceElement aStackTraceElement, Class aPublisherType ) {
		_name = RuntimeUtility.toClassName( aStackTraceElement );
		_group = RuntimeUtility.toFullyQualifiedPackageName( aStackTraceElement );
		_publisherType = aPublisherType;
		_uid = UniqueIdGeneratorSingleton.getInstance().next();
	}


	// /////////////////////////////////////////////////////////////////////////
	// METHODS:
	// /////////////////////////////////////////////////////////////////////////

	@Override
	public String getUniversalId() {
		return _uid;
	}

	@Override
	public String getName() {
		return _name;
	}

	@Override
	public String getGroup() {
		return _group;
	}
	
	@Override
	public String getChannel() {
		return _channel;
	}

	@Override
	public Class getPublisherType() {
		return _publisherType;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy