001 /* 002 Copyright (C) 2002 Renaud Pawlak <renaud@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.ide; 020 021 import java.lang.Class; 022 import java.util.Collection; 023 import java.util.List; 024 import java.util.Set; 025 import java.util.Vector; 026 import org.objectweb.jac.core.ACManager; 027 import org.objectweb.jac.core.AspectComponent; 028 import org.objectweb.jac.core.Jac; 029 import org.objectweb.jac.util.File; 030 031 public class AspectConfiguration extends ModelElement { 032 033 public AspectConfiguration() { 034 } 035 036 public AspectConfiguration(String aspectName) { 037 this.name = aspectName; 038 } 039 040 public String toString() { 041 String _name=null; 042 if (name != null) { 043 _name=name; 044 } else if(aspect!=null) { 045 _name=aspect.getName(); 046 } 047 if (_name!=null) { 048 if(woven) 049 return _name+" *"; 050 else 051 return _name; 052 } else { 053 return super.toString(); 054 } 055 } 056 057 Application application; 058 059 /** 060 * Get the value of application. 061 * @return value of application. 062 */ 063 public Application getApplication() { 064 return application; 065 } 066 067 /** 068 * Set the value of application. 069 * @param v Value to assign to application. 070 */ 071 public void setApplication(Application v) { 072 this.application = v; 073 } 074 075 String name; 076 077 /** 078 * Get the value of name. 079 * @return value of name. 080 */ 081 public String getName() { 082 return name; 083 } 084 085 /** 086 * Set the value of name. 087 * @param v Value to assign to name. 088 */ 089 public void setName(String v) { 090 this.name = v; 091 } 092 093 public static Set getDeclaredAspects(Object substance) { 094 return ACManager.getACM().getDeclaredACs(); 095 } 096 097 Aspect aspect; 098 099 /** 100 * Get the value of aspect. 101 * @return value of aspect. 102 */ 103 public Aspect getAspect() { 104 return aspect; 105 } 106 107 /** 108 * Set the value of aspect. 109 * @param v Value to assign to aspect. 110 */ 111 public void setAspect(Aspect v) { 112 this.aspect = v; 113 } 114 115 boolean woven = true; 116 117 /** 118 * Get the value of woven. 119 * @return value of woven. 120 */ 121 public boolean isWoven() { 122 return woven; 123 } 124 125 /** 126 * Set the value of woven. 127 * @param v Value to assign to woven. 128 */ 129 public void setWoven(boolean v) { 130 this.woven = v; 131 } 132 133 public boolean canReload() { 134 return application!=null && application.isStarted() && application.isDistributionEnabled(); 135 } 136 137 /** 138 * Reloads the configuration in the running process. 139 */ 140 public void reload() throws Throwable/*IOException*/ { 141 if (!application.isStarted()) { 142 org.objectweb.jac.aspects.gui.Actions.showStatus( 143 "Application is not started: cannot reload configuration"); 144 return; 145 } 146 147 org.objectweb.jac.aspects.gui.Actions.showStatus("Reloading aspect configuration '"+ 148 name+"'..."); 149 150 Jac.remoteReloadAspect(getApplication().getName(), 151 getApplication().getServerName(),name); 152 } 153 154 String configurationCode = ""; 155 156 /** 157 * Get the value of configurationCode. 158 * @return value of configurationCode. 159 */ 160 public String getConfigurationCode() { 161 return configurationCode; 162 } 163 164 /** 165 * Set the value of configurationCode. 166 * @param v Value to assign to configurationCode. 167 */ 168 public void setConfigurationCode(String v) { 169 this.configurationCode = v; 170 } 171 172 String defaultConfigurationCode = ""; 173 174 /** 175 * Get the value of defaultConfigurationCode. 176 * @return value of defaultConfigurationCode. 177 */ 178 public String getDefaultConfigurationCode() { 179 return defaultConfigurationCode; 180 } 181 182 /** 183 * Set the value of defaultConfigurationCode. 184 * @param v Value to assign to defaultConfigurationCode. 185 */ 186 public void setDefaultConfigurationCode(String v) { 187 this.defaultConfigurationCode = v; 188 } 189 190 191 private List configItems=new Vector(); 192 193 /** 194 * add a new ConfigItem on this Element 195 * @param config the new ConfigItem 196 */ 197 public void addConfigItem(ConfigItem config){ 198 configItems.add(config); 199 } 200 201 /** 202 * remove an ConfigItem 203 * @param config the ConfigItem 204 */ 205 public void removeConfigItem(ConfigItem config){ 206 configItems.remove(config); 207 } 208 209 /** 210 * Returns all the configuration methods of the aspect 211 * @return a collection of java.lang.reflect.Method 212 */ 213 public Collection getConfigurationMethods() 214 { 215 String acClassName = ACManager.getACM().getACPathFromName(name); 216 try { 217 Class acClass = Class.forName(acClassName); 218 AspectComponent acInstance = (AspectComponent)acClass.newInstance(); 219 return acInstance.getConfigurationMethods(); 220 } catch (Exception e) { 221 } 222 return new Vector(); 223 } 224 }