Berin,
I've taken a look at the resolver package. It is very nice and general,
but I fear that it is also too much as it is in CVS and there are issues
with
it that I do not understand.
public interface Resolver {
Token lookup( Query query )
}
public interface Token {
Object[] references();
...
}
As I see it, the gain is that you can look up several components
with one single call to Resolver.resolve, and then release them all
simultaneously.
Briefly, consider those two advantages completely separate. We can have
none, one or both of them.
LOOKUP OF SEVERAL COMPONENTS AT ONCE
------------------------------------
Why? I fail to see the point of this. The usage would be
1) Fill in a query object.
2) lookup(query)
3) Extract the components from the Token based on their index in the
returned array of Objects.
I see no gain in number of lines of code: To lookup N components, you
need to fill in a query object = N lines, resolve = 1 line, extract = N
lines.
In effect, the number of lines of code has doubled. Better to provide an
easy
interface for lookups and do N lookup(Query) calls.
RELEASE OF SEVERAL COMPONENTS AT ONCE
-------------------------------------
Good. Much like the catch and finally clauses put all
error handling into one spot, and the CM interface allows
one to release a null component, we get all error handling into one place
and guarantee that multiple components are released properly.
My proposal:
public interface Resolver {
// --------------------- Lookup of a single
component ------------------------------------
/**
* Looks up a component.
* This method is identical to Object lookup( Query query ) called as
* lookup( new Query (role) );
*/
Object lookup( String role ) throws ComponentException;
/**
* Looks up a component.
*/
Object lookup( Query query ) throws ComponentException;
/**
* Releases a single object.
*/
Object release( Object component );
// --------------------- Lookup/release of multiple
components ---------------------------
/**
* Looks up a component and if successful, associates it with a release
token.
* This method is identical to Object lookup( Query query, Token token )
called as
* lookup( new Query (role), Token token );
*/
Object lookup( String role, Token token ) throws InvalidTokenException,
ComponentException;
/**
* Looks up a component and if successful, associates it with a release
token.
*/
Object lookup( Query query, Token token ) throws InvalidTokenException,
ComponentException;
/**
* Releases all objects looked up via a given token.
*/
Object release( Token token );
}
public class Token extends java.rmi.server.UID {}
public class Query {
public Query (String role);
public Query (String role, Parameters parameters);
}
The single-component lookup/release works as the CM interface.
The multiple version, with Token, works like this:
Token token = new Token (); // Guaranteed unique due to
java.rmi.server.UID
MyComponent myComp = null;
MyComponent2 myComp2 = null;
try {
myComp = (MyComponent) resolver.resolve (MyComponent.ROLE, token);
myComp2 = (MyComponent2) resolver.resolve (MyComponent2.ROLE, token);
} finally {
resolver.release (token);
}
/LS
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>