001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.aopalliance.intercept;
018
019/**
020 * Intercepts the construction of a new object.
021 *
022 * <p>The user should implement the {@link
023 * #construct(ConstructorInvocation)} method to modify the original
024 * behavior. E.g. the following class implements a singleton
025 * interceptor (allows only one unique instance for the intercepted
026 * class):
027 *
028 * <pre class=code>
029 * class DebuggingInterceptor implements ConstructorInterceptor {
030 *   Object instance=null;
031 *
032 *   Object construct(ConstructorInvocation i) throws Throwable {
033 *     if(instance==null) {
034 *       return instance=i.proceed();
035 *     } else {
036 *       throw new Exception("singleton does not allow multiple instance");
037 *     }
038 *   }
039 * }
040 * </pre>
041 *
042 * @author Rod Johnson
043 */
044public interface ConstructorInterceptor extends Interceptor  {
045
046        /**
047         * Implement this method to perform extra treatments before and
048         * after the construction of a new object. Polite implementations
049         * would certainly like to invoke {@link Joinpoint#proceed()}.
050         * @param invocation the construction joinpoint
051         * @return the newly created object, which is also the result of
052         * the call to {@link Joinpoint#proceed()}; might be replaced by
053         * the interceptor
054         * @throws Throwable if the interceptors or the target object
055         * throws an exception
056         */
057        Object construct(ConstructorInvocation invocation) throws Throwable;
058
059}