View Javadoc
1 /* 2 * ModuleCfgImpl.java 3 * Created on August 16, 2003 4 * 5 * The Blues Framework - A lightweight application framework 6 * Copyright (C) 2003 Lonnie Pryor 7 * http://blues.lonniepryor.com 8 * 9 * This library is free software; you can redistribute it and/or modify it under the 10 * terms of the GNU Lesser General Public License as published by the Free Software 11 * Foundation; either version 2.1 of the License, or (at your option) any later 12 * version. 13 * 14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY 15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 16 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License along 19 * with this library; if not, write to: 20 * 21 * The Free Software Foundation, Inc. 22 * 59 Temple Place, Suite 330 23 * Boston, MA 02111-1307 USA 24 * 25 */ 26 package com.lonniepryor.blues.cfg; 27 28 import java.util.HashSet; 29 import java.util.LinkedList; 30 import java.util.List; 31 import java.util.Set; 32 33 /*** 34 * Generic implementation of {@link ModuleCfg}. 35 * 36 * @author Lonnie Pryor 37 * @version $Revision: 1.1 $ 38 */ 39 public class ModuleCfgImpl implements ModuleCfg { 40 /*** All of the element names declared in this module. */ 41 private final Set allNames = new HashSet(); 42 /*** The variables declared in this module. */ 43 private final List variableNames = new LinkedList(); 44 /*** The pointcuts declared in this module. */ 45 private final List pointcutCfgs = new LinkedList(); 46 /*** The advices declared in this module. */ 47 private final List adviceCfgs = new LinkedList(); 48 /*** The services declared in this module. */ 49 private final List serviceCfgs = new LinkedList(); 50 /*** The includes declared in this module. */ 51 private final List includeCfgs = new LinkedList(); 52 53 /*** 54 * Creates a new ModuleCfgImpl object. 55 */ 56 public ModuleCfgImpl () { 57 } 58 59 /*** 60 * Declares a variable in this module. 61 * 62 * @param variable The variable to declare. 63 */ 64 public void declareVariable (VariableCfg variable) { 65 if (variable == null) 66 throw new NullPointerException("Variable config cannot be null"); 67 indexName(variable.getName()); 68 variableNames.add(variable.getName()); 69 } 70 71 /*** 72 * Declares a pointcut config in this module. 73 * 74 * @param pointcut The pointcut to declare. 75 */ 76 public void declarePointcut (PointcutCfgImpl pointcut) { 77 declare(pointcut); 78 } 79 80 /*** 81 * Declares an advice in this module. 82 * 83 * @param advice The advice to declare. 84 */ 85 public void declareAdvice (AdviceCfgImpl advice) { 86 declare(advice); 87 } 88 89 /*** 90 * Declares a service in this module. 91 * 92 * @param service The service to declare. 93 */ 94 public void declareService (ServiceCfgImpl service) { 95 declare(service); 96 } 97 98 /*** 99 * Declares an include in this module. 100 * 101 * @param include The include to declare. 102 */ 103 public void declareIncludeModule (IncludeCfgImpl include) { 104 declare(include); 105 } 106 107 /*** 108 * Declares a pointcut config in this module. 109 * 110 * @param pointcut The pointcut to declare. 111 */ 112 public void declare (PointcutCfg pointcut) { 113 if (pointcut == null) 114 throw new NullPointerException("Pointcut config cannot be null"); 115 indexName(pointcut.getName()); 116 pointcutCfgs.add(pointcut); 117 } 118 119 /*** 120 * Declares an advice config in this module. 121 * 122 * @param advice The advice to declare. 123 */ 124 public void declare (AdviceCfg advice) { 125 if (advice == null) 126 throw new NullPointerException("Advice config cannot be null"); 127 adviceCfgs.add(advice); 128 } 129 130 /*** 131 * Declares a service config in this module. 132 * 133 * @param service The service to declare. 134 */ 135 public void declare (ServiceCfg service) { 136 if (service == null) 137 throw new NullPointerException("Service config cannot be null"); 138 indexName(service.getName()); 139 serviceCfgs.add(service); 140 } 141 142 /*** 143 * Declares an include config in this module. 144 * 145 * @param include The include to declare. 146 */ 147 public void declare (IncludeCfg include) { 148 if (include == null) 149 throw new NullPointerException("Include config cannot be null"); 150 indexName(include.getName()); 151 includeCfgs.add(include); 152 } 153 154 /*** 155 * Indexes the specified name in this module's index, failing if it is already 156 * declared. 157 * 158 * @param name The name to index. 159 */ 160 private void indexName (String name) { 161 if (!allNames.add(name)) 162 throw new IllegalArgumentException( 163 "Cannot declare more than one element with name '" + name + "'"); 164 } 165 166 /* (non-Javadoc) 167 * @see com.lonniepryor.blues.cfg.ModuleCfg#getVariables() 168 */ 169 public String[] getVariables () { 170 return (String[])variableNames.toArray(new String[variableNames.size()]); 171 } 172 173 /* (non-Javadoc) 174 * @see com.lonniepryor.blues.cfg.ModuleCfg#getDeclaredPointcuts() 175 */ 176 public PointcutCfg[] getPointcuts () { 177 return (PointcutCfg[])pointcutCfgs.toArray( 178 new PointcutCfg[pointcutCfgs.size()]); 179 } 180 181 /* (non-Javadoc) 182 * @see com.lonniepryor.blues.cfg.ModuleCfg#getDeclaredAdvice() 183 */ 184 public AdviceCfg[] getAdvices () { 185 return (AdviceCfg[])adviceCfgs.toArray(new AdviceCfg[adviceCfgs.size()]); 186 } 187 188 /* (non-Javadoc) 189 * @see com.lonniepryor.blues.cfg.ModuleCfg#getDeclaredServices() 190 */ 191 public ServiceCfg[] getServices () { 192 return (ServiceCfg[])serviceCfgs.toArray(new ServiceCfg[serviceCfgs.size()]); 193 } 194 195 /* (non-Javadoc) 196 * @see com.lonniepryor.blues.cfg.ModuleCfg#getIncludes() 197 */ 198 public IncludeCfg[] getIncludes () { 199 return (IncludeCfg[])includeCfgs.toArray(new IncludeCfg[includeCfgs.size()]); 200 } 201 202 /*** 203 * Child element for declaring external variables. 204 * 205 * @author Lonnie Pryor 206 * @version $Revision: 1.1 $ 207 */ 208 public static class VariableCfg implements Verifiable { 209 /*** The name of the external variable. */ 210 private String name = null; 211 212 /*** 213 * Creates a new VariableCfg object. 214 */ 215 public VariableCfg () { 216 } 217 218 /*** 219 * Sets the name of the external variable. 220 * 221 * @param name The name of the external variable. 222 */ 223 public void setName (String name) { 224 this.name = name; 225 } 226 227 /* (non-Javadoc) 228 * @see com.lonniepryor.blues.cfg.Verifiable#verify() 229 */ 230 public void verify () { 231 if (name == null) 232 throw new IllegalStateException("No variable name specified"); 233 if (name.length() == 0) 234 throw new IllegalStateException("Empty variable name"); 235 } 236 237 /*** 238 * Returns the name of the external variable. 239 * 240 * @return The name of the external variable. 241 */ 242 public String getName () { 243 return name; 244 } 245 } 246 }

This page was automatically generated by Maven