com.vaadin.terminal
Class AbstractClientConnector

java.lang.Object
  extended by com.vaadin.terminal.AbstractClientConnector
All Implemented Interfaces:
Connector, ClientConnector, RpcTarget, Serializable
Direct Known Subclasses:
AbstractComponent, AbstractExtension

public abstract class AbstractClientConnector
extends Object
implements ClientConnector

An abstract base class for ClientConnector implementations. This class provides all the basic functionality required for connectors.

Since:
7.0.0
Version:
7.0.0.alpha3
Author:
Vaadin Ltd
See Also:
Serialized Form

Constructor Summary
AbstractClientConnector()
           
 
Method Summary
protected  void addExtension(Extension extension)
          Add an extension to this connector.
protected  void addMethodInvocationToQueue(String interfaceName, Method method, Object[] parameters)
          For internal use: adds a method invocation to the pending RPC call queue.
 void attach()
          Notifies the connector that it is connected to an application.
protected  SharedState createState()
          Creates the shared state bean to be used in server to client communication.
 void detach()
          Notifies the component that it is detached from the application.
static Iterable<ClientConnector> getAllChildrenIterable(ClientConnector connector)
          Get an Iterable for iterating over all child connectors, including both extensions and child components.
protected  Application getApplication()
          Finds the Application to which this connector belongs.
 String getConnectorId()
          Returns the id for this connector.
 Collection<Extension> getExtensions()
          Get a read-only collection of all extensions attached to this connector.
 ClientConnector getParent()
          Gets the parent connector of this connector, or null if the connector is not attached to any parent.
 Root getRoot()
          Finds a Root ancestor of this connector.
 RpcManager getRpcManager(Class<?> rpcInterface)
          Returns the RPC manager instance to use when receiving calls for an RPC interface.
<T extends ClientRpc>
T
getRpcProxy(Class<T> rpcInterface)
          Returns an RPC proxy for a given server to client RPC interface for this component.
 SharedState getState()
          Gets the current shared state of the connector.
 Class<? extends SharedState> getStateType()
          Returns the type of the shared state for this connector
 boolean isConnectorEnabled()
          Checks if the communicator is enabled.
protected
<T extends ServerRpc>
void
registerRpc(T implementation)
          Registers an RPC interface implementation for this component.
protected
<T> void
registerRpc(T implementation, Class<T> rpcInterfaceType)
          Registers an RPC interface implementation for this component.
 void removeExtension(Extension extension)
          Remove an extension from this connector.
 void requestRepaint()
          Requests that the connector should be repainted as soon as possible.
 void requestRepaintAll()
          Causes a repaint of this connector, and all connectors below it.
 List<ClientMethodInvocation> retrievePendingRpcCalls()
          Returns the list of pending server to client RPC calls and clears the list.
 void setParent(ClientConnector parent)
          Sets the parent connector of the connector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractClientConnector

public AbstractClientConnector()
Method Detail

requestRepaint

public void requestRepaint()
Description copied from interface: ClientConnector
Requests that the connector should be repainted as soon as possible.

Specified by:
requestRepaint in interface ClientConnector

registerRpc

protected <T> void registerRpc(T implementation,
                               Class<T> rpcInterfaceType)
Registers an RPC interface implementation for this component. A component can listen to multiple RPC interfaces, and subclasses can register additional implementations.

Parameters:
implementation - RPC interface implementation
rpcInterfaceType - RPC interface class for which the implementation should be registered
Since:
7.0

registerRpc

protected <T extends ServerRpc> void registerRpc(T implementation)
Registers an RPC interface implementation for this component. A component can listen to multiple RPC interfaces, and subclasses can register additional implementations.

Parameters:
implementation - RPC interface implementation. Also used to deduce the type.
Since:
7.0

getState

public SharedState getState()
Description copied from interface: Connector
Gets the current shared state of the connector.

Specified by:
getState in interface Connector
Returns:
state The shared state object. Can be any sub type of SharedState. Never null.

createState

protected SharedState createState()
Creates the shared state bean to be used in server to client communication.

By default a state object of the defined return type of getState() is created. Subclasses can override this method and return a new instance of the correct state class but this should rarely be necessary.

No configuration of the values of the state should be performed in createState().

Returns:
new shared state object
Since:
7.0

getStateType

public Class<? extends SharedState> getStateType()
Description copied from interface: ClientConnector
Returns the type of the shared state for this connector

Specified by:
getStateType in interface ClientConnector
Returns:
The type of the state. Must never return null.

getRpcProxy

public <T extends ClientRpc> T getRpcProxy(Class<T> rpcInterface)
Returns an RPC proxy for a given server to client RPC interface for this component. TODO more javadoc, subclasses, ...

Parameters:
rpcInterface - RPC interface type
Since:
7.0

addMethodInvocationToQueue

protected void addMethodInvocationToQueue(String interfaceName,
                                          Method method,
                                          Object[] parameters)
