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 delegating action.
025     *
026     * @author <a href="http://www.dpml.net">Digital Product Management Library</a>
027     * @version 2.1.1
028     */
029    public class ApplyAction implements Action, Serializable
030    {
031        private final String m_id;
032        
033       /**
034        * Creation of a new apply action.
035        * @param id transition name
036        */
037        public ApplyAction( final String id )
038        {
039            if( null == id )
040            {
041                throw new NullPointerException( "id" );
042            }
043            m_id = id;
044        }
045        
046       /**
047        * Return the action name.
048        * @return the name
049        */
050        public String getName()
051        {
052            return "apply:"+ m_id;
053        }
054        
055       /**
056        * Return the id of the transition to apply.
057        * @return the transition id
058        */
059        public String getID()
060        {
061            return m_id;
062        }
063        
064       /**
065        * Compare this object to another for equality.
066        * @param other the other object
067        * @return true if the object is equal to this object
068        */
069        public boolean equals( Object other )
070        {
071            if( null == other )
072            {
073                return false;
074            }
075            else if( other instanceof ApplyAction )
076            {
077                ApplyAction action = (ApplyAction) other;
078                return m_id.equals( action.getID() );
079            }
080            else
081            {
082                return false;
083            }
084        }
085        
086       /**
087        * Compute the hashcode for this instance.
088        * @return the hashcode value
089        */
090        public int hashCode()
091        {
092            return m_id.hashCode();
093        }
094    
095       /**
096        * Return a string representation of the instance.
097        * @return the string value
098        */
099        public String toString()
100        {
101            return "apply:" + m_id;
102        }
103    }