01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.plugins.trigger;
19:
20: import org.apache.ivy.core.IvyContext;
21: import org.apache.ivy.core.event.IvyEventFilter;
22: import org.apache.ivy.plugins.matcher.PatternMatcher;
23: import org.apache.ivy.util.filter.Filter;
24:
25: /**
26: * Base class for easy trigger implementation. This base class takes of the event filtering part,
27: * the only method to implement in subclasses is {@link IvyListener#progress(IvyEvent)} which should
28: * do whatever the trigger needs to do when the event occurs. This method will only be called when
29: * an event matching the trigger filter occurs.
30: *
31: * @since 1.4
32: */
33: public abstract class AbstractTrigger implements Trigger {
34: private Filter filter;
35:
36: private String event;
37:
38: private String expression;
39:
40: private String matcher = PatternMatcher.EXACT;
41:
42: public Filter getEventFilter() {
43: if (filter == null) {
44: filter = createFilter();
45: }
46: return filter;
47: }
48:
49: private Filter createFilter() {
50: return new IvyEventFilter(getEvent(), getFilter(),
51: getPatternMatcher());
52: }
53:
54: private PatternMatcher getPatternMatcher() {
55: return IvyContext.getContext().getSettings()
56: .getMatcher(matcher);
57: }
58:
59: public String getEvent() {
60: return event;
61: }
62:
63: public void setEvent(String event) {
64: this .event = event;
65: }
66:
67: public String getFilter() {
68: return expression;
69: }
70:
71: public void setFilter(String filterExpression) {
72: expression = filterExpression;
73: }
74:
75: public String getMatcher() {
76: return matcher;
77: }
78:
79: public void setMatcher(String matcher) {
80: this.matcher = matcher;
81: }
82:
83: }
|