net.jini.constraint
Class BasicMethodConstraints

java.lang.Object
  extended by net.jini.constraint.BasicMethodConstraints
All Implemented Interfaces:
Serializable, MethodConstraints

public final class BasicMethodConstraints
extends Object
implements MethodConstraints, Serializable

Basic implementation of MethodConstraints, allowing limited wildcard matching on method names and parameter types. Methods can be specified by exact name and parameter types (matching a single method), by exact name (matching all methods with that name), by name prefix (matching all methods with names that start with that prefix), by name suffix (matching all methods with names that end with that suffix), and by a default that matches all methods. Normally instances of this class should be obtained from a Configuration rather than being explicitly constructed.

Since:
2.0
Author:
Sun Microsystems, Inc.
See Also:
Serialized Form

Nested Class Summary
static class BasicMethodConstraints.MethodDesc
          Descriptor for specifying the constraints associated with one or more methods allowing limited wildcard matching on method names and parameter types.
 
Field Summary
private  BasicMethodConstraints.MethodDesc[] descs
          The ordered method descriptors.
private static ObjectStreamField[] serialPersistentFields
           
private static long serialVersionUID
           
 
Constructor Summary
BasicMethodConstraints(BasicMethodConstraints.MethodDesc[] descs)
          Creates an instance with the specified ordered array of descriptors.
BasicMethodConstraints(InvocationConstraints constraints)
          Creates an instance that maps all methods to the specified constraints.
 
Method Summary
private  void check()
          Throws IllegalArgumentException if the descriptors array is empty, or if any descriptor is preceded by another descriptor that matches at least the same methods.
private static void check(BasicMethodConstraints.MethodDesc prev, BasicMethodConstraints.MethodDesc desc)
          Throws IllegalArgumentException if the parameter types of prev cover those of desc.
 boolean equals(Object obj)
          Two instances of this class are equal if they have the same descriptors in the same order.
 InvocationConstraints getConstraints(Method method)
          Returns the constraints for the specified remote method as a non-null value.
 BasicMethodConstraints.MethodDesc[] getMethodDescs()
          Returns the descriptors.
private static int hash(Object[] elements)
          Returns the sum of the hash codes of all elements of the given array.
 int hashCode()
          Returns a hash code value for this object.
 Iterator possibleConstraints()
          Returns an iterator that yields all of the possible distinct constraints that can be returned by getConstraints, in arbitrary order and with duplicates permitted.
private  void readObject(ObjectInputStream s)
          Verifies legal descriptor ordering.
private static void rethrow(RuntimeException e)
          If the exception is a NullPointerException or IllegalArgumentException, wrap it in an InvalidObjectException and throw that, otherwise rethrow the exception as is.
 String toString()
          Returns a string representation of this object.
 
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

serialPersistentFields

private static final ObjectStreamField[] serialPersistentFields

descs

private final BasicMethodConstraints.MethodDesc[] descs
The ordered method descriptors.

Constructor Detail

BasicMethodConstraints

public BasicMethodConstraints(BasicMethodConstraints.MethodDesc[] descs)
Creates an instance with the specified ordered array of descriptors. The getConstraints method searches the descriptors in the specified order. For any given descriptor in the array, no preceding descriptor can match at least the same methods as the given descriptor; that is, more specific descriptors must precede less specific descriptors. The array passed to the constructor is neither modified nor retained; subsequent changes to that array have no effect on the instance created.

Parameters:
descs - the descriptors
Throws:
NullPointerException - if the argument is null or any element of the argument is null
IllegalArgumentException - if the descriptors array is empty, or if any descriptor is preceded by another descriptor that matches at least the same methods

BasicMethodConstraints

public BasicMethodConstraints(InvocationConstraints constraints)
Creates an instance that maps all methods to the specified constraints. The constraints can be null, which is treated the same as an empty instance. Calling this constructor is equivalent to constructing an instance of this class with an array containing a single default descriptor constructed with the specified constraints.

Parameters:
constraints - the constraints, or null
Method Detail

check

private void check()
Throws IllegalArgumentException if the descriptors array is empty, or if any descriptor is preceded by another descriptor that matches at least the same methods. Throws NullPointerException if the array or any element is null.


check

private static void check(BasicMethodConstraints.MethodDesc prev,
                          BasicMethodConstraints.MethodDesc desc)
Throws IllegalArgumentException if the parameter types of prev cover those of desc.


getConstraints

public InvocationConstraints getConstraints(Method method)
Returns the constraints for the specified remote method as a non-null value. Searches the descriptors in order, and returns the constraints in the first descriptor that matches the method, or an empty constraints instance if there is no match.

Specified by:
getConstraints in interface MethodConstraints
Parameters:
method - the method
Returns:
the constraints for the specified method as a non-null value
Throws:
NullPointerException - if the argument is null

possibleConstraints

public Iterator possibleConstraints()
Description copied from interface: MethodConstraints
Returns an iterator that yields all of the possible distinct constraints that can be returned by getConstraints, in arbitrary order and with duplicates permitted. The iterator throws an UnsupportedOperationException on any attempt to remove an element.

Specified by:
possibleConstraints in interface MethodConstraints
Returns:
an iterator that yields all of the possible distinct constraints that can be returned by getConstraints, in arbitrary order and with duplicates permitted

getMethodDescs

public BasicMethodConstraints.MethodDesc[] getMethodDescs()
Returns the descriptors. Returns a new non-null array every time it is called.

Returns:
the descriptors as a new non-null array

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class Object

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Two instances of this class are equal if they have the same descriptors in the same order.

Overrides:
equals in class Object

readObject

private void readObject(ObjectInputStream s)
                 throws IOException,
                        ClassNotFoundException
Verifies legal descriptor ordering.

Throws:
InvalidObjectException - if any descriptor is null, or the descriptors array is empty, or if any descriptor is preceded by another descriptor that matches at least the same methods
IOException
ClassNotFoundException

hash

private static int hash(Object[] elements)
Returns the sum of the hash codes of all elements of the given array.


rethrow

private static void rethrow(RuntimeException e)
                     throws InvalidObjectException
If the exception is a NullPointerException or IllegalArgumentException, wrap it in an InvalidObjectException and throw that, otherwise rethrow the exception as is.

Throws:
InvalidObjectException


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