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 ServiceBeanMatcher implements BeanMatcher {
021    
022            public ServiceBeanMatcher() {
023                    this(false);
024            }
025    
026            public ServiceBeanMatcher(boolean counterMatcher) {
027                    _counterMatcher = counterMatcher;
028            }
029    
030            @Override
031            public boolean match(Class<?> beanClass, String beanName) {
032                    if (_counterMatcher) {
033                            return beanName.equals(_COUNTER_SERVICE_BEAN_NAME);
034                    }
035                    else if (!beanName.equals(_COUNTER_SERVICE_BEAN_NAME) &&
036                                     beanName.endsWith(_SERVICE_SUFFIX)) {
037    
038                            return true;
039                    }
040    
041                    return false;
042            }
043    
044            private static final String _COUNTER_SERVICE_BEAN_NAME =
045                    "com.liferay.counter.service.CounterLocalService";
046    
047            private static final String _SERVICE_SUFFIX = "Service";
048    
049            private boolean _counterMatcher;
050    
051    }