Changeset 5606
- Timestamp:
- Apr 14, 2011, 9:45:23 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 deleted
- 16 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsControl.java
r5605 r5606 39 39 import net.sf.basedb.core.Application; 40 40 import net.sf.basedb.core.Client; 41 import net.sf.basedb.core.Config;42 41 import net.sf.basedb.core.DbControl; 43 42 import net.sf.basedb.core.Permission; … … 53 52 import net.sf.basedb.util.extensions.Registry; 54 53 import net.sf.basedb.util.extensions.events.EventType; 54 import net.sf.basedb.util.extensions.manager.ExtensionKey; 55 55 import net.sf.basedb.util.extensions.manager.ExtensionsFile; 56 56 import net.sf.basedb.util.extensions.manager.ExtensionsManager; 57 57 import net.sf.basedb.util.extensions.manager.ObjectKey; 58 58 import net.sf.basedb.util.extensions.manager.ProcessResults; 59 import net.sf.basedb.util.extensions.manager.Settings; 59 60 import net.sf.basedb.util.extensions.manager.filter.DeletedFilter; 60 61 import net.sf.basedb.util.extensions.manager.filter.ValidAndNewOrModifiedFilter; 61 62 import net.sf.basedb.util.extensions.manager.processor.DeleteResourcesProcessor; 62 63 import net.sf.basedb.util.extensions.manager.processor.ExtractResourcesProcessor; 63 import net.sf.basedb.util.extensions.manager.processor.MarkAsProcessedProcessor;64 64 import net.sf.basedb.util.extensions.manager.processor.UnregisterExtensionsProcessor; 65 import net.sf.basedb.util.extensions.xml.ExtensionPointFilter; 65 66 66 67 /** … … 118 119 private static boolean initialised = false; 119 120 120 // The registry that holds information about installed extensions 121 // The main extensions manager, registry and settings 122 private static ExtensionsManager manager; 121 123 private static Registry registry; 122 123 // The main extensions manager124 private static ExtensionsManager manager;125 126 // The directory where extension files are located127 //private static ExtensionsDirectory extensionsDir;128 129 // Settings130 124 private static Settings settings; 131 125 … … 144 138 if (initialised) return; 145 139 log.info("Initialising extensions controller"); 146 //extensionsDir = directory;147 140 servletContext = context; 148 141 149 // Createregistry142 // Hook into core manager and registry 150 143 manager = Application.getExtensionsManager(); 151 registry = Application.getExtensionsManager().getRegistry(); 144 registry = manager.getRegistry(); 145 settings = manager.getSettings(); 152 146 153 147 // Register some extension points programmatically. This … … 157 151 EditUtil.registerExtensionPoints(registry); // TabControls 158 152 153 // Add default web-client extension points and extensions 159 154 manager.addURI(URI.create(ExtensionsControl.class.getResource("/web-extensions.xml").toString())); 160 155 161 // Load settings162 File settingsFile = new File(Config.getConfigDirectory(), "settings.xml");163 settings = new Settings(settingsFile);164 //extensionsDir.addIgnore(settingsFile);165 166 156 // Install extensions 167 //XmlLoader loader = new XmlLoader();168 157 lastScanResults = new ProcessResults(false, false); 169 158 170 // Filter that only load web extension points 171 //loader.setFilter(new ExtensionPointFilter("net\\.sf\\.basedb\\.clients\\.web\\..*")); 172 173 /* 174 final VariableConverter variableConverter = new VariableConverter(); 175 variableConverter.setVariable("ROOT", servletContext.getContextPath()); 176 variableConverter.setVariable("HOME", null); 177 variableConverter.setVariable("SERVLET_HOME", null); 178 final PathConverter pathConverter = new PathConverter(servletContext.getContextPath(), null); 179 180 loader.addValueConverter(variableConverter); 181 loader.addValueConverter(pathConverter); 182 */ 183 184 /* 185 manager.processFiles(new RegisterExtensionsProcessor(loader, false, lastScanResults) 186 { 187 188 @Override 189 public void processFile(ExtensionsManager manager, 190 WriteableExtensionsFile xtFile) 191 { 192 String homePath = servletContext.getContextPath() + RESOURCES_URL + "/" + xtFile.getExtensionsFile().getName(); 193 //String servletHomePath = getServletsUrl(extFile); 194 variableConverter.setVariable("HOME", homePath); 195 //variableConverter.setVariable("SERVLET_HOME", servletHomePath); 196 pathConverter.setHome(homePath); 197 198 super.processFile(manager, xtFile); 199 } 200 }); 201 */ 202 // manager.processFiles(new ExtractResourcesProcessor(new java.io.File(servletContext.getRealPath(RESOURCES_URL)), false, Pattern.compile("resources/(.*)"), "$1", lastScanResults)); 203 //lastScanResults = new ScanResults(true, false); 204 /* 205 lastScanResults = extensionsDir.installAndUpdateExtensions(registry, 206 servletContext, false, false); 207 */ 208 159 // Initial scan 209 160 scan(true, false); 210 211 161 initialised = true; 212 162 213 Services.init( registry, settings);163 Services.init(); 214 164 log.info("Extensions controller initialised successfully"); 215 165 } … … 225 175 Services.close(); 226 176 registry = null; 227 //extensionsDir = null;228 settings = null;229 177 servletContext = null; 230 178 lastScanResults = null; … … 234 182 235 183 236 private static synchronizedProcessResults scan(boolean initialScan, boolean forceUpdate)184 private static ProcessResults scan(boolean initialScan, boolean forceUpdate) 237 185 { 238 186 String rootPath = servletContext.getContextPath(); … … 251 199 int numRegistered = 0; 252 200 253 if (!initialScan) 254 { 255 // 1. Process files that has been deleted 256 DeletedFilter deleted = new DeletedFilter(); 201 synchronized (manager) 202 { 203 if (!initialScan) 204 { 205 // 1. Process files that has been deleted 206 DeletedFilter deleted = new DeletedFilter(); 207 208 // 1a. Remove resources extracted from JAR files 209 DeleteResourcesProcessor deleteResources = new DeleteResourcesProcessor(resourceDir, results); 210 manager.processFiles(deleteResources, deleted); 211 212 // 1b. Unregister all extensions from deleted files 213 UnregisterExtensionsProcessor unregister = new UnregisterExtensionsProcessor(results); 214 manager.processFiles(unregister, deleted); 215 numUnregistered = unregister.getNumUnregistered(); 216 } 257 217 258 // 1a. Remove resources extracted from JAR files 259 DeleteResourcesProcessor deleteResources = new DeleteResourcesProcessor(resourceDir, results); 260 manager.processFiles(deleteResources, deleted); 218 // 2. Update the manager with new and modified files 219 manager.scanForNewAndUpdated(); 220 numNewFiles = manager.getNumNew(); 221 numModifiedFiles = manager.getNumModified(); 222 numDeletedFiles = manager.getNumDeleted(); 261 223 262 // 1b. Unregister all extensions from deleted files 263 UnregisterExtensionsProcessor unregister = new UnregisterExtensionsProcessor(results); 264 manager.processFiles(unregister, deleted); 265 numUnregistered = unregister.getNumUnregistered(); 266 } 267 268 // 2. Update the manager with new and modified files 269 manager.scanForNewAndUpdated(); 270 numNewFiles = manager.getNumNew(); 271 numModifiedFiles = manager.getNumModified(); 272 numDeletedFiles = manager.getNumDeleted(); 273 274 if (initialScan || numNewFiles > 0 || numModifiedFiles > 0 || forceUpdate) 275 { 276 // Process files that are valid and new/updated (unless forceUpdate=true) 277 ValidAndNewOrModifiedFilter valid = new ValidAndNewOrModifiedFilter(initialScan || forceUpdate); 224 if (initialScan || numNewFiles > 0 || numModifiedFiles > 0 || forceUpdate) 225 { 226 // Process files that are valid and new/updated (unless forceUpdate=true) 227 ValidAndNewOrModifiedFilter valid = new ValidAndNewOrModifiedFilter(initialScan || forceUpdate); 228 229 // 3. Load extension definitions 230 WebClientRegisterExtensionsProcessor registerExtensions = 231 new WebClientRegisterExtensionsProcessor(rootPath, rootPath + RESOURCES_URL, rootPath + SERVLET_URL, results); 232 registerExtensions.setForceUpdate(forceUpdate); 233 if (initialScan) 234 { 235 // Filter that only load web extension points 236 registerExtensions.getXmlLoader().setFilter(new ExtensionPointFilter("net\\.sf\\.basedb\\.clients\\.web\\..*")); 237 } 238 manager.processFiles(registerExtensions, valid); 239 240 // 4. Extract web resources 241 ExtractResourcesProcessor extractResources = new ExtractResourcesProcessor(resourceDir, Pattern.compile("resources/(.*)"), "$1", results); 242 extractResources.setForceOverwrite(forceUpdate); 243 manager.processFiles(extractResources, valid); 244 245 // 5. Servlets 246 LoadServletsProcessor loadServlets = new LoadServletsProcessor(servletContext, results); 247 manager.processFiles(loadServlets, valid); 248 249 // 6. Actual registration of all extensions 250 registerExtensions.finalizeRegistration(manager); 251 numRegistered = registerExtensions.getNumRegistered(); 252 } 278 253 279 // 3. Load extension definitions 280 WebClientRegisterExtensionsProcessor registerExtensions = 281 new WebClientRegisterExtensionsProcessor(rootPath, rootPath + RESOURCES_URL, rootPath + SERVLET_URL, results); 282 registerExtensions.setForceUpdate(forceUpdate); 283 manager.processFiles(registerExtensions, valid); 284 285 // 4. Extract web resources 286 ExtractResourcesProcessor extractResources = new ExtractResourcesProcessor(resourceDir, Pattern.compile("resources/(.*)"), "$1", results); 287 extractResources.setForceOverwrite(forceUpdate); 288 manager.processFiles(extractResources, valid); 289 290 // 5. Servlets 291 292 // 6. Actual registration of all extensions 293 registerExtensions.finalizeRegistration(manager); 294 numRegistered = registerExtensions.getNumRegistered(); 295 } 296 297 // Reset the 'last modifed' status of all files and generated summary per file 298 manager.processFiles(new SetFileStatusProcessor(results)); 299 results.setEnded(); 254 // Reset the 'last modifed' status of all files and generated summary per file 255 manager.processFiles(new SetFileStatusProcessor(results)); 256 results.setEnded(); 257 } 300 258 301 259 // Generate summary message, etc. … … 422 380 public static String getHomeUrl(String extensionId) 423 381 { 424 return null;425 //return file == null ? null : extensionsDir.getResourcesUrl(file);382 ExtensionsFile xtFile = manager.getFileByObjectKey(new ExtensionKey(extensionId)); 383 return xtFile == null ? null : servletContext.getContextPath() + RESOURCES_URL + "/" + xtFile.getName(); 426 384 } 427 385 428 386 /** 429 387 Get the base URL for servlets in the extension with the given ID. The 430 URL is a local absolute U TL, eg. it includes the full path but not the388 URL is a local absolute URL, eg. it includes the full path but not the 431 389 protocol, server or port. The URL is usually something like: 432 390 <p> … … 446 404 public static String getServletUrl(String extensionId, String servletName) 447 405 { 448 //ExtensionsFile file = extensionsDir.getFileByExtensionId(extensionId);406 ExtensionsFile xtFile = manager.getFileByObjectKey(new ExtensionKey(extensionId)); 449 407 String servletPath = null; 450 /* 451 if (file != null) 452 { 453 servletPath = extensionsDir.getServletsUrl(file) + "/" + servletName; 454 } 455 */ 408 if (xtFile != null) 409 { 410 servletPath = servletContext.getContextPath() + SERVLET_URL + "/" + xtFile.getName() + "/" + servletName; 411 } 456 412 return servletPath; 457 413 } … … 521 477 /** 522 478 Get the results of the last scan (manual or automatic). 523 @return A {@link ScanResults} object, or null if no scan479 @return A {@link ProcessResults} object, or null if no scan 524 480 has taken place 525 481 */ … … 701 657 702 658 /** 703 Get information about the file a given extension or extension704 point is defined in.705 @param extensionId The ID of an extension or extension point706 @return Information about the file the extension is defined in,707 or null if no extension with the given ID isfound659 Find out which file the given object is defined in. 660 661 @param key An object key 662 @return Information about the file, or null if 663 the object can't be found 708 664 */ 709 665 public ExtensionsFile getFileByObjectKey(ObjectKey key) … … 716 672 If no file with the given name is found or if that file isn't an 717 673 extensions file, nothing is done. 718 @param file name The filenamewhich contains the extensions674 @param fileuri The fileuri which contains the extensions 719 675 @param enable TRUE to enable, FALSE to disable 720 676 */ 721 public void enableAllInFile(String file name, boolean enable)722 { 723 checkPermission(Permission.WRITE, "File[" + file name+ "]");724 /* 725 ExtensionsFile file = null; //getFile(filename);677 public void enableAllInFile(String fileuri, boolean enable) 678 { 679 checkPermission(Permission.WRITE, "File[" + fileuri + "]"); 680 681 ExtensionsFile file = getFile(fileuri); 726 682 if (file == null) 727 683 { 728 log.warn("File '" + file name+ "' is not an extensions file");684 log.warn("File '" + fileuri + "' is not an extensions file"); 729 685 return; 730 686 } 731 687 732 Iterator<ExtensionPoint<?>> itp = file.getExtensionPoints(); 733 while (itp.hasNext()) 734 { 735 ExtensionPoint<?> ep = itp.next(); 688 for (ExtensionPoint ep : file.getObjectsOfClass(ExtensionPoint.class)) 689 { 736 690 if (!enable) registry.handleEvent(BEFORE_DISABLE, ep, null); 737 691 settings.enableExtensionPoint(ep.getId(), enable); … … 739 693 } 740 694 741 Iterator<Extension<?>> itx = file.getExtensions(); 742 while (itx.hasNext()) 743 { 744 Extension<?> ext = itx.next(); 695 for (Extension ext : file.getObjectsOfClass(Extension.class)) 696 { 745 697 ExtensionPoint ep = getExtensionPoint(ext.getExtends()); 746 698 if (!enable) registry.handleEvent(BEFORE_DISABLE, ep, ext); … … 748 700 if (enable) registry.handleEvent(AFTER_ENABLE, ep, ext); 749 701 } 750 */751 702 } 752 703 -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/service/Services.java
r4618 r5606 23 23 24 24 import net.sf.basedb.clients.web.extensions.ExtensionsControl; 25 import net.sf.basedb.c lients.web.extensions.Settings;25 import net.sf.basedb.core.Application; 26 26 import net.sf.basedb.util.extensions.Extension; 27 27 import net.sf.basedb.util.extensions.ExtensionsFilter; 28 28 import net.sf.basedb.util.extensions.ExtensionsInvoker; 29 import net.sf.basedb.util.extensions.Registry;30 29 import net.sf.basedb.util.extensions.SingleExtensionFilter; 31 30 import net.sf.basedb.util.extensions.events.ExtensionPointEventFilter; 31 import net.sf.basedb.util.extensions.manager.ExtensionsManager; 32 32 33 33 /** … … 47 47 48 48 private static boolean initialised; 49 private static Settings settings;50 49 51 50 /** … … 53 52 is started up. 54 53 */ 55 public static synchronized void init( Registry registry, Settings s)54 public static synchronized void init() 56 55 { 57 56 if (initialised) return; 58 57 log.info("Initialising services"); 59 settings = s;58 ExtensionsManager manager = Application.getExtensionsManager(); 60 59 ExtensionsInvoker<ServiceControllerAction> invoker = getInvoker(null); 61 60 invoker.render(new StartServiceRenderer()); 62 registry.registerEventHandler(63 new ServicesEventHandler( settings),61 manager.getRegistry().registerEventHandler( 62 new ServicesEventHandler(), 64 63 new ExtensionPointEventFilter(EXTENSION_POINT_ID)); 65 64 log.info("Initialising services done"); … … 77 76 ExtensionsInvoker<ServiceControllerAction> invoker = getInvoker(null); 78 77 invoker.render(new StopServiceRenderer()); 79 settings = null;80 78 initialised = false; 81 79 log.info("Closing all services done"); … … 114 112 { 115 113 ExtensionsFilter filter = extension == null ? 116 settings: new SingleExtensionFilter(extension.getId());114 Application.getExtensionsManager().getSettings() : new SingleExtensionFilter(extension.getId()); 117 115 ExtensionsInvoker<?> invoker = ExtensionsControl.useExtensions(null, filter, EXTENSION_POINT_ID); 118 116 invoker.setClearErrors(true); -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/service/ServicesEventHandler.java
r4512 r5606 23 23 24 24 import net.sf.basedb.clients.web.extensions.ExtensionsControl; 25 import net.sf.basedb.c lients.web.extensions.Settings;25 import net.sf.basedb.core.Application; 26 26 import net.sf.basedb.util.extensions.Extension; 27 27 import net.sf.basedb.util.extensions.ExtensionPoint; 28 28 import net.sf.basedb.util.extensions.events.EventHandler; 29 29 import net.sf.basedb.util.extensions.events.EventType; 30 import net.sf.basedb.util.extensions.manager.Settings; 30 31 31 32 /** … … 44 45 org.apache.log4j.LogManager.getLogger("net.sf.basedb.clients.web.extensions.service.ServicesEventHandler"); 45 46 46 private Settings settings;47 private final Settings settings; 47 48 48 public ServicesEventHandler( Settings settings)49 public ServicesEventHandler() 49 50 { 50 this.settings = settings;51 this.settings = Application.getExtensionsManager().getSettings(); 51 52 } 52 53 -
trunk/src/clients/web/net/sf/basedb/clients/web/servlet/ExtensionsServlet.java
r5601 r5606 21 21 package net.sf.basedb.clients.web.servlet; 22 22 23 import java.io.File;24 23 import java.io.IOException; 25 24 import java.util.regex.Matcher; … … 34 33 35 34 import net.sf.basedb.clients.web.extensions.ExtensionsControl; 36 import net.sf.basedb.clients.web.extensions.ExtensionsDirectory;37 import net.sf.basedb.clients.web.extensions.ExtensionsFile;38 35 import net.sf.basedb.clients.web.extensions.RequestWrapper; 39 36 import net.sf.basedb.clients.web.extensions.ServletWrapper; 37 import net.sf.basedb.clients.web.extensions.ServletWrapperKey; 40 38 import net.sf.basedb.util.Values; 39 import net.sf.basedb.util.extensions.manager.ExtensionsFile; 41 40 42 41 /** … … 74 73 ServletConfig cfg = getServletConfig(); 75 74 ServletContext context = cfg.getServletContext(); 76 /*77 File extensionsDir = new File(context.getRealPath(ExtensionsControl.EXTENSIONS_URL));78 File resourcesDir = new File(context.getRealPath(ExtensionsControl.RESOURCES_URL));79 String rootUrl = context.getContextPath();80 81 ExtensionsDirectory extensions = new ExtensionsDirectory(82 extensionsDir, resourcesDir, rootUrl, rootUrl + ExtensionsControl.RESOURCES_URL);83 */84 75 ExtensionsControl.init(context); 85 76 } … … 134 125 135 126 ExtensionsControl ec = ExtensionsControl.get(null); 136 ExtensionsFile file = null; //ec.getFile(jarName); 127 ServletWrapperKey servletKey = new ServletWrapperKey(jarName, servletName); 128 ExtensionsFile file = ec.getFileByObjectKey(servletKey); 137 129 if (file == null) 138 130 { … … 146 138 } 147 139 148 ServletWrapper wrapper = file.get Servlet(servletName);140 ServletWrapper wrapper = file.getObjectForKey(servletKey); 149 141 if (wrapper == null) 150 142 { -
trunk/src/core/net/sf/basedb/core/Application.java
r5605 r5606 536 536 // TODO -- should this be moved to a utility class? Probably... 537 537 Registry xtRegistry = new Registry(); 538 xtManager = new ExtensionsManager(xtRegistry); 538 java.io.File xtSettings = new java.io.File(pluginsDirectory, "settings.xml"); 539 xtManager = new ExtensionsManager(xtRegistry, xtSettings); 539 540 540 541 // Add core extension points and extensions -
trunk/src/core/net/sf/basedb/util/extensions/Registry.java
r5599 r5606 52 52 @version 2.7 53 53 @base.modified $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $ 54 @see net.sf.basedb.clients.web.extensions.ExtensionsDirectory55 54 */ 56 55 public class Registry -
trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionKey.java
r5602 r5606 60 60 61 61 /* 62 From the ObjectKey interface 63 ---------------------------- 64 */ 65 @Override 66 public String toDescription() 67 { 68 return "Extension '" + id + "'"; 69 } 70 // ----------------------------- 71 72 /* 62 73 From the Object class 63 74 --------------------- -
trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionPointKey.java
r5602 r5606 60 60 61 61 /* 62 From the ObjectKey interface 63 ---------------------------- 64 */ 65 @Override 66 public String toDescription() 67 { 68 return "Extension point '" + id + "'"; 69 } 70 // ----------------------------- 71 72 /* 62 73 From the Object class 63 74 --------------------- -
trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionsFile.java
r5605 r5606 689 689 { 690 690 checkClosed(); 691 xtFile.manager.registerObject(key, this.xtFile); 691 692 xtFile.allObjects.put(key, obj); 692 xtFile.manager.registerObject(key, this.xtFile);693 693 } 694 694 … … 703 703 checkClosed(); 704 704 xtFile.allObjects.remove(key); 705 xtFile.manager.unregisterObject(key );705 xtFile.manager.unregisterObject(key, this.xtFile); 706 706 } 707 707 -
trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionsManager.java
r5605 r5606 36 36 import java.util.TreeMap; 37 37 38 import net.sf.basedb.core.ItemAlreadyExistsException; 38 39 import net.sf.basedb.util.RegexpFileFilter; 39 40 import net.sf.basedb.util.extensions.Registry; … … 56 57 org.apache.log4j.LogManager.getLogger("net.sf.basedb.util.extensions.manager.ExtensionsManager"); 57 58 59 // Main registry for extensions 58 60 private final Registry registry; 59 61 // Settings file 62 private final Settings settings; 60 63 // Manually added ignore files 61 64 private final Set<File> ignore; … … 65 68 private final Map<URI, ExtensionsFile> xtFiles; 66 69 // Map objects to the file they are defined in. The key is a unique object id. 67 private final Map<ObjectKey , ExtensionsFile> installedObjects;70 private final Map<ObjectKey<?>, ExtensionsFile> installedObjects; 68 71 69 72 private int numNew; … … 78 81 @param registry 79 82 */ 80 public ExtensionsManager(Registry registry )83 public ExtensionsManager(Registry registry, File settingsFile) 81 84 { 82 85 this.registry = registry; 86 this.settings = new Settings(this, settingsFile); 83 87 this.ignore = new HashSet<File>(); 84 88 this.directories = new HashSet<File>(); 85 89 this.xtFiles = new TreeMap<URI, ExtensionsFile>(new JarFirstURIComparator()); 86 this.installedObjects = new HashMap<ObjectKey, ExtensionsFile>(); 90 this.installedObjects = new HashMap<ObjectKey<?>, ExtensionsFile>(); 91 addIgnore(settingsFile); 87 92 } 88 93 … … 94 99 { 95 100 return registry; 101 } 102 103 /** 104 Get the settings for the extension manager. 105 */ 106 public Settings getSettings() 107 { 108 return settings; 96 109 } 97 110 … … 103 116 @see #removeIgnore(File) 104 117 */ 105 public void addIgnore(File file)118 public synchronized void addIgnore(File file) 106 119 { 107 120 if (file == null) return; … … 114 127 @see #addIgnore(File) 115 128 */ 116 public void removeIgnore(File file)129 public synchronized void removeIgnore(File file) 117 130 { 118 131 if (file == null) return; … … 130 143 not previously known to the manager 131 144 */ 132 public int addDirectory(File dir)145 public synchronized int addDirectory(File dir) 133 146 { 134 147 if (dir == null) throw new NullPointerException("dir"); … … 147 160 @return The extension file object representing the added file 148 161 */ 149 public ExtensionsFile addFile(File file)162 public synchronized ExtensionsFile addFile(File file) 150 163 { 151 164 if (file == null) throw new NullPointerException("file"); … … 168 181 @return The extension file object representing the added uri 169 182 */ 170 public ExtensionsFile addURI(URI uri)183 public synchronized ExtensionsFile addURI(URI uri) 171 184 { 172 185 if (uri == null) throw new NullPointerException("uri"); … … 175 188 return xtFile; 176 189 } 177 178 /*179 public void removeFile(ExtensionsFile xtFile)180 {181 xtFiles.remove(xtFile.getURI());182 //ignore.remove(xtFile);183 Iterator<ExtensionsFile> it = installedObjects.values().iterator();184 while (it.hasNext())185 {186 if (it.next().equals(xtFile)) it.remove();187 }188 }189 */190 190 191 191 private void addExtensionsFile(ExtensionsFile xtFile) … … 206 206 @return The number of new + modified files that was found 207 207 */ 208 public int scanForNewAndUpdated()208 public synchronized int scanForNewAndUpdated() 209 209 { 210 210 numNew = 0; … … 371 371 or null if no object is found for the given key 372 372 */ 373 public ExtensionsFile getFileByObjectKey(ObjectKey key)373 public ExtensionsFile getFileByObjectKey(ObjectKey<?> key) 374 374 { 375 375 return installedObjects.get(key); … … 380 380 381 381 @param key The object key 382 @param xtFile The extensions file 383 */ 384 void registerObject(ObjectKey key, ExtensionsFile xtFile) 385 { 386 installedObjects.put(key, xtFile); 387 } 388 389 /** 390 Unregister an object. 382 @param xtFile The extensions file the object is defined in 383 */ 384 void registerObject(ObjectKey<?> key, ExtensionsFile xtFile) 385 { 386 ExtensionsFile xtOther = installedObjects.get(key); 387 if (xtOther == null) 388 { 389 installedObjects.put(key, xtFile); 390 } 391 else 392 { 393 throw new ItemAlreadyExistsException(key.toDescription() + " is defined in '" + xtOther.getName() + "'"); 394 } 395 } 396 397 /** 398 Unregister an object. The given extensions file must match 399 be equal to the one that registered the object, otherwise 400 the unregistration is ignored. 401 391 402 @param key The object key 392 */ 393 void unregisterObject(ObjectKey key) 394 { 395 installedObjects.remove(key); 403 @param xtFile The extensions file the object is defined in 404 */ 405 void unregisterObject(ObjectKey<?> key, ExtensionsFile xtFile) 406 { 407 if (xtFile.equals(installedObjects.get(key))) 408 { 409 installedObjects.remove(key); 410 } 396 411 } 397 412 … … 408 423 } 409 424 425 /** 426 Process all know file with the given processer. 427 @param processor A processor implementation, null is not allowed 428 */ 410 429 public void processFiles(ExtensionsFileProcessor processor) 411 430 { … … 420 439 limit which files are sent to the processor 421 440 */ 422 public void processFiles(ExtensionsFileProcessor processor, Filter<ExtensionsFile> filter)441 public synchronized void processFiles(ExtensionsFileProcessor processor, Filter<ExtensionsFile> filter) 423 442 { 424 443 if (processor == null) throw new NullPointerException("processor"); … … 479 498 } 480 499 500 /** 501 Compare URI:s so that 'jar:' scheme always are listed first. This means 502 that the core defintion files are always displayed before any external 503 extensions. 504 */ 481 505 public static class JarFirstURIComparator 482 506 implements Comparator<URI> -
trunk/src/core/net/sf/basedb/util/extensions/manager/FactoryParametersKey.java
r5602 r5606 58 58 59 59 /* 60 From the ObjectKey interface 61 ---------------------------- 62 */ 63 @Override 64 public String toDescription() 65 { 66 return "Factory '" + factory + "'"; 67 } 68 // ----------------------------- 69 70 71 /* 60 72 From the Object class 61 73 --------------------- -
trunk/src/core/net/sf/basedb/util/extensions/manager/ObjectKey.java
r5602 r5606 32 32 <p> 33 33 34 This interface doesn't have any methods. It is up to the 35 actual implementations to decide what actually makes up 36 a key that can be used to identify an object. Implementors 34 It is up to the actual implementations to decide what actually 35 makes up a key that can be used to identify an object. Implementors 37 36 of this interface should implement <code>equals()</code> and 38 37 <code>hashCode()</code> methods to only match with it's … … 47 46 */ 48 47 public interface ObjectKey<O> 49 {} 48 { 49 /** 50 Get a string description of the key that is suitable for use 51 in (error) messages to users. 52 */ 53 public String toDescription(); 54 } -
trunk/src/core/net/sf/basedb/util/extensions/manager/Settings.java
r5605 r5606 20 20 along with BASE. If not, see <http://www.gnu.org/licenses/>. 21 21 */ 22 package net.sf.basedb. clients.web.extensions;22 package net.sf.basedb.util.extensions.manager; 23 23 24 24 import java.io.BufferedInputStream; … … 40 40 /** 41 41 Class for keeping settings for the extensions system. Settings 42 are kept in the file <code>WEB-INF/extensions/settings.xml</code>. 42 are kept in the <code>settings.xml</code> file in the plug-ins 43 directory. 43 44 <p> 44 45 … … 64 65 { 65 66 66 //private static final String AUTO_INSTALL = "auto-install";67 68 //private final ExtensionsDirectory directory;69 67 private final File file; 68 private final ExtensionsManager manager; 70 69 private boolean hasChanged; 71 70 private Presets presets; … … 78 77 it will be created if {@link #save()} is called. The settings file 79 78 must be an XML file that can be read by the {@link Presets} class. 80 @param file The file to load/save settings in 79 @param file The file to load/save settings in. If null, settings only are 80 kept in memory and are lost when the server is shutdown. 81 81 */ 82 public Settings(File file)82 Settings(ExtensionsManager manager, File file) 83 83 { 84 // this.directory = directory;84 this.manager = manager; 85 85 this.file = file; 86 86 this.presets = new Presets(); 87 if (file .exists())87 if (file != null && file.isFile()) 88 88 { 89 89 try … … 112 112 { 113 113 if (extensionPoint == null) return false; 114 //ExtensionsFile extFile = directory.getFileByExtensionId(extensionPoint.getId());115 //if (extFile != null && (extFile.hasError() || !extFile.isValid())) return false;114 ExtensionsFile xtFile = manager.getFileByObjectKey(new ExtensionPointKey(extensionPoint)); 115 if (xtFile != null && (xtFile.hasError() || !xtFile.isValid())) return false; 116 116 return disabledExtensionPoints.getSetting(extensionPoint.getId()) == null; 117 117 } … … 121 121 { 122 122 if (extension == null) return false; 123 //ExtensionsFile extFile = directory.getFileByExtensionId(extension.getId());124 //if (extFile != null && (extFile.hasError() || !extFile.isValid())) return false;123 ExtensionsFile xtFile = manager.getFileByObjectKey(new ExtensionKey(extension)); 124 if (xtFile != null && (xtFile.hasError() || !xtFile.isValid())) return false; 125 125 return disabledExtensions.getSetting(extension.getId()) == null; 126 126 } … … 155 155 public synchronized void save() 156 156 { 157 if (!hasChanged ) return;157 if (!hasChanged || file == null) return; 158 158 try 159 159 { … … 166 166 throw new RuntimeException(ex); 167 167 } 168 hasChanged = true;168 hasChanged = false; 169 169 } 170 170 } -
trunk/src/core/net/sf/basedb/util/extensions/manager/processor/RegisterExtensionsProcessor.java
r5605 r5606 27 27 28 28 import net.sf.basedb.util.FileUtil; 29 import net.sf.basedb.util.extensions.Action;30 29 import net.sf.basedb.util.extensions.Extension; 31 30 import net.sf.basedb.util.extensions.ExtensionPoint; … … 122 121 FileData data = new FileData(); 123 122 data.writeableFile = wFile; 124 data.extensionPoints = new ArrayList<ExtensionPoint >(loader.getExtensionPoints());125 data.extensions = new ArrayList<Extension >(loader.getExtensions());123 data.extensionPoints = new ArrayList<ExtensionPoint<?>>(loader.getExtensionPoints()); 124 data.extensions = new ArrayList<Extension<?>>(loader.getExtensions()); 126 125 numFiles++; 127 126 log.info("Loaded " + data.extensionPoints.size() + "/" + data.extensions.size() + … … 309 308 { 310 309 results.addErrorMessage(xtFile, 311 "Could not register extension point s: " + ex.getMessage());310 "Could not register extension point(s): " + ex.getMessage()); 312 311 } 313 312 log.error("Could not register extension points from file: " + xtFile, ex); … … 350 349 { 351 350 results.addErrorMessage(xtFile, 352 "Could not register extension points: " + ex.getMessage());351 "Could not register extension(s): " + ex.getMessage()); 353 352 } 354 353 log.error("Could not register extension points from file: " + xtFile, ex); … … 402 401 { 403 402 int numRegistered = 0; 404 for (ExtensionPoint< Action> ep : data.extensionPoints)403 for (ExtensionPoint<?> ep : data.extensionPoints) 405 404 { 406 405 if (forceUpdate || !registry.extensionPointIsRegistered(ep.getId())) … … 441 440 { 442 441 int numRegistered = 0; 443 for (Extension< Action> ext : data.extensions)442 for (Extension<?> ext : data.extensions) 444 443 { 445 444 if (forceUpdate || !registry.extensionIsRegistered(ext.getId())) … … 503 502 { 504 503 WriteableExtensionsFile writeableFile; 505 List<Extension > extensions;506 List<ExtensionPoint > extensionPoints;504 List<Extension<?>> extensions; 505 List<ExtensionPoint<?>> extensionPoints; 507 506 } 508 507 -
trunk/src/core/net/sf/basedb/util/uri/ConnectionManagerUtil.java
r5599 r5606 37 37 import net.sf.basedb.util.extensions.Registry; 38 38 import net.sf.basedb.util.extensions.SingleExtensionFilter; 39 import net.sf.basedb.util.extensions.manager.ExtensionsManager; 39 40 40 41 /** … … 200 201 private static ExtensionsInvoker<ConnectionManagerFactory> getInvoker(ClientContext context, ExtensionsFilter filter) 201 202 { 202 Registry registry = Application.getExtensionsManager().getRegistry(); 203 ExtensionsManager manager = Application.getExtensionsManager(); 204 if (filter == null) filter = manager.getSettings(); 205 Registry registry = manager.getRegistry(); 203 206 return (ExtensionsInvoker<ConnectionManagerFactory>)registry.useExtensions(context, filter, EXTENSION_POINT_ID); 204 207 } -
trunk/www/admin/extensions/details.jsp
r5603 r5606 147 147 function enableFile(enable) 148 148 { 149 window.parent.frames['tree'].setChildIcons('<%=HTML.javaScriptEncode(file uri)%>', enable);149 window.parent.frames['tree'].setChildIcons('<%=HTML.javaScriptEncode(file != null ? file.getName() : "")%>', enable); 150 150 var url = 'index.jsp?ID=<%=ID%>&cmd=EnableFile'; 151 151 url += '&fileuri=<%=HTML.urlEncode(fileuri)%>'; -
trunk/www/admin/extensions/index.jsp
r5601 r5606 84 84 { 85 85 dc = sc.newDbControl(); 86 String file name = request.getParameter("filename");86 String fileuri = request.getParameter("fileuri"); 87 87 boolean enable = Values.getBoolean(request.getParameter("enable")); 88 88 ExtensionsControl ec = ExtensionsControl.get(dc); 89 ec.enableAllInFile(file name, enable);89 ec.enableAllInFile(fileuri, enable); 90 90 ec.saveSettings(); 91 redirect = "details.jsp?ID=" + ID + "&file name=" + HTML.urlEncode(filename);91 redirect = "details.jsp?ID=" + ID + "&fileuri=" + HTML.urlEncode(fileuri); 92 92 } 93 93 else if ("ManualScan".equals(cmd))
Note: See TracChangeset
for help on using the changeset viewer.