[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Multiple Method Introductions: patterns?
|
As you suggest and Ram advises, this *is* a pattern
(typically called "mixin interface" and often used in
conjunction with "tag interface").
You can also implement it without a common supertype
if you define default and per-class implementations of
getInputSource(). Something like...
interface Validator {
void generateValidity();
InputSource getInputSource();
}
public void Validator.generateValidity() {
InputSource source = getInputSource();
return (null == source ? null : source.getValidity());
}
// default implementation
public InputSource Validator.getInputSource() {
return null;
}
// custom implementation
public InputSource ConcreteClass.getInputSource() {
return getSource();
}
Wes
P.S. - a *shameful* plug: If you're interested in AspectJ
patterns, please sign up for the "good aop" tutorial at
AOSD 2004; early registration discounts have been extended,
but only until Friday Feb. 20.
See http://aosd.net/conference.php
Ramnivas Laddad wrote:
Hi Jeff,
Do you have a common interface that all of the classes
(CIncludeTransformer, DatabaseReader, FragmentExtractorGenerator)
implement? And does such interface provide access to
inputSource field? If so, you can do soemthing like:
privileged public aspect CachingAspect {
/* assuming your classes implement InputSourceProvider
that contain a method "getInputSource()" */
public interface Validator extends InputSourceProvider {
public void generateValidity();
}
declare parents:
(org.apache.cocoon.transformation.CIncludeTransformer ||
org.apache.cocoon.reading.DatabaseReader ||
org.apache.cocoon.generation.FragmentExtractorGenerator)
implements Validator;
public Validator.generateValidity() {
if (this.getInputSource() == null)
return null;
return this.getInputSource().getValidity();
}
}
-Ramnivas
--- daltonj@xxxxxxxxx wrote:
I am doing method introductions on a large scale while refactoring
Apache
Cocoon. What I have run into is this, I have used AspectJ to extend
a large
number of classes to implement an interface
(CacheableProcessingComponenent). .. so for example:
privileged public aspect CachingAspect {
// This works, clearly.
declare parents:
(org.apache.cocoon.transformation.CIncludeTransformer ||
org.apache.cocoon.reading.DatabaseReader ||
org.apache.cocoon.generation.FragmentExtractorGenerator) implements
CacheableProcessingComponent;
// This requires introducing two methods, one of which is below.
What I
// would like to do is this:
public SourceValidity
(org.apache.cocoon.transformation.CIncludeTransformer||org.apache.cocoon.reading
.DatabaseReader||org.apache.cocoon.generation.FragmentExtractorGenerator).genera
teValidity() {
if (this.inputSource == null)
return null;
return this.inputSource.getValidity();
}
}
I have a large classes that use this method that I want to insert
using this
one introduction. What is the best way to accomplish the above?
I have seen some simple wild-card matching in Ramnivas's book, but I
have
not see anything like what I am trying to do. I have not seen any
complicated examples that would relate to the above.
Suggestions?
Thanks.
- Jeff
-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users
__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users