For internal use: adds a method invocation to the pending RPC call queue.

Parameters:
interfaceName - RPC interface name
method - RPC method
parameters - RPC all parameters
Since:
7.0

getRpcManager

public RpcManager getRpcManager(Class<?> rpcInterface)
Description copied from interface: RpcTarget
Returns the RPC manager instance to use when receiving calls for an RPC interface.

Specified by:
getRpcManager in interface RpcTarget
Parameters:
rpcInterface - RPC interface for which a call was made
Returns:
RPC Manager handling calls for the interface
Since:
7.0
See Also:
RpcTarget.getRpcManager(Class)

retrievePendingRpcCalls

public List<ClientMethodInvocation> retrievePendingRpcCalls()
Description copied from interface: ClientConnector
Returns the list of pending server to client RPC calls and clears the list.

Specified by:
retrievePendingRpcCalls in interface ClientConnector
Returns:
an unmodifiable ordered list of pending server to client method calls (not null)

getConnectorId

public String getConnectorId()
Description copied from interface: Connector
Returns the id for this connector. This is set by the framework and does not change during the lifetime of a connector.

Specified by:
getConnectorId in interface Connector
Returns:
The id for the connector.

getApplication

protected Application getApplication()
Finds the Application to which this connector belongs. If the connector has not been attached, null is returned.

Returns:
The connector's application, or null if not attached

getRoot

public Root getRoot()
Finds a Root ancestor of this connector. null is returned if no Root ancestor is found (typically because the connector is not attached to a proper hierarchy).

Specified by:
getRoot in interface ClientConnector
Returns:
the Root ancestor of this connector, or null if none is found.

requestRepaintAll

public void requestRepaintAll()
Description copied from interface: ClientConnector
Causes a repaint of this connector, and all connectors below it. This should only be used in special cases, e.g when the state of a descendant depends on the state of an ancestor.

Specified by:
requestRepaintAll in interface ClientConnector

getAllChildrenIterable

public static Iterable<ClientConnector> getAllChildrenIterable(ClientConnector connector)
Get an Iterable for iterating over all child connectors, including both extensions and child components.

Parameters:
connector - the connector to get children for
Returns:
an Iterable giving all child connectors.

getExtensions

public Collection<Extension> getExtensions()
Description copied from interface: ClientConnector
Get a read-only collection of all extensions attached to this connector.

Specified by:
getExtensions in interface ClientConnector
Returns:
a collection of extensions

addExtension

protected void addExtension(Extension extension)
Add an extension to this connector. This method is protected to allow extensions to select which targets they can extend.

Parameters:
extension - the extension to add

removeExtension

public void removeExtension(Extension extension)
Description copied from interface: ClientConnector
Remove an extension from this connector.

Specified by:
removeExtension in interface ClientConnector
Parameters:
extension - the extension to remove.

setParent

public void setParent(ClientConnector parent)
Description copied from interface: ClientConnector
Sets the parent connector of the connector.

This method automatically calls ClientConnector.attach() if the connector becomes attached to the application, regardless of whether it was attached previously. Conversely, if the parent is null and the connector is attached to the application, ClientConnector.detach() is called for the connector.

This method is rarely called directly. One of the ComponentContainer.addComponent(Component) or addExtension(Extension) methods are normally used for adding connectors to a parent and they will call this method implicitly.

It is not possible to change the parent without first setting the parent to null.

Specified by:
setParent in interface ClientConnector
Parameters:
parent - the parent connector

getParent

public ClientConnector getParent()
Description copied from interface: Connector
Gets the parent connector of this connector, or null if the connector is not attached to any parent.

Specified by:
getParent in interface Connector
Specified by:
getParent in interface ClientConnector
Returns:
the parent connector, or null if there is no parent.

attach

public void attach()
Description copied from interface: ClientConnector
Notifies the connector that it is connected to an application.

The caller of this method is ClientConnector.setParent(ClientConnector) if the parent is itself already attached to the application. If not, the parent will call the ClientConnector.attach() for all its children when it is attached to the application. This method is always called before the connector's data is sent to the client-side for the first time.

The attachment logic is implemented in AbstractClientConnector.

Specified by:
attach in interface ClientConnector

detach

public void detach()
Notifies the component that it is detached from the application.

The caller of this method is ClientConnector.setParent(ClientConnector) if the parent is in the application. When the parent is detached from the application it is its response to call ClientConnector.detach() for all the children and to detach itself from the terminal.

The getApplication() and getRoot() methods might return null after this method is called.

Specified by:
detach in interface ClientConnector

isConnectorEnabled

public boolean isConnectorEnabled()
Description copied from interface: ClientConnector
Checks if the communicator is enabled. An enabled communicator is allowed to receive messages from its counter-part.

Specified by:
isConnectorEnabled in interface ClientConnector
Returns:
true if the connector can receive messages, false otherwise


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.