1/* 2 * Copyright 2002,2003 The Apache Software Foundation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package org.mockito.cglib.proxy; 18 19/** 20 * All enhanced instances returned by the {@link Enhancer} class implement this interface. 21 * Using this interface for new instances is faster than going through the <code>Enhancer</code> 22 * interface or using reflection. In addition, to intercept methods called during 23 * object construction you <b>must</b> use these methods instead of reflection. 24 * @author Juozas Baliuka <a href="mailto:baliuka@mwm.lt">baliuka@mwm.lt</a> 25 * @version $Id: Factory.java,v 1.13 2004/06/24 21:15:20 herbyderby Exp $ 26 */ 27public interface Factory { 28 /** 29 * Creates new instance of the same type, using the no-arg constructor. 30 * The class of this object must have been created using a single Callback type. 31 * If multiple callbacks are required an exception will be thrown. 32 * @param callback the new interceptor to use 33 * @return new instance of the same type 34 */ 35 Object newInstance(Callback callback); 36 37 /** 38 * Creates new instance of the same type, using the no-arg constructor. 39 * @param callbacks the new callbacks(s) to use 40 * @return new instance of the same type 41 */ 42 Object newInstance(Callback[] callbacks); 43 44 /** 45 * Creates a new instance of the same type, using the constructor 46 * matching the given signature. 47 * @param types the constructor argument types 48 * @param args the constructor arguments 49 * @param callbacks the new interceptor(s) to use 50 * @return new instance of the same type 51 */ 52 Object newInstance(Class[] types, Object[] args, Callback[] callbacks); 53 54 /** 55 * Return the <code>Callback</code> implementation at the specified index. 56 * @param index the callback index 57 * @return the callback implementation 58 */ 59 Callback getCallback(int index); 60 61 /** 62 * Set the callback for this object for the given type. 63 * @param index the callback index to replace 64 * @param callback the new callback 65 */ 66 void setCallback(int index, Callback callback); 67 68 /** 69 * Replace all of the callbacks for this object at once. 70 * @param callbacks the new callbacks(s) to use 71 */ 72 void setCallbacks(Callback[] callbacks); 73 74 /** 75 * Get the current set of callbacks for ths object. 76 * @return a new array instance 77 */ 78 Callback[] getCallbacks(); 79} 80