01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
18:
19: import org.apache.tapestry.ComponentEventHandler;
20: import org.apache.tapestry.runtime.Component;
21: import org.apache.tapestry.runtime.Event;
22:
23: public class EventImpl implements Event {
24: private boolean _aborted;
25:
26: private Component _component;
27:
28: private String _methodDescription;
29:
30: private final ComponentEventHandler _handler;
31:
32: public EventImpl(ComponentEventHandler handler) {
33: _handler = notNull(handler, "handler");
34: }
35:
36: public boolean isAborted() {
37: return _aborted;
38: }
39:
40: public void setSource(Component component, String methodDescription) {
41: _component = component;
42: _methodDescription = methodDescription;
43: }
44:
45: @SuppressWarnings("unchecked")
46: public boolean storeResult(Object result) {
47: // Given that this method is *only* invoked from code
48: // that is generated at runtime and proven to be correct,
49: // this should never, ever happen. But what the hell,
50: // let's check anyway.
51:
52: if (_aborted)
53: throw new IllegalStateException(ServicesMessages
54: .componentEventIsAborted(_methodDescription));
55:
56: if (result != null)
57:
58: _aborted |= _handler.handleResult(result, _component,
59: _methodDescription);
60:
61: return _aborted;
62: }
63:
64: protected String getMethodDescription() {
65: return _methodDescription;
66: }
67: }
|