001    // SECTION-START[License Header]
002    // <editor-fold defaultstate="collapsed" desc=" Generated License ">
003    /*
004     *   Java Object Management and Configuration
005     *   Copyright (C) Christian Schulte, 2005-206
006     *   All rights reserved.
007     *
008     *   Redistribution and use in source and binary forms, with or without
009     *   modification, are permitted provided that the following conditions
010     *   are met:
011     *
012     *     o Redistributions of source code must retain the above copyright
013     *       notice, this list of conditions and the following disclaimer.
014     *
015     *     o Redistributions in binary form must reproduce the above copyright
016     *       notice, this list of conditions and the following disclaimer in
017     *       the documentation and/or other materials provided with the
018     *       distribution.
019     *
020     *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
021     *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
022     *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
023     *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
024     *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
025     *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026     *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027     *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028     *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
029     *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030     *
031     *   $JOMC: DefaultInvocation.java 4381 2012-03-04 19:29:29Z schulte2005 $
032     *
033     */
034    // </editor-fold>
035    // SECTION-END
036    package org.jomc.ri;
037    
038    import java.lang.reflect.Method;
039    import java.util.HashMap;
040    import java.util.Map;
041    import org.jomc.model.Instance;
042    import org.jomc.model.Modules;
043    import org.jomc.spi.Invocation;
044    
045    // SECTION-START[Documentation]
046    // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
047    /**
048     * Default {@code Invocation} implementation.
049     *
050     * <dl>
051     *   <dt><b>Identifier:</b></dt><dd>org.jomc.ri.DefaultInvocation</dd>
052     *   <dt><b>Name:</b></dt><dd>JOMC RI</dd>
053     *   <dt><b>Abstract:</b></dt><dd>No</dd>
054     *   <dt><b>Final:</b></dt><dd>No</dd>
055     *   <dt><b>Stateless:</b></dt><dd>No</dd>
056     * </dl>
057     *
058     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
059     * @version 1.0
060     */
061    // </editor-fold>
062    // SECTION-END
063    // SECTION-START[Annotations]
064    // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
065    @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
066    // </editor-fold>
067    // SECTION-END
068    public class DefaultInvocation implements Invocation
069    {
070        // SECTION-START[DefaultInvocation]
071    
072        /** Constant for the context key of the {@code Object} of this invocation. */
073        public static final String OBJECT_KEY = "org.jomc.spi.Invocation.object";
074    
075        /** Constant for the context key of the {@code Method} of this invocation. */
076        public static final String METHOD_KEY = "org.jomc.spi.Invocation.method";
077    
078        /** Constant for the context key of the {@code Object[]} arguments of this invocation. */
079        public static final String ARGUMENTS_KEY = "org.jomc.spi.Invocation.arguments";
080    
081        /** Constant for the context key of the result {@code Object} of this invocation. */
082        public static final String RESULT_KEY = "org.jomc.spi.Invocation.result";
083    
084        /** Constant for the context key of the {@code Instance} corresponding to the object of this invocation. */
085        public static final String INSTANCE_KEY = "org.jomc.spi.Invocation.instance";
086    
087        /** Constant for the context key of the {@code Modules} corresponding to the object of this invocation. */
088        public static final String MODULES_KEY = "org.jomc.spi.Invocation.modules";
089    
090        /** Constant for the context key of the {@code ClassLoader} corresponding to the modules of this invocation. */
091        public static final String CLASSLOADER_KEY = "org.jomc.spi.Invocation.classLoader";
092    
093        /** The context of this invocation. */
094        private Map context;
095    
096        /**
097         * Creates a new {@code DefaultInvocation} instance taking an invocation to initialize the instance with.
098         *
099         * @param invocation The invocation to initialize the instance with.
100         */
101        public DefaultInvocation( final Invocation invocation )
102        {
103            this.context = new HashMap( invocation.getContext() );
104        }
105    
106        public Map getContext()
107        {
108            if ( this.context == null )
109            {
110                this.context = new HashMap();
111            }
112    
113            return this.context;
114        }
115    
116        public Object getObject()
117        {
118            return this.getContext().get( OBJECT_KEY );
119        }
120    
121        public Method getMethod()
122        {
123            return (Method) this.getContext().get( METHOD_KEY );
124        }
125    
126        public Object[] getArguments()
127        {
128            return (Object[]) this.getContext().get( ARGUMENTS_KEY );
129        }
130    
131        public Object getResult()
132        {
133            return this.getContext().get( RESULT_KEY );
134        }
135    
136        public void setResult( final Object value )
137        {
138            if ( value == null )
139            {
140                this.getContext().remove( RESULT_KEY );
141            }
142            else
143            {
144                this.getContext().put( RESULT_KEY, value );
145            }
146        }
147    
148        /**
149         * Gets the instance of the object of this invocation from the context of this invocation.
150         *
151         * @return The instance of the object of this invocation from the context of this invocation or {@code null}.
152         *
153         * @see #INSTANCE_KEY
154         */
155        public Instance getInstance()
156        {
157            return (Instance) this.getContext().get( INSTANCE_KEY );
158        }
159    
160        /**
161         * Gets the modules corresponding to the object of this invocation from the context of this invocation.
162         *
163         * @return The modules corresponding to the object of this invocation from the context of this invocation or
164         * {@code null}.
165         *
166         * @see #MODULES_KEY
167         */
168        public Modules getModules()
169        {
170            return (Modules) this.getContext().get( MODULES_KEY );
171        }
172    
173        /**
174         * Gets the class loader corresponding to the modules of this invocation from the context of this invocation.
175         *
176         * @return The class loader corresponding to the modules of this invocation from the context of this invocation or
177         * {@code null}.
178         *
179         * @see #CLASSLOADER_KEY
180         */
181        public ClassLoader getClassLoader()
182        {
183            return (ClassLoader) this.getContext().get( CLASSLOADER_KEY );
184        }
185    
186        // SECTION-END
187        // SECTION-START[Constructors]
188        // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
189        /** Creates a new {@code DefaultInvocation} instance. */
190        @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
191        public DefaultInvocation()
192        {
193            // SECTION-START[Default Constructor]
194            super();
195            // SECTION-END
196        }
197        // </editor-fold>
198        // SECTION-END
199        // SECTION-START[Dependencies]
200        // SECTION-END
201        // SECTION-START[Properties]
202        // SECTION-END
203        // SECTION-START[Messages]
204        // SECTION-END
205    }