View Javadoc

1   // SECTION-START[License Header]
2   // <editor-fold defaultstate="collapsed" desc=" Generated License ">
3   /*
4    *   Java Object Management and Configuration
5    *   Copyright (C) Christian Schulte, 2005-206
6    *   All rights reserved.
7    *
8    *   Redistribution and use in source and binary forms, with or without
9    *   modification, are permitted provided that the following conditions
10   *   are met:
11   *
12   *     o Redistributions of source code must retain the above copyright
13   *       notice, this list of conditions and the following disclaimer.
14   *
15   *     o Redistributions in binary form must reproduce the above copyright
16   *       notice, this list of conditions and the following disclaimer in
17   *       the documentation and/or other materials provided with the
18   *       distribution.
19   *
20   *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21   *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22   *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23   *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
24   *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25   *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26   *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27   *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29   *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   *
31   *   $JOMC: DefaultInvocation.java 4712 2013-01-02 13:56:12Z schulte $
32   *
33   */
34  // </editor-fold>
35  // SECTION-END
36  package org.jomc.ri;
37  
38  import java.lang.reflect.Method;
39  import java.util.HashMap;
40  import java.util.Map;
41  import org.jomc.model.Instance;
42  import org.jomc.model.Modules;
43  import org.jomc.spi.Invocation;
44  
45  // SECTION-START[Documentation]
46  // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
47  /**
48   * Default {@code Invocation} implementation.
49   *
50   * <dl>
51   *   <dt><b>Identifier:</b></dt><dd>org.jomc.ri.DefaultInvocation</dd>
52   *   <dt><b>Name:</b></dt><dd>JOMC ⁑ RI ⁑ DefaultInvocation</dd>
53   *   <dt><b>Abstract:</b></dt><dd>No</dd>
54   *   <dt><b>Final:</b></dt><dd>No</dd>
55   *   <dt><b>Stateless:</b></dt><dd>No</dd>
56   * </dl>
57   *
58   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0
59   * @version 1.0
60   */
61  // </editor-fold>
62  // SECTION-END
63  // SECTION-START[Annotations]
64  // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
65  @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" )
66  // </editor-fold>
67  // SECTION-END
68  public class DefaultInvocation implements Invocation
69  {
70      // SECTION-START[DefaultInvocation]
71  
72      /** Constant for the context key of the {@code Object} of this invocation. */
73      public static final String OBJECT_KEY = "org.jomc.spi.Invocation.object";
74  
75      /** Constant for the context key of the {@code Method} of this invocation. */
76      public static final String METHOD_KEY = "org.jomc.spi.Invocation.method";
77  
78      /** Constant for the context key of the {@code Object[]} arguments of this invocation. */
79      public static final String ARGUMENTS_KEY = "org.jomc.spi.Invocation.arguments";
80  
81      /** Constant for the context key of the result {@code Object} of this invocation. */
82      public static final String RESULT_KEY = "org.jomc.spi.Invocation.result";
83  
84      /** Constant for the context key of the {@code Instance} corresponding to the object of this invocation. */
85      public static final String INSTANCE_KEY = "org.jomc.spi.Invocation.instance";
86  
87      /** Constant for the context key of the {@code Modules} corresponding to the object of this invocation. */
88      public static final String MODULES_KEY = "org.jomc.spi.Invocation.modules";
89  
90      /** Constant for the context key of the {@code ClassLoader} corresponding to the modules of this invocation. */
91      public static final String CLASSLOADER_KEY = "org.jomc.spi.Invocation.classLoader";
92  
93      /** The context of this invocation. */
94      private Map context;
95  
96      /**
97       * Creates a new {@code DefaultInvocation} instance taking an invocation to initialize the instance with.
98       *
99       * @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.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" )
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 }