SmartFrog 3.10.000

org.smartfrog.sfcore.utils
Class ComponentHelper

java.lang.Object
  extended by org.smartfrog.sfcore.utils.ComponentHelper

public class ComponentHelper
extends java.lang.Object

Contains methods for helping components; a factoring out of common functionality. Component helpers must be bound to Prim classes before use. created 18-May-2004 11:26:15


Constructor Summary
ComponentHelper(Prim owner)
          construct a component helper and bind to a prim class
 
Method Summary
 Reference completeNameOrNull()
          Returns the complete name for any component from the root of the application and does not throw any exception.
 Reference completeNameSafe()
          Returns the complete name for any component from the root of the application and does not throw any exception.
static Reference completeNameSafe(Prim owner)
          Returns the complete name for any component from the root of the application and does not throw any exception.
static Prim findAncestorImplementing(Prim node, java.lang.String interfaceName, int depth)
          find an ancestor of a given type
 Prim findAncestorImplementing(java.lang.String interfaceName, int depth)
          find an ancestor of the owner that implements this class.
 java.lang.String getCodebase()
          get the codebase of a component
 Log getLogger()
          get the relevant logger for this component.
 Prim getOwner()
          return the prim that this helper is bound to
static boolean implementsInterface(java.lang.Class clazz, java.lang.String interfaceName)
          recursive search for interface inheritance
 java.io.InputStream loadResource(java.lang.String resourcename)
          load a resource using the classpath of the component at question.
 java.lang.String loadResourceToString(java.lang.String resourcename, java.nio.charset.Charset encoding)
          Load a resource into a string
 void logIgnoredException(java.lang.Throwable thrown)
          ignore an exception by logging it at the fine level.
 void sfSelfDetachAndOrTerminate(java.lang.String terminationType, java.lang.String terminationMessage, Reference refId, java.lang.Throwable thrown)
          s Method that can be invoked in any PrimImpl to trigger the detach and/or termination of a component according to the values of the boolean attributes 'sfShouldDetach', 'sfShouldTerminate' and 'sfShouldTerminateQuietly' Example: new ComponentHelper(this).sfSelfDetachAndOrTerminate("normal","Copy ",this.sfCompleteNameSafe(),null);
 void targetForTermination()
          mark this task for termination by spawning a separate thread to do it.
 void targetForTermination(TerminationRecord record, boolean detach, boolean quietly)
          mark this task for termination by spawning a separate thread to do it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentHelper

public ComponentHelper(Prim owner)
construct a component helper and bind to a prim class

Parameters:
owner - the owner to which this helper should be bound
Method Detail

getOwner

public Prim getOwner()
return the prim that this helper is bound to

Returns:
Prim the owner this helper is bound to

getLogger

public Log getLogger()
get the relevant logger for this component. When logging against a remote class, this is probably the classname of the proxy.

Returns:
Log Logger for this component

logIgnoredException

public void logIgnoredException(java.lang.Throwable thrown)
ignore an exception by logging it at the fine level.

Parameters:
thrown - exception to be logged

completeNameOrNull

public Reference completeNameOrNull()
Returns the complete name for any component from the root of the application and does not throw any exception. If an exception is thrown it will return null

Returns:
reference of attribute names to this component or a null

completeNameSafe

public Reference completeNameSafe()
Returns the complete name for any component from the root of the application and does not throw any exception. If an exception is thrown it will return a new empty reference.

Returns:
reference of attribute names to this component or an empty reference

completeNameSafe

public static Reference completeNameSafe(Prim owner)
Returns the complete name for any component from the root of the application and does not throw any exception. If an exception is thrown it will return a new empty reference.

Parameters:
owner - component whose completename is to be returned
Returns:
reference of attribute names to this component or an empty reference

sfSelfDetachAndOrTerminate

public void sfSelfDetachAndOrTerminate(java.lang.String terminationType,
                                       java.lang.String terminationMessage,
                                       Reference refId,
                                       java.lang.Throwable thrown)
s Method that can be invoked in any PrimImpl to trigger the detach and/or termination of a component according to the values of the boolean attributes 'sfShouldDetach', 'sfShouldTerminate' and 'sfShouldTerminateQuietly' Example: new ComponentHelper(this).sfSelfDetachAndOrTerminate("normal","Copy ",this.sfCompleteNameSafe(),null);

Parameters:
terminationType - - termination type, system recognized types are "normal", "abnormal" and "externalReferenceDead".
terminationMessage - - description of termination
refId - Reference - id of terminating component
thrown - Thrown fault

targetForTermination

public void targetForTermination(TerminationRecord record,
                                 boolean detach,
                                 boolean quietly)
mark this task for termination by spawning a separate thread to do it. as Prim.sfTerminate(org.smartfrog.sfcore.prim.TerminationRecord) and Prim.sfStart() are synchronized, the thread blocks until sfStart has finished.

Parameters:
record - record to terminate with
detach - detach first?
quietly - terminate quietly?

targetForTermination

public void targetForTermination()
mark this task for termination by spawning a separate thread to do it. as Prim.sfTerminate(org.smartfrog.sfcore.prim.TerminationRecord) and Prim.sfStart() are synchronized, the thread blocks until sfStart has finished. Note that we detach before terminating; this stops our timely end propagating.


loadResource

public java.io.InputStream loadResource(java.lang.String resourcename)
                                 throws SmartFrogException,
                                        java.rmi.RemoteException
load a resource using the classpath of the component at question.

Parameters:
resourcename - name of resource on the classpath
Returns:
an input stream if the resource was found and loaded
Throws:
SmartFrogException - if the resource is not on the classpath
java.rmi.RemoteException - in case of Remote/network error

loadResourceToString

public java.lang.String loadResourceToString(java.lang.String resourcename,
                                             java.nio.charset.Charset encoding)
                                      throws SmartFrogException,
                                             java.rmi.RemoteException
Load a resource into a string

Parameters:
resourcename - name of resource on the classpath
encoding - encoding to be used
Returns:
String if the resource was found and loaded
Throws:
SmartFrogException - if the resource is not on the classpath
java.rmi.RemoteException - in case of Remote/network error

getCodebase

public java.lang.String getCodebase()
                             throws SmartFrogResolutionException,
                                    java.rmi.RemoteException
get the codebase of a component

Returns:
String codebase of a component
Throws:
SmartFrogResolutionException - if failed to resolve
java.rmi.RemoteException - in case of Remote/network error

findAncestorImplementing

public static Prim findAncestorImplementing(Prim node,
                                            java.lang.String interfaceName,
                                            int depth)
                                     throws java.rmi.RemoteException
find an ancestor of a given type

Parameters:
node - node to look for
interfaceName - full name of interface to look for
depth - 0 means dont look upwards, -1 means indefinite.
Returns:
a parent or null for no match
Throws:
java.rmi.RemoteException - in case of Remote/network error

findAncestorImplementing

public Prim findAncestorImplementing(java.lang.String interfaceName,
                                     int depth)
                              throws java.rmi.RemoteException
find an ancestor of the owner that implements this class.

Parameters:
interfaceName - full name of interface to look for
depth - 0 means dont look upwards, -1 means indefinite.
Returns:
a parent or null for no match
Throws:
java.rmi.RemoteException - in case of Remote/network error

implementsInterface

public static boolean implementsInterface(java.lang.Class clazz,
                                          java.lang.String interfaceName)
recursive search for interface inheritance

Parameters:
clazz - Class name
interfaceName - full name of interface to look for
Returns:
boolean true is the interface is found in the recursive search

SmartFrog CORE 3.10.000

(C) Copyright 1998-2006 Hewlett-Packard Development Company, LP