001 // SECTION-START[License Header]
002 // <editor-fold defaultstate="collapsed" desc=" Generated License ">
003 /*
004 * Copyright (c) 2009 The JOMC Project
005 * Copyright (c) 2005 Christian Schulte <cs@jomc.org>
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 BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS"
021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
022 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
023 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR
024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
027 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
028 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
029 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
030 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031 *
032 * $Id: DefaultInvocation.java 968 2009-11-18 06:08:28Z schulte2005 $
033 *
034 */
035 // </editor-fold>
036 // SECTION-END
037 package org.jomc.ri;
038
039 import java.lang.reflect.Method;
040 import java.util.HashMap;
041 import java.util.Map;
042 import org.jomc.model.Instance;
043 import org.jomc.spi.Invocation;
044
045 // SECTION-START[Documentation]
046 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
047 /**
048 * Default invocation.
049 * @see DefaultInvoker
050 *
051 * @author <a href="mailto:cs@jomc.org">Christian Schulte</a> 1.0
052 * @version $Id: DefaultInvocation.java 968 2009-11-18 06:08:28Z schulte2005 $
053 */
054 // </editor-fold>
055 // SECTION-END
056 // SECTION-START[Annotations]
057 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
058 @javax.annotation.Generated( value = "org.jomc.tools.JavaSources",
059 comments = "See http://jomc.sourceforge.net/jomc/1.0-alpha-8/jomc-tools" )
060 // </editor-fold>
061 // SECTION-END
062 public class DefaultInvocation implements Invocation
063 {
064 // SECTION-START[DefaultInvocation]
065
066 /** Constant for the context key of the {@code Object} of this invocation. */
067 public static final String OBJECT_KEY = Invocation.class.getName() + ".object";
068
069 /** Constant for the context key of the {@code Method} of this invocation. */
070 public static final String METHOD_KEY = Invocation.class.getName() + ".method";
071
072 /** Constant for the context key of the {@code Object[]} arguments of this invocation. */
073 public static final String ARGUMENTS_KEY = Invocation.class.getName() + ".arguments";
074
075 /** Constant for the context key of the result {@code Object} of this invocation. */
076 public static final String RESULT_KEY = Invocation.class.getName() + ".result";
077
078 /** Constant for the context key of the {@code Instance} corresponding to the object of this invocation. */
079 public static final String INSTANCE_KEY = Invocation.class.getName() + ".instance";
080
081 /** The context of this invocation. */
082 private Map context;
083
084 /**
085 * Creates a new {@code DefaultInvocation} instance taking an invocation to initialize the instance with.
086 *
087 * @param invocation The invocation to initialize the instance with.
088 */
089 public DefaultInvocation( final Invocation invocation )
090 {
091 this.context = new HashMap( invocation.getContext() );
092 }
093
094 public Map getContext()
095 {
096 if ( this.context == null )
097 {
098 this.context = new HashMap();
099 }
100
101 return this.context;
102 }
103
104 public Object getObject()
105 {
106 return this.getContext().get( OBJECT_KEY );
107 }
108
109 public Method getMethod()
110 {
111 return (Method) this.getContext().get( METHOD_KEY );
112 }
113
114 public Object[] getArguments()
115 {
116 return (Object[]) this.getContext().get( ARGUMENTS_KEY );
117 }
118
119 public Object getResult()
120 {
121 return this.getContext().get( RESULT_KEY );
122 }
123
124 public void setResult( final Object value )
125 {
126 if ( value == null )
127 {
128 this.getContext().remove( RESULT_KEY );
129 }
130 else
131 {
132 this.getContext().put( RESULT_KEY, value );
133 }
134 }
135
136 /**
137 * Gets the instance of the object of this invocation from the context of this invocation.
138 *
139 * @return The instance of the object of this invocation from the context of this invocation or {@code null}.
140 *
141 * @see #INSTANCE_KEY
142 */
143 public Instance getInstance()
144 {
145 return (Instance) this.getContext().get( INSTANCE_KEY );
146 }
147
148 // SECTION-END
149 // SECTION-START[Constructors]
150 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
151
152 /** Creates a new {@code DefaultInvocation} instance. */
153 @javax.annotation.Generated( value = "org.jomc.tools.JavaSources",
154 comments = "See http://jomc.sourceforge.net/jomc/1.0-alpha-8/jomc-tools" )
155 public DefaultInvocation()
156 {
157 // SECTION-START[Default Constructor]
158 super();
159 // SECTION-END
160 }
161 // </editor-fold>
162 // SECTION-END
163 // SECTION-START[Dependencies]
164 // SECTION-END
165 // SECTION-START[Properties]
166 // SECTION-END
167 // SECTION-START[Messages]
168 // SECTION-END
169 }