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: package org.apache.cocoon.portal.event.impl;
18:
19: import java.util.ArrayList;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: import org.apache.avalon.framework.configuration.Configuration;
24: import org.apache.avalon.framework.configuration.ConfigurationException;
25: import org.apache.avalon.framework.parameters.Parameters;
26: import org.apache.avalon.framework.service.ServiceException;
27: import org.apache.avalon.framework.service.ServiceSelector;
28:
29: /**
30: *
31: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
32: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
33: *
34: * @version CVS $Id: EventAspectChain.java 433543 2006-08-22 06:22:54Z crossley $
35: */
36: public final class EventAspectChain {
37:
38: private List aspects = new ArrayList();
39:
40: private List configs = new ArrayList();
41:
42: public void configure(ServiceSelector selector, Configuration conf)
43: throws ConfigurationException {
44: if (conf != null) {
45: Configuration[] aspects = conf.getChildren("aspect");
46: if (aspects != null) {
47: for (int i = 0; i < aspects.length; i++) {
48: final Configuration current = aspects[i];
49: final String role = current.getAttribute("type");
50: try {
51: this .aspects.add(selector.select(role));
52: this .configs.add(Parameters
53: .fromConfiguration(current));
54: } catch (ServiceException se) {
55: throw new ConfigurationException(
56: "Unable to lookup aspect " + role, se);
57: }
58: }
59: }
60: } else {
61: throw new ConfigurationException("No aspects configured");
62: }
63: }
64:
65: public Iterator getIterator() {
66: return this .aspects.iterator();
67: }
68:
69: public Iterator getConfigIterator() {
70: return this .configs.iterator();
71: }
72:
73: public void dispose(ServiceSelector selector) {
74: Iterator i = this.aspects.iterator();
75: while (i.hasNext()) {
76: selector.release(i.next());
77: }
78: this.aspects.clear();
79: }
80: }
|