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.springframework.aop.aspectj.annotation;
018
019import org.springframework.aop.aspectj.SimpleAspectInstanceFactory;
020import org.springframework.core.Ordered;
021import org.springframework.core.annotation.OrderUtils;
022
023/**
024 * Implementation of {@link MetadataAwareAspectInstanceFactory} that
025 * creates a new instance of the specified aspect class for every
026 * {@link #getAspectInstance()} call.
027 *
028 * @author Juergen Hoeller
029 * @since 2.0.4
030 */
031public class SimpleMetadataAwareAspectInstanceFactory extends SimpleAspectInstanceFactory
032                implements MetadataAwareAspectInstanceFactory {
033
034        private final AspectMetadata metadata;
035
036
037        /**
038         * Create a new SimpleMetadataAwareAspectInstanceFactory for the given aspect class.
039         * @param aspectClass the aspect class
040         * @param aspectName the aspect name
041         */
042        public SimpleMetadataAwareAspectInstanceFactory(Class<?> aspectClass, String aspectName) {
043                super(aspectClass);
044                this.metadata = new AspectMetadata(aspectClass, aspectName);
045        }
046
047
048        @Override
049        public final AspectMetadata getAspectMetadata() {
050                return this.metadata;
051        }
052
053        @Override
054        public Object getAspectCreationMutex() {
055                return this;
056        }
057
058        @Override
059        protected int getOrderForAspectClass(Class<?> aspectClass) {
060                return OrderUtils.getOrder(aspectClass, Ordered.LOWEST_PRECEDENCE);
061        }
062
063}