001 /* 002 * Copyright 2005 Stephen J. McConnell. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.state; 020 021 import java.io.Serializable; 022 023 /** 024 * Default implementation of trigger. 025 * 026 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 027 * @version 1.0.4 028 */ 029 public class DefaultTrigger implements Trigger, Serializable 030 { 031 private final TriggerEvent m_event; 032 private final Action m_action; 033 034 /** 035 * Creation of a new trigger. 036 * @param event the trigger event constant 037 * @param action the action fired by the trigger 038 */ 039 public DefaultTrigger( final TriggerEvent event, final Action action ) 040 { 041 if( null == event ) 042 { 043 throw new NullPointerException( "event" ); 044 } 045 if( null == action ) 046 { 047 throw new NullPointerException( "action" ); 048 } 049 m_event = event; 050 m_action = action; 051 } 052 053 /** 054 * Return the event enumneration that this trigger is associated with. 055 * @return the triggering event class 056 */ 057 public TriggerEvent getEvent() 058 { 059 return m_event; 060 } 061 062 /** 063 * Return the actions that this trigger initiates. 064 * @return the triggered action 065 */ 066 public Action getAction() 067 { 068 return m_action; 069 } 070 071 /** 072 * Compare this object to another for equality. 073 * @param other the other object 074 * @return true if the object is equal to this object 075 */ 076 public boolean equals( Object other ) 077 { 078 if( null == other ) 079 { 080 return false; 081 } 082 else if( other instanceof DefaultTrigger ) 083 { 084 DefaultTrigger trigger = (DefaultTrigger) other; 085 if( !m_event.equals( trigger.getEvent() ) ) 086 { 087 return false; 088 } 089 else 090 { 091 return m_action.equals( trigger.getAction() ); 092 } 093 } 094 else 095 { 096 return false; 097 } 098 } 099 100 /** 101 * Compute the hashcode for this instance. 102 * @return the hashcode value 103 */ 104 public int hashCode() 105 { 106 int hash = m_event.hashCode(); 107 hash ^= m_action.hashCode(); 108 return hash; 109 } 110 111 /** 112 * Return a string representation of the instance. 113 * @return the string value 114 */ 115 public String toString() 116 { 117 return "trigger:" + m_event.getName(); 118 } 119 }