View Javadoc
1   package org.andromda.cartridges.ejb3.metafacades;
2   
3   import java.text.MessageFormat;
4   import java.util.Collection;
5   import java.util.LinkedHashSet;
6   import org.andromda.cartridges.ejb3.EJB3Profile;
7   import org.andromda.metafacades.uml.DependencyFacade;
8   import org.andromda.metafacades.uml.ModelElementFacade;
9   import org.apache.commons.collections.Closure;
10  import org.apache.commons.collections.CollectionUtils;
11  import org.apache.commons.collections.Predicate;
12  import org.apache.commons.collections.Transformer;
13  import org.apache.commons.lang.BooleanUtils;
14  import org.apache.commons.lang.StringUtils;
15  
16  /**
17   * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3InterceptorFacade.
18   *
19   * @see EJB3InterceptorFacade
20   */
21  public class EJB3InterceptorFacadeLogicImpl
22      extends EJB3InterceptorFacadeLogic
23  {
24      private static final long serialVersionUID = 34L;
25      /**
26       * The property which stores the pattern defining the interceptor class name.
27       */
28      private static final String INTERCEPTOR_NAME_PATTERN = "interceptorNamePattern";
29  
30      /**
31       * @param metaObject
32       * @param context
33       */
34      public EJB3InterceptorFacadeLogicImpl(final Object metaObject, final String context)
35      {
36          super(metaObject, context);
37      }
38  
39      /**
40       * @see EJB3InterceptorFacade#getInterceptorName()
41       */
42      @Override
43      protected String handleGetInterceptorName()
44      {
45          String interceptorNamePattern = (String)this.getConfiguredProperty(INTERCEPTOR_NAME_PATTERN);
46  
47          return MessageFormat.format(
48                  interceptorNamePattern,
49                  StringUtils.trimToEmpty(this.getName()));
50      }
51  
52      /**
53       * @see EJB3InterceptorFacade#getFullyQualifiedInterceptorName()
54       */
55      @Override
56      protected String handleGetFullyQualifiedInterceptorName()
57      {
58          return EJB3MetafacadeUtils.getFullyQualifiedName(
59                  this.getPackageName(),
60                  this.getInterceptorName(),
61                  null);
62      }
63  
64      /**
65       * @see EJB3InterceptorFacadeLogic#handleGetInterceptorReferences()
66       */
67      @Override
68      protected Collection<DependencyFacade> handleGetInterceptorReferences()
69      {
70          Collection<DependencyFacade> references = this.getSourceDependencies();
71          CollectionUtils.filter(
72              references,
73              new Predicate()
74              {
75                  public boolean evaluate(final Object object)
76                  {
77                      DependencyFacade dependency = (DependencyFacade)object;
78                      ModelElementFacade targetElement = dependency.getTargetElement();
79                      return targetElement != null && targetElement.hasStereotype(EJB3Profile.STEREOTYPE_INTERCEPTOR);
80                  }
81              });
82          CollectionUtils.transform(
83              references,
84              new Transformer()
85              {
86                  public Object transform(final Object object)
87                  {
88                      return ((DependencyFacade)object).getTargetElement();
89                  }
90              });
91          final Collection<DependencyFacade> interceptors = new LinkedHashSet(references);
92          CollectionUtils.forAllDo(
93              references,
94              new Closure()
95              {
96                  public void execute(final Object object)
97                  {
98                      if (object instanceof EJB3InterceptorFacade)
99                      {
100                         interceptors.addAll(((EJB3InterceptorFacade)object).getInterceptorReferences());
101                     }
102                 }
103             });
104         return interceptors;
105     }
106 
107     /**
108      * @see EJB3InterceptorFacadeLogic#handleIsDefaultInterceptor()
109      */
110     @Override
111     protected boolean handleIsDefaultInterceptor()
112     {
113         boolean isDefaultInterceptor = false;
114         String isDefaultInterceptorStr =
115             String.valueOf(this.findTaggedValue(EJB3Profile.TAGGEDVALUE_DEFAULT_INTERCEPTOR));
116         if (StringUtils.isNotBlank(isDefaultInterceptorStr))
117         {
118             isDefaultInterceptor = BooleanUtils.toBoolean(isDefaultInterceptorStr);
119         }
120         return isDefaultInterceptor;
121     }
122 }