CVS: Tapestry/framework/src/net/sf/tapestry/spec ILibrarySpecification.java,1.4.2.2,1.4.2.3 LibrarySpecification.java,1.8.2.1,1.8.2.2
Howard Lewis Ship <[email protected]>
| Newsgroups | gmane.comp.java.tapestry.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/spec
In directory sc8-pr-cvs1:/tmp/cvs-serv32418/framework/src/net/sf/tapestry/spec
Modified Files:
Tag: hship-2-3
ILibrarySpecification.java LibrarySpecification.java
Log Message:
Require a IMonitor instance for each request.
Provide a shared null IMonitor implementation.
Allow a monitor to be specified as an application extension.
Add ability to check type of extension.
Index: ILibrarySpecification.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/spec/ILibrarySpecification.java,v
retrieving revision 1.4.2.2
retrieving revision 1.4.2.3
diff -C2 -d -r1.4.2.2 -r1.4.2.3
*** ILibrarySpecification.java 11 Dec 2002 14:02:26 -0000 1.4.2.2
--- ILibrarySpecification.java 16 Dec 2002 12:56:35 -0000 1.4.2.3
***************
*** 123,126 ****
--- 123,140 ----
/**
+ * Returns an instantiated extension, performing a check to ensure
+ * that the extension is a subtype of the given class (or extends the given
+ * interface).
+ *
+ * @throws IllegalArgumentException if no extension specification exists for
+ * the given name, or if the extension fails the type check.
+ *
+ * @since 2.4
+ *
+ **/
+
+ public Object getExtension(String name, Class typeConstraint);
+
+ /**
* Returns true if the named extension exists (or can be instantiated),
* returns false if the named extension has no specification.
Index: LibrarySpecification.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/spec/LibrarySpecification.java,v
retrieving revision 1.8.2.1
retrieving revision 1.8.2.2
diff -C2 -d -r1.8.2.1 -r1.8.2.2
*** LibrarySpecification.java 7 Dec 2002 13:26:12 -0000 1.8.2.1
--- LibrarySpecification.java 16 Dec 2002 12:56:35 -0000 1.8.2.2
***************
*** 87,96 ****
private String _publicId;
-
/**
* The location of the specification.
*
**/
!
private IResourceLocation _specificationLocation;
--- 87,95 ----
private String _publicId;
/**
* The location of the specification.
*
**/
!
private IResourceLocation _specificationLocation;
***************
*** 296,308 ****
*
**/
!
public boolean checkExtension(String name)
{
if (_extensions == null)
return false;
!
return _extensions.containsKey(name);
}
!
/**
* Returns an instantiated extension. Extensions are created as needed and
--- 295,307 ----
*
**/
!
public boolean checkExtension(String name)
{
if (_extensions == null)
return false;
!
return _extensions.containsKey(name);
}
!
/**
* Returns an instantiated extension. Extensions are created as needed and
***************
*** 316,319 ****
--- 315,325 ----
public synchronized Object getExtension(String name)
{
+ return getExtension(name, null);
+ }
+
+ /** @since 2.4 **/
+
+ public synchronized Object getExtension(String name, Class typeConstraint)
+ {
if (_instantiatedExtensions == null)
_instantiatedExtensions = new HashMap();
***************
*** 326,331 ****
if (spec == null)
! throw new IllegalArgumentException(
! Tapestry.getString("LibrarySpecification.no-such-extension", name));
result = spec.instantiateExtension(_resolver);
--- 332,336 ----
if (spec == null)
! throw new IllegalArgumentException(Tapestry.getString("LibrarySpecification.no-such-extension", name));
result = spec.instantiateExtension(_resolver);
***************
*** 334,341 ****
--- 339,377 ----
}
+ if (typeConstraint != null)
+ applyTypeConstraint(name, result, typeConstraint);
+
return result;
}
/**
+ * Checks that an extension conforms to the supplied type constraint.
+ *
+ * @throws IllegalArgumentException if the extension fails the check.
+ *
+ * @since 2.4
+ *
+ **/
+
+ protected void applyTypeConstraint(String name, Object extension, Class typeConstraint)
+ {
+ Class extensionClass = extension.getClass();
+
+ // Can you assign an instance of the extension to a variable
+ // of type typeContraint legally?
+
+ if (typeConstraint.isAssignableFrom(extensionClass))
+ return;
+
+ String key =
+ typeConstraint.isInterface()
+ ? "LibrarySpecification.extension-does-not-implement-interface"
+ : "LibrarySpecification.extension-not-a-subclass";
+
+ throw new IllegalArgumentException(
+ Tapestry.getString(key, name, extensionClass.getName(), typeConstraint.getName()));
+ }
+
+ /**
* Invoked after the entire specification has been constructed
* to instantiate any extensions marked immediate.
***************
*** 381,385 ****
*
**/
!
protected Map getExtensions()
{
--- 417,421 ----
*
**/
!
protected Map getExtensions()
{
***************
*** 406,410 ****
*
**/
!
protected Map getLibraries()
{
--- 442,446 ----
*
**/
!
protected Map getLibraries()
{
***************
*** 524,528 ****
/** @since 2.4 **/
!
public IResourceLocation getSpecificationLocation()
{
--- 560,564 ----
/** @since 2.4 **/
!
public IResourceLocation getSpecificationLocation()
{
***************
*** 531,535 ****
/** @since 2.4 **/
!
public void setSpecificationLocation(IResourceLocation specificationLocation)
{
--- 567,571 ----
/** @since 2.4 **/
!
public void setSpecificationLocation(IResourceLocation specificationLocation)
{
***************
*** 538,546 ****
/** @since 2.4 **/
!
public String toString()
{
ToStringBuilder builder = new ToStringBuilder(this);
!
builder.append("components", _components);
builder.append("description", _description);
--- 574,582 ----
/** @since 2.4 **/
!
public String toString()
{
ToStringBuilder builder = new ToStringBuilder(this);
!
builder.append("components", _components);
builder.append("description", _description);
***************
*** 552,561 ****
builder.append("services", _services);
builder.append("specificationLocation", _specificationLocation);
!
extendDescription(builder);
!
return builder.toString();
}
!
/**
* Does nothing, subclasses may override to add additional
--- 588,597 ----
builder.append("services", _services);
builder.append("specificationLocation", _specificationLocation);
!
extendDescription(builder);
!
return builder.toString();
}
!
/**
* Does nothing, subclasses may override to add additional
***************
*** 566,570 ****
*
**/
!
protected void extendDescription(ToStringBuilder builder)
{
--- 602,606 ----
*
**/
!
protected void extendDescription(ToStringBuilder builder)
{
-------------------------------------------------------
This sf.net email is sponsored by:
With Great Power, Comes Great Responsibility
Learn to use your power at OSDN's High Performance Computing Channel
http://hpc.devchannel.org/