View Javadoc

1   package org.apache.fulcrum.yaafi.framework.role;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  
24  import org.apache.avalon.framework.configuration.Configuration;
25  import org.apache.avalon.framework.configuration.ConfigurationException;
26  import org.apache.fulcrum.yaafi.framework.constant.AvalonFortressConstants;
27  import org.apache.fulcrum.yaafi.framework.constant.AvalonPhoenixConstants;
28  import org.apache.fulcrum.yaafi.framework.constant.AvalonYaafiConstants;
29  import org.apache.fulcrum.yaafi.framework.util.Validate;
30  
31  /**
32   * Parses the role configuration file of various Avalon containers.
33   *
34   * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
35   */
36  
37  public class RoleConfigurationParserImpl
38      implements RoleConfigurationParser
39  {
40      /** The flavour of Avalon container */
41      private String containerFlavour;
42  
43      /**
44       * Constructor
45       * @param containerFlavour The flavour of Avalon container
46       */
47      public RoleConfigurationParserImpl( String containerFlavour )
48      {
49          Validate.notEmpty( containerFlavour, "containerFlavour" );
50          this.containerFlavour = containerFlavour;
51      }
52  
53      /**
54       * Parses a role configuration file.
55       *
56       * @param roleConfiguration the role configuration file to parse
57       * @return the parsed RoleEntries
58       * @throws ConfigurationException the configuration couldn't be processsed
59       */
60      public RoleEntry[] parse( Configuration roleConfiguration )
61          throws ConfigurationException
62      {
63          Validate.notNull( roleConfiguration, "roleConfiguration" );
64  
65          if( AvalonYaafiConstants.AVALON_CONTAINER_YAAFI.equals(containerFlavour) )
66          {
67              return mapFromYaafi(roleConfiguration);
68  
69          }
70          if( AvalonPhoenixConstants.AVALON_CONTAINER_PHOENIX.equals(containerFlavour) )
71          {
72              return mapFromPhoenix(roleConfiguration);
73  
74          }
75          else if( AvalonFortressConstants.AVALON_CONTAINER_FORTESS.equals(containerFlavour) )
76          {
77              return mapFromFortress(roleConfiguration);
78  
79          }
80          else
81          {
82              String msg = "Don't know the following container flavour : " + containerFlavour;
83              throw new IllegalArgumentException(msg);
84          }
85      }
86  
87      /**
88       * Parses a YAAFI role configuration file.
89       *
90       * @param roleConfiguration the role configuration
91       * @return the role entries from the configuration file
92       * @throws ConfigurationException the configuration couldn't be processsed
93       */
94      private RoleEntry[] mapFromYaafi( Configuration roleConfiguration )
95          throws ConfigurationException
96      {
97          Validate.notNull(roleConfiguration, "roleConfiguration");
98  
99          String clazzName = null;
100         String name = null;
101         String shorthand = null;
102         boolean isEarlyInit = false;
103         String description = null;
104         String componentType = null;
105         String componentFlavour = null;
106         boolean hasProxy = false;
107         ArrayList interceptorList = null;
108         String logCategory = null;
109         RoleEntry roleEntry = null;
110 
111         Configuration[] list = roleConfiguration.getChildren( "role" );
112         RoleEntry[] result = new RoleEntry[list.length];
113 
114         for( int i=0; i<list.length; i++ )
115         {
116             clazzName = list[i].getAttribute("default-class");
117             name = list[i].getAttribute("name",clazzName);
118             shorthand = list[i].getAttribute("shorthand",name);
119             isEarlyInit = list[i].getAttributeAsBoolean("early-init",true);
120             description = list[i].getAttribute("description",null);
121             componentType = list[i].getAttribute("component-type","avalon");
122             componentFlavour = list[i].getAttribute("component-flavour", AvalonYaafiConstants.AVALON_CONTAINER_YAAFI);
123             hasProxy = list[i].getAttributeAsBoolean("has-proxy",true);
124             logCategory = list[i].getAttribute("logger",shorthand);
125 
126             // parse the list of defined interceptors
127 
128             Configuration[] interceptorConfigList = list[i].getChild("interceptors").getChildren("interceptor");
129             interceptorList = new ArrayList();
130 
131             for( int j=0; j<interceptorConfigList.length; j++ )
132             {
133                 interceptorList.add(interceptorConfigList[j].getValue("interceptor"));
134             }
135 
136             // create a role entry
137 
138             roleEntry = new RoleEntryImpl(
139                 name,
140                 clazzName,
141                 shorthand,
142                 isEarlyInit,
143                 description,
144                 componentType,
145                 componentFlavour,
146                 hasProxy,
147                 interceptorList,
148                 logCategory
149                 );
150 
151             result[i] = roleEntry;
152         }
153 
154         return result;
155     }
156 
157     private RoleEntry[] mapFromPhoenix( Configuration roleConfiguration )
158         throws ConfigurationException
159     {
160         Validate.notNull(roleConfiguration, "roleConfiguration");
161         throw new ConfigurationException("Not supported yet");
162     }
163 
164     private RoleEntry[] mapFromFortress( Configuration roleConfiguration )
165         throws ConfigurationException
166     {
167         Validate.notNull(roleConfiguration, "roleConfiguration");
168         throw new ConfigurationException("Not supported yet");
169     }
170 }