1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.aop.framework;
  17. /**
  18. * Simple implementation of AopProxyFactory
  19. * @author Rod Johnson
  20. * @version $Id: DefaultAopProxyFactory.java,v 1.2 2004/03/18 02:46:05 trisberg Exp $
  21. */
  22. public class DefaultAopProxyFactory implements AopProxyFactory {
  23. /**
  24. * @see org.springframework.aop.framework.AopProxyFactory#createAopProxy(org.springframework.aop.framework.AdvisedSupport)
  25. */
  26. public AopProxy createAopProxy(AdvisedSupport advisedSupport) throws AopConfigException {
  27. boolean useCglib = advisedSupport.getOptimize() || advisedSupport.getProxyTargetClass() || advisedSupport.getProxiedInterfaces().length == 0;
  28. if (useCglib) {
  29. return CglibProxyFactory.createCglibProxy(advisedSupport);
  30. }
  31. else {
  32. // Depends on whether we have expose proxy or frozen or static ts
  33. return new JdkDynamicAopProxy(advisedSupport);
  34. }
  35. }
  36. /**
  37. * Inner class to just introduce a CGLIB dependency
  38. * when actually creating a CGLIB proxy.
  39. */
  40. private static class CglibProxyFactory {
  41. private static AopProxy createCglibProxy(AdvisedSupport advisedSupport) {
  42. return new Cglib2AopProxy(advisedSupport);
  43. }
  44. }
  45. }