Qwylt

java.lang.module.spi
Class PackageConnection

java.lang.Object
  extended by java.lang.module.spi.PackageConnection
All Implemented Interfaces:
java.lang.Iterable<ModuleArchive>

public class PackageConnection
extends java.lang.Object
implements java.lang.Iterable<ModuleArchive>

This class represents the connection between a package consumer and a ClassSpace that will satisfy it for a specific package name.

This class acts as a domain for the purposes of constraint resolution, where all candidate archives added to it have already met the constraints expressed by an Import for a given package.

Once fully populated, constraints are applied by the owning ImportSpace, potentially reducing the set of candidates in the domain and failing if the set reduces to zero.

Once committed, the getConnection() method can be called to convert one or more candidates into a ClassSpace that meets all applicable constraints, and is a suitable replacement for an import. Normally, only one candidate will be selected, and this implementation simply chooses the first one in the domain; however, subclasses are free to make a different choice. For example, in the OSGi split-package case, multiple candidates may be "merged" under a facade ClassSpace instance.

Since:
Dec 23, 2008
Author:
Bryan Atsatt

Nested Class Summary
static class PackageConnection.ConnectionType
           
 
Constructor Summary
PackageConnection(PackageConnection.ConnectionType type, java.lang.String packageName, java.util.List<? extends ModuleArchive> domain, boolean check)
          Constructs an instance.
PackageConnection(PackageConnection.ConnectionType type, java.lang.String packageName, ModuleArchive domain)
          Constructs an instance.
 
Method Summary
protected  void commitDomain()
          Commit the domain, ensuring that only the selected candidate(s) remain.
 boolean contains(ModuleArchive candidate)
          Returns true if the domain contains the specified candidate.
 ClassSpace getClassSpace()
          Returns the ClassSpace that is the endpoint of this connection.
protected  ClassSpace getConnection()
          Returns a ClassSpace to use for this connection.
 ModuleArchive getCurrentCandidate()
          Returns the current domain candidate.
 java.util.List<? extends ModuleArchive> getDomain()
          Returns the modifiable domain for this instance.
 java.lang.String getPackageName()
          Returns the package name provided by this connection.
 PackageConnection.ConnectionType getType()
          Returns the connection type.
 boolean isCommitted()
          Returns true if this connection has been committed.
 boolean isReExported()
          Returns whether or not the package should be re-exported.
 java.util.Iterator<ModuleArchive> iterator()
          Returns an iterator over the domain.
 void setConnectTo(ModuleArchive candidate)
          Set the candidate to which to connect.
 void setFirstCandidate()
          Sets the domain to use the first candidate.
 boolean setNextCandidate()
          Sets the domain to the next candidate, if any.
 java.lang.String toString()
          Returns a string representation of this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PackageConnection

public PackageConnection(PackageConnection.ConnectionType type,
                         java.lang.String packageName,
                         ModuleArchive domain)
Constructs an instance.

Parameters:
type - The connection type.
packageName - The package provided by the connection.
domain - The candidate for the specified package.

PackageConnection

public PackageConnection(PackageConnection.ConnectionType type,
                         java.lang.String packageName,
                         java.util.List<? extends ModuleArchive> domain,
                         boolean check)
Constructs an instance.

Parameters:
type - The connection type.
packageName - The package provided by the connection.
domain - The set of candidates for the specified package.
check - true if should validate that candidate exports package.
Method Detail

getType

public PackageConnection.ConnectionType getType()
Returns the connection type.

Returns:
The type.

getPackageName

public java.lang.String getPackageName()
Returns the package name provided by this connection.

Returns:
The package name.

iterator

public java.util.Iterator<ModuleArchive> iterator()
Returns an iterator over the domain.

Specified by:
iterator in interface java.lang.Iterable<ModuleArchive>
Returns:
an Iterator.

getDomain

public java.util.List<? extends ModuleArchive> getDomain()
Returns the modifiable domain for this instance.

Returns:
The domain.
Throws:
java.lang.IllegalStateException - If this connection is committed.

isReExported

public boolean isReExported()
Returns whether or not the package should be re-exported.

Returns:
true if the package should be re-exported; false otherwise.

setFirstCandidate

public void setFirstCandidate()
Sets the domain to use the first candidate.


setNextCandidate

public boolean setNextCandidate()
Sets the domain to the next candidate, if any.

Returns:
true if there is another candidate, false otherwise.

getCurrentCandidate

public ModuleArchive getCurrentCandidate()
Returns the current domain candidate.

Returns:
The candidate.

isCommitted

public boolean isCommitted()
Returns true if this connection has been committed.

Returns:
true if this connection is shared; false otherwise.

setConnectTo

public void setConnectTo(ModuleArchive candidate)
Set the candidate to which to connect.

Parameters:
candidate - The archive, which must already be in this domain.
Throws:
java.lang.IllegalStateException - If the archive is not already present.

contains

public boolean contains(ModuleArchive candidate)
Returns true if the domain contains the specified candidate.

Parameters:
candidate - The candidate.
Returns:
true if the domain contains the specified candidate; false otherwise.

getClassSpace

public ClassSpace getClassSpace()
Returns the ClassSpace that is the endpoint of this connection.

Returns:
The ClassSpace.

toString

public java.lang.String toString()
Returns a string representation of this instance.

Overrides:
toString in class java.lang.Object
Returns:
The string.

commitDomain

protected void commitDomain()
Commit the domain, ensuring that only the selected candidate(s) remain.


getConnection

protected ClassSpace getConnection()
Returns a ClassSpace to use for this connection. This implementation returns the Module instance from the current candidate in the domain. Subclasses may override to return a different ClassSpace; for example, an OSGi implementation might return a virtual class space for a split package.

Returns:
The ClassSpace of the first candidate.

Qwylt

Send comments or questions to Bryan Atsatt