On Oct 5, 2006, at 7:32 PM, Raymond Feng wrote:
Hi, Luciano.
1) Did you use the Tuscany launcher to run your class? The launcher
will bootstrap the Tuscany runtime then
CurrentCompositeContext.getContext() will return an non-null instance.
2) With @Context annoation, the Tuscany runtime will inject the
context to the field and you don't have to call
"CurrentCompositeContext.getContext();".
Yes that would work if it were completely implemented. There is a
ContextProcessor I put in a while back but it is not finished. If
someone is interested in finishing that up it would be good.
In terms of injecting the context and doing a locateService, I'd
actually like to get that removed from the spec since I don't think
there is any reason for it. Specifically, if code is managed, i.e. it
is an SCA component implementation, it should just use DI to inject
the target and not bother with the locate. This will result in less
code and allow the runtime to manage dependencies. If the example
Luciano provided were an SCA component (I assume it is since it has
an SCA annotation), it should just have the scheduler injected onto
it. For unmanaged code, e.g. a JSP tag, it would use locateService.
Jim
Thanks,
Raymond
----- Original Message ----- From: "Luciano Resende"
<[EMAIL PROTECTED]>
To: "tuscany-dev" <[email protected]>
Sent: Thursday, October 05, 2006 7:17 PM
Subject: Consuming simple SCA service
I have created a simple schedule service (SchedulerService
interface and
SchedulerServiceImpl)...
And I was trying to build a simple java client to consume the
service like
this :
public class SchedulerServiceClient {
@Context
CompositeContext compositeContext;
/**
* @param args
*/
public static void main(String[] args) {
try {
CompositeContext context =
CurrentCompositeContext.getContext();
SchedulerService schedulerService = context.locateService(
SchedulerService.class, "SchedulerServiceComponent");
String[] courseWeekdays = { "Mon", "Wed" };
Course course = new Course(courseWeekdays, "CSCI-
E-280", new
Date(), new Date(), "Database course");
List scheduleDates =
schedulerService.processCourseSchedule
(course);
Iterator scheduleIterator = scheduleDates.iterator();
while (scheduleIterator.hasNext()) {
Date d = (Date) scheduleIterator.next();
System.out.println(d.toString());
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
The issue is that i keep getting NPE trying to get a reference to
context...
Any ideas on what i'm doing wrong ? Should i be using it in a
different way
?
- Luciano
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]