com.sun.jini.reggie
Class ServiceType

java.lang.Object
  extended by com.sun.jini.reggie.ServiceType
All Implemented Interfaces:
Serializable

 class ServiceType
extends Object
implements Serializable

A ServiceType is a descriptor for a class, packaged up for transmission between client-side proxies and the registrar server. Instances are never visible to clients, they are private to the communication between the proxies and the server.

This class only has a bare minimum of methods, to minimize the amount of code downloaded into clients.

Author:
Sun Microsystems, Inc.
See Also:
see ClassResolver (com.sun.jini.reggie.test.share.ClassResolver?)

Field Summary
private static ServiceType[] empty
           
protected  long hash
          Hash for the type
private  boolean integrity
          Flag set to true if this instance was unmarshalled from an integrity-protected stream, or false otherwise
protected  ServiceType[] interfaces
          Descriptor for the interfaces.
private  String name
          Class name.
protected  ServiceType replacement
          An instance containing only name, no supertype info.
private static long serialVersionUID
           
protected  ServiceType superclass
          Descriptor for the superclass.
 
Constructor Summary
  ServiceType(Class clazz, ServiceType superclass, ServiceType[] interfaces)
          Should only be called by ClassMapper
private ServiceType(ServiceType stype)
          Constructor used for creating replacement instances, containing only name.
 
Method Summary
private  void computeHash()
          Computes a SHA-1 digest from the hash of the superclass, if there is a superclass, followed by the name of this class, followed by the name and type for each field, if any, declared by this class and ordered alphabetically by field name.
 boolean equals(Object o)
          Returns true if the object passed in is an instance of Type with the same type hash.
 ServiceType[] getInterfaces()
          Return the interfaces.
 String getName()
          Returns the name of this type
 ServiceType getReplacement()
          Return the replacement, if any, containing only name and rep.
 ServiceType getSuperclass()
          Return the superclass descriptor
 int hashCode()
          Return a hashcode for this type.
 boolean isAssignableFrom(ServiceType cls)
          Returns true if this type is equal to type or if this type is equal to a superclass of type.
private  boolean isAssignableFrom(ServiceType[] ifaces)
          Test if this isAssignableFrom any of the given interface types.
 boolean isInterface()
           
private  void readObject(ObjectInputStream in)
          Samples integrity protection setting (if any) of the stream from which this instance is being deserialized.
private  void readObjectNoData()
          Throws InvalidObjectException, since data for this class is required.
 Class toClass(String codebase)
          Converts this descriptor to a Class instance, loading from codebase
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

empty

private static final ServiceType[] empty

name

private String name
Class name. If the class is generated by java.lang.reflect.Proxy, then the name is of the form ";iface1;iface2;...;ifaceN".


hash

protected long hash
Hash for the type


superclass

protected ServiceType superclass
Descriptor for the superclass.


interfaces

protected ServiceType[] interfaces
Descriptor for the interfaces. As a special case, interfaces is null for the descriptor for java.lang.Object, and non-null otherwise. This avoids carrying a boolean isInterface around.


replacement

protected transient ServiceType replacement
An instance containing only name, no supertype info. This is only used on the registrar side, to minimize the amount of info transmitted back to clients.


integrity

private transient boolean integrity
Flag set to true if this instance was unmarshalled from an integrity-protected stream, or false otherwise

Constructor Detail

ServiceType

public ServiceType(Class clazz,
                   ServiceType superclass,
                   ServiceType[] interfaces)
            throws MarshalException
Should only be called by ClassMapper

Throws:
MarshalException

ServiceType

private ServiceType(ServiceType stype)
Constructor used for creating replacement instances, containing only name.

Method Detail

getName

public String getName()
Returns the name of this type

Returns:
the name of this type

getSuperclass

public ServiceType getSuperclass()
Return the superclass descriptor


getInterfaces

public ServiceType[] getInterfaces()
Return the interfaces. The array is not a copy; do not modify it.


getReplacement

public ServiceType getReplacement()
Return the replacement, if any, containing only name and rep.


isAssignableFrom

private boolean isAssignableFrom(ServiceType[] ifaces)
Test if this isAssignableFrom any of the given interface types. Note ifaces cannot be null.


isInterface

public boolean isInterface()
See Also:
Class.isInterface()

isAssignableFrom

public boolean isAssignableFrom(ServiceType cls)
Returns true if this type is equal to type or if this type is equal to a superclass of type.

Parameters:
cls - Type to check if subclass of this class
Returns:
true if type is a subclass of this type, false otherwise
See Also:
Class.isAssignableFrom(java.lang.Class)

toClass

public Class toClass(String codebase)
              throws IOException,
                     ClassNotFoundException
Converts this descriptor to a Class instance, loading from codebase

Parameters:
codebase - String the codebase to load the class from
Returns:
Class the class this descriptor represents
Throws:
IOException
ClassNotFoundException

equals

public boolean equals(Object o)
Returns true if the object passed in is an instance of Type with the same type hash. Returns false otherwise.

Overrides:
equals in class Object
Parameters:
o - object to compare this object against
Returns:
true if this object equals the object passed in; false otherwise.

hashCode

public int hashCode()
Return a hashcode for this type.

Overrides:
hashCode in class Object
Returns:
int the hashcode for this type

toString

public String toString()
Overrides:
toString in class Object

computeHash

private void computeHash()
                  throws IOException,
                         NoSuchAlgorithmException
Computes a SHA-1 digest from the hash of the superclass, if there is a superclass, followed by the name of this class, followed by the name and type for each field, if any, declared by this class and ordered alphabetically by field name. The first 8 bytes of the digest are used to form the 64-bit hash value for this type.

Throws:
IOException
NoSuchAlgorithmException

readObject

private void readObject(ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException
Samples integrity protection setting (if any) of the stream from which this instance is being deserialized.

Throws:
IOException
ClassNotFoundException

readObjectNoData

private void readObjectNoData()
                       throws InvalidObjectException
Throws InvalidObjectException, since data for this class is required.

Throws:
InvalidObjectException


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.