001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.spring.aop;
016    
017    /**
018     * @author Shuyang Zhou
019     */
020    public class ChainableMethodAdviceInjector {
021    
022            public void afterPropertiesSet() {
023                    if (!isInjectCondition()) {
024                            return;
025                    }
026    
027                    ChainableMethodAdvice newChainableMethodAdvice =
028                            getNewChainableMethodAdvice();
029    
030                    if (newChainableMethodAdvice == null) {
031                            throw new IllegalArgumentException(
032                                    "New Chainable method advice is null");
033                    }
034    
035                    ChainableMethodAdvice parentChainableMethodAdvice =
036                            getParentChainableMethodAdvice();
037    
038                    if (parentChainableMethodAdvice == null) {
039                            throw new IllegalArgumentException(
040                                    "Parent chainable method advice is null");
041                    }
042    
043                    newChainableMethodAdvice.nextMethodInterceptor =
044                            parentChainableMethodAdvice.nextMethodInterceptor;
045                    parentChainableMethodAdvice.nextMethodInterceptor =
046                            newChainableMethodAdvice;
047            }
048    
049            public void setInjectCondition(boolean injectCondition) {
050                    _injectCondition = injectCondition;
051            }
052    
053            public void setNewChainableMethodAdvice(
054                    ChainableMethodAdvice newChainableMethodAdvice) {
055    
056                    _newChainableMethodAdvice = newChainableMethodAdvice;
057            }
058    
059            public void setParentChainableMethodAdvice(
060                    ChainableMethodAdvice parentChainableMethodAdvice) {
061    
062                    _parentChainableMethodAdvice = parentChainableMethodAdvice;
063            }
064    
065            protected ChainableMethodAdvice getNewChainableMethodAdvice() {
066                    return _newChainableMethodAdvice;
067            }
068    
069            protected ChainableMethodAdvice getParentChainableMethodAdvice() {
070                    return _parentChainableMethodAdvice;
071            }
072    
073            protected boolean isInjectCondition() {
074                    return _injectCondition;
075            }
076    
077            private boolean _injectCondition;
078            private ChainableMethodAdvice _newChainableMethodAdvice;
079            private ChainableMethodAdvice _parentChainableMethodAdvice;
080    
081    }