View Javadoc

1   /*
2    Copyright 2007 Ramon Servadei
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 fulmine.distribution.events;
17  
18  import fulmine.context.IFrameworkContext;
19  import fulmine.distribution.connection.IConnection;
20  import fulmine.distribution.connection.IConnectionBroker;
21  import fulmine.distribution.connection.IConnectionDiscoverer;
22  import fulmine.distribution.connection.IConnectionParameters;
23  import fulmine.event.IEventManager;
24  import fulmine.event.system.AbstractSystemEvent;
25  
26  /**
27   * Raised by an {@link IConnectionDiscoverer} implementation and encapsulates
28   * the connection details to a remote {@link IFrameworkContext}.
29   * 
30   * @author Ramon Servadei
31   */
32  public final class ContextDiscoveredEvent extends AbstractSystemEvent
33  {
34      /**
35       * The parameter encapsulating the details required to make the connection
36       * to the remote {@link IFrameworkContext}.
37       */
38      private final IConnectionParameters connectionParameters;
39  
40      /**
41       * Standard constructor with the details of how to connect to a discovered
42       * remote {@link IFrameworkContext}
43       * 
44       * @param context
45       *            the context for event operations
46       * @param connectionParameters
47       *            the details required to make the connection to the remote
48       *            context
49       */
50      public ContextDiscoveredEvent(IEventManager context,
51          IConnectionParameters connectionParameters)
52      {
53          super(context);
54          this.connectionParameters = connectionParameters;
55      }
56  
57      /**
58       * Get the details required to make the connection to the remote
59       * {@link IFrameworkContext}
60       * 
61       * @param <T>
62       *            a type of {@link IConnectionParameters}
63       * @return the parameters that can be used to create the {@link IConnection}
64       *         to the remote context
65       * @see IConnectionBroker#connect(IConnectionParameters)
66       */
67      @SuppressWarnings("unchecked")
68      public <T extends IConnectionParameters> T getConnectionParameters()
69      {
70          return (T) connectionParameters;
71      }
72  
73      @Override
74      public String toDetailedString()
75      {
76          return toString();
77      }
78  
79      @Override
80      public String toIdentityString()
81      {
82          return toString();
83      }
84  
85      @Override
86      protected String getAdditionalToString()
87      {
88          return "connectionParameters=" + getConnectionParameters();
89      }
90  }