KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > event > impl > EventAspectChain


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.event.impl;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.avalon.framework.configuration.Configuration;
23 import org.apache.avalon.framework.configuration.ConfigurationException;
24 import org.apache.avalon.framework.parameters.Parameters;
25 import org.apache.avalon.framework.service.ServiceException;
26 import org.apache.avalon.framework.service.ServiceSelector;
27
28 /**
29  *
30  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
31  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
32  *
33  * @version CVS $Id: EventAspectChain.java 30932 2004-07-29 17:35:38Z vgritsenko $
34  */

35 public final class EventAspectChain {
36     
37     private List JavaDoc aspects = new ArrayList JavaDoc();
38     
39     private List JavaDoc configs = new ArrayList JavaDoc();
40     
41     public void configure(ServiceSelector selector, Configuration conf)
42     throws ConfigurationException {
43         if ( conf != null ) {
44             Configuration[] aspects = conf.getChildren("aspect");
45             if ( aspects != null ) {
46                 for(int i=0; i < aspects.length; i++) {
47                     final Configuration current = aspects[i];
48                     final String JavaDoc role = current.getAttribute("type");
49                     try {
50                         this.aspects.add(selector.select(role));
51                         this.configs.add(Parameters.fromConfiguration(current));
52                     } catch (ServiceException se) {
53                         throw new ConfigurationException("Unable to lookup aspect " + role, se);
54                     }
55                 }
56             }
57         } else {
58             throw new ConfigurationException("No aspects configured");
59         }
60     }
61     
62     public Iterator JavaDoc getIterator() {
63         return this.aspects.iterator();
64     }
65     
66     public Iterator JavaDoc getConfigIterator() {
67         return this.configs.iterator();
68     }
69     
70     public void dispose(ServiceSelector selector) {
71         Iterator JavaDoc i = this.aspects.iterator();
72         while (i.hasNext()) {
73             selector.release(i.next());
74         }
75         this.aspects.clear();
76     }
77 }
78
Popular Tags