001 package org.apache.fulcrum.yaafi.framework.role; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import java.util.ArrayList; 023 024 import org.apache.avalon.framework.configuration.Configuration; 025 import org.apache.avalon.framework.configuration.ConfigurationException; 026 import org.apache.fulcrum.yaafi.framework.constant.AvalonFortressConstants; 027 import org.apache.fulcrum.yaafi.framework.constant.AvalonPhoenixConstants; 028 import org.apache.fulcrum.yaafi.framework.constant.AvalonYaafiConstants; 029 import org.apache.fulcrum.yaafi.framework.util.Validate; 030 031 /** 032 * Parses the role configuration file of various Avalon containers. 033 * 034 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a> 035 */ 036 037 public class RoleConfigurationParserImpl 038 implements RoleConfigurationParser 039 { 040 /** The flavour of Avalon container */ 041 private String containerFlavour; 042 043 /** 044 * Constructor 045 * @param containerFlavour The flavour of Avalon container 046 */ 047 public RoleConfigurationParserImpl( String containerFlavour ) 048 { 049 Validate.notEmpty( containerFlavour, "containerFlavour" ); 050 this.containerFlavour = containerFlavour; 051 } 052 053 /** 054 * Parses a role configuration file. 055 * 056 * @param roleConfiguration the role configuration file to parse 057 * @return the parsed RoleEntries 058 * @throws ConfigurationException the configuration couldn't be processsed 059 */ 060 public RoleEntry[] parse( Configuration roleConfiguration ) 061 throws ConfigurationException 062 { 063 Validate.notNull( roleConfiguration, "roleConfiguration" ); 064 065 if( AvalonYaafiConstants.AVALON_CONTAINER_YAAFI.equals(containerFlavour) ) 066 { 067 return mapFromYaafi(roleConfiguration); 068 069 } 070 if( AvalonPhoenixConstants.AVALON_CONTAINER_PHOENIX.equals(containerFlavour) ) 071 { 072 return mapFromPhoenix(roleConfiguration); 073 074 } 075 else if( AvalonFortressConstants.AVALON_CONTAINER_FORTESS.equals(containerFlavour) ) 076 { 077 return mapFromFortress(roleConfiguration); 078 079 } 080 else 081 { 082 String msg = "Don't know the following container flavour : " + containerFlavour; 083 throw new IllegalArgumentException(msg); 084 } 085 } 086 087 /** 088 * Parses a YAAFI role configuration file. 089 * 090 * @param roleConfiguration the role configuration 091 * @return the role entries from the configuration file 092 * @throws ConfigurationException the configuration couldn't be processsed 093 */ 094 private RoleEntry[] mapFromYaafi( Configuration roleConfiguration ) 095 throws ConfigurationException 096 { 097 Validate.notNull(roleConfiguration, "roleConfiguration"); 098 099 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 }