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 <cs@schulte.it>, 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 5061 2015-05-31 13:20:40Z 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.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" ) 66 // </editor-fold> 67 // SECTION-END 68 public class DefaultInvocation implements Invocation 69 { 70 // SECTION-START[DefaultInvocation] 71 72 /** 73 * Constant for the context key of the {@code Object} of this invocation. 74 */ 75 public static final String OBJECT_KEY = "org.jomc.spi.Invocation.object"; 76 77 /** 78 * Constant for the context key of the {@code Method} of this invocation. 79 */ 80 public static final String METHOD_KEY = "org.jomc.spi.Invocation.method"; 81 82 /** 83 * Constant for the context key of the {@code Object[]} arguments of this invocation. 84 */ 85 public static final String ARGUMENTS_KEY = "org.jomc.spi.Invocation.arguments"; 86 87 /** 88 * Constant for the context key of the result {@code Object} of this invocation. 89 */ 90 public static final String RESULT_KEY = "org.jomc.spi.Invocation.result"; 91 92 /** 93 * Constant for the context key of the {@code Instance} corresponding to the object of this invocation. 94 */ 95 public static final String INSTANCE_KEY = "org.jomc.spi.Invocation.instance"; 96 97 /** 98 * Constant for the context key of the {@code Modules} corresponding to the object of this invocation. 99 */ 100 public static final String MODULES_KEY = "org.jomc.spi.Invocation.modules"; 101 102 /** 103 * Constant for the context key of the {@code ClassLoader} corresponding to the modules of this invocation. 104 */ 105 public static final String CLASSLOADER_KEY = "org.jomc.spi.Invocation.classLoader"; 106 107 /** 108 * The context of this invocation. 109 */ 110 private Map context; 111 112 /** 113 * Creates a new {@code DefaultInvocation} instance taking an invocation to initialize the instance with. 114 * 115 * @param invocation The invocation to initialize the instance with. 116 */ 117 public DefaultInvocation( final Invocation invocation ) 118 { 119 this.context = new HashMap( invocation.getContext() ); 120 } 121 122 public Map getContext() 123 { 124 if ( this.context == null ) 125 { 126 this.context = new HashMap(); 127 } 128 129 return this.context; 130 } 131 132 public Object getObject() 133 { 134 return this.getContext().get( OBJECT_KEY ); 135 } 136 137 public Method getMethod() 138 { 139 return (Method) this.getContext().get( METHOD_KEY ); 140 } 141 142 public Object[] getArguments() 143 { 144 return (Object[]) this.getContext().get( ARGUMENTS_KEY ); 145 } 146 147 public Object getResult() 148 { 149 return this.getContext().get( RESULT_KEY ); 150 } 151 152 public void setResult( final Object value ) 153 { 154 if ( value == null ) 155 { 156 this.getContext().remove( RESULT_KEY ); 157 } 158 else 159 { 160 this.getContext().put( RESULT_KEY, value ); 161 } 162 } 163 164 /** 165 * Gets the instance of the object of this invocation from the context of this invocation. 166 * 167 * @return The instance of the object of this invocation from the context of this invocation or {@code null}. 168 * 169 * @see #INSTANCE_KEY 170 */ 171 public Instance getInstance() 172 { 173 return (Instance) this.getContext().get( INSTANCE_KEY ); 174 } 175 176 /** 177 * Gets the modules corresponding to the object of this invocation from the context of this invocation. 178 * 179 * @return The modules corresponding to the object of this invocation from the context of this invocation or 180 * {@code null}. 181 * 182 * @see #MODULES_KEY 183 */ 184 public Modules getModules() 185 { 186 return (Modules) this.getContext().get( MODULES_KEY ); 187 } 188 189 /** 190 * Gets the class loader corresponding to the modules of this invocation from the context of this invocation. 191 * 192 * @return The class loader corresponding to the modules of this invocation from the context of this invocation or 193 * {@code null}. 194 * 195 * @see #CLASSLOADER_KEY 196 */ 197 public ClassLoader getClassLoader() 198 { 199 return (ClassLoader) this.getContext().get( CLASSLOADER_KEY ); 200 } 201 202 // SECTION-END 203 // SECTION-START[Constructors] 204 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> 205 /** Creates a new {@code DefaultInvocation} instance. */ 206 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" ) 207 public DefaultInvocation() 208 { 209 // SECTION-START[Default Constructor] 210 super(); 211 // SECTION-END 212 } 213 // </editor-fold> 214 // SECTION-END 215 // SECTION-START[Dependencies] 216 // SECTION-END 217 // SECTION-START[Properties] 218 // SECTION-END 219 // SECTION-START[Messages] 220 // SECTION-END 221 222 }