View Javadoc

1   // SECTION-START[License Header]
2   // <editor-fold defaultstate="collapsed" desc=" Generated License ">
3   /*
4    *   Java Object Management and Configuration
5    *   Copyright (C) Christian Schulte, 2005-206
6    *   All rights reserved.
7    *
8    *   Redistribution and use in source and binary forms, with or without
9    *   modification, are permitted provided that the following conditions
10   *   are met:
11   *
12   *     o Redistributions of source code must retain the above copyright
13   *       notice, this list of conditions and the following disclaimer.
14   *
15   *     o Redistributions in binary form must reproduce the above copyright
16   *       notice, this list of conditions and the following disclaimer in
17   *       the documentation and/or other materials provided with the
18   *       distribution.
19   *
20   *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21   *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22   *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23   *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
24   *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25   *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26   *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27   *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29   *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   *
31   *   $JOMC: TestInvoker.java 4459 2012-03-27 23:55:31Z schulte2005 $
32   *
33   */
34  // </editor-fold>
35  // SECTION-END
36  package org.jomc.ri.test.support;
37  
38  import java.util.Arrays;
39  import java.util.Iterator;
40  import org.jomc.model.Instance;
41  import org.jomc.ri.DefaultInvocation;
42  import org.jomc.ri.DefaultInvoker;
43  import org.jomc.spi.Invocation;
44  
45  // SECTION-START[Documentation]
46  // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
47  /**
48   * Test {@code Invoker} implementation.
49   *
50   * <dl>
51   *   <dt><b>Identifier:</b></dt><dd>JOMC :: RI :: Tests :: Test Invoker</dd>
52   *   <dt><b>Name:</b></dt><dd>JOMC :: RI :: Tests :: Test Invoker</dd>
53   *   <dt><b>Specifications:</b></dt>
54   *     <dd>org.jomc.spi.Invoker</dd>
55   *   <dt><b>Abstract:</b></dt><dd>No</dd>
56   *   <dt><b>Final:</b></dt><dd>No</dd>
57   *   <dt><b>Stateless:</b></dt><dd>No</dd>
58   * </dl>
59   *
60   * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
61   * @version 1.2.2
62   */
63  // </editor-fold>
64  // SECTION-END
65  // SECTION-START[Annotations]
66  // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
67  @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
68  // </editor-fold>
69  // SECTION-END
70  public class TestInvoker extends DefaultInvoker
71  {
72      // SECTION-START[Invoker]
73      // SECTION-END
74      // SECTION-START[TestInvoker]
75  
76      @Override
77      public Invocation postInvoke( final Invocation invocation )
78      {
79          final StringBuilder b = new StringBuilder();
80          b.append( invocation.getObject().toString() );
81  
82          if ( invocation.getContext().get( DefaultInvocation.INSTANCE_KEY ) != null )
83          {
84              b.append( "[" ).append( ( (Instance) invocation.getContext().get( DefaultInvocation.INSTANCE_KEY ) ).
85                  getIdentifier() ).append( "]: " );
86  
87          }
88  
89          b.append( invocation.getMethod().getName() ).append( "( " );
90  
91          if ( invocation.getArguments() != null )
92          {
93              for ( Iterator it = Arrays.asList( invocation.getArguments() ).iterator(); it.hasNext(); )
94              {
95                  b.append( it.next() );
96                  if ( it.hasNext() )
97                  {
98                      b.append( ", " );
99                  }
100             }
101         }
102 
103         b.append( " ): " ).append( invocation.getResult() );
104         System.out.println( b.toString() );
105         return invocation;
106     }
107 
108     // SECTION-END
109     // SECTION-START[Constructors]
110     // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
111     /** Creates a new {@code TestInvoker} instance. */
112     @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
113     public TestInvoker()
114     {
115         // SECTION-START[Default Constructor]
116         super();
117         // SECTION-END
118     }
119     // </editor-fold>
120     // SECTION-END
121     // SECTION-START[Dependencies]
122     // SECTION-END
123     // SECTION-START[Properties]
124     // SECTION-END
125     // SECTION-START[Messages]
126     // SECTION-END
127 }