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 java.io.Serializable; 020 021import org.springframework.aop.aspectj.SingletonAspectInstanceFactory; 022import org.springframework.core.Ordered; 023import org.springframework.core.annotation.OrderUtils; 024 025/** 026 * Implementation of {@link MetadataAwareAspectInstanceFactory} that is backed 027 * by a specified singleton object, returning the same instance for every 028 * {@link #getAspectInstance()} call. 029 * 030 * @author Rod Johnson 031 * @author Juergen Hoeller 032 * @since 2.0 033 * @see SimpleMetadataAwareAspectInstanceFactory 034 */ 035@SuppressWarnings("serial") 036public class SingletonMetadataAwareAspectInstanceFactory extends SingletonAspectInstanceFactory 037 implements MetadataAwareAspectInstanceFactory, Serializable { 038 039 private final AspectMetadata metadata; 040 041 042 /** 043 * Create a new SingletonMetadataAwareAspectInstanceFactory for the given aspect. 044 * @param aspectInstance the singleton aspect instance 045 * @param aspectName the name of the aspect 046 */ 047 public SingletonMetadataAwareAspectInstanceFactory(Object aspectInstance, String aspectName) { 048 super(aspectInstance); 049 this.metadata = new AspectMetadata(aspectInstance.getClass(), aspectName); 050 } 051 052 053 @Override 054 public final AspectMetadata getAspectMetadata() { 055 return this.metadata; 056 } 057 058 @Override 059 public Object getAspectCreationMutex() { 060 return this; 061 } 062 063 @Override 064 protected int getOrderForAspectClass(Class<?> aspectClass) { 065 return OrderUtils.getOrder(aspectClass, Ordered.LOWEST_PRECEDENCE); 066 } 067 068}