Changeset 4207
- Timestamp:
- Apr 4, 2008, 2:44:51 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 22 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/AbstractJspActionFactory.java
r4198 r4207 26 26 import net.sf.basedb.util.extensions.Action; 27 27 import net.sf.basedb.util.extensions.ActionFactory; 28 import net.sf.basedb.util.extensions.Context; 29 import net.sf.basedb.util.extensions.Extension; 28 import net.sf.basedb.util.extensions.InvokationContext; 30 29 31 30 /** … … 39 38 be propagated to the {@link JspContext#addScript(String)} 40 39 and {@link JspContext#addStylesheet(String)} methods in 41 the {@link #prepareContext( Context, Extension)}.40 the {@link #prepareContext(InvokationContext)}. 42 41 43 42 @author nicklas … … 68 67 */ 69 68 @Override 70 public boolean prepareContext( Context context, Extension<? super A> extension)69 public boolean prepareContext(InvokationContext<? super A> context) 71 70 { 72 prepareContext((JspContext)context );71 prepareContext((JspContext)context.getClientContext()); 73 72 return true; 74 73 } -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/AbstractJspRendererFactory.java
r4198 r4207 25 25 26 26 import net.sf.basedb.util.extensions.Action; 27 import net.sf.basedb.util.extensions.Context; 28 import net.sf.basedb.util.extensions.Extension; 27 import net.sf.basedb.util.extensions.InvokationContext; 29 28 import net.sf.basedb.util.extensions.RendererFactory; 30 29 … … 39 38 be propagated to the {@link JspContext#addScript(String)} 40 39 and {@link JspContext#addStylesheet(String)} methods in 41 the {@link #prepareContext( Context, Extension)}.40 the {@link #prepareContext(InvokationContext)}. 42 41 43 42 @author nicklas … … 66 65 */ 67 66 @Override 68 public void prepareContext( Context context, Extension<? extends A> extension)67 public void prepareContext(InvokationContext<? extends A> context) 69 68 { 70 prepareContext((JspContext)context );69 prepareContext((JspContext)context.getClientContext()); 71 70 } 72 71 // ---------------------------------- -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsControl.java
r4202 r4207 182 182 Extension points that are not found are ignored. 183 183 @return An invoker instance 184 @see Registry#useExtensions(net.sf.basedb.util.extensions.C ontext, net.sf.basedb.util.extensions.ExtensionsFilter, String...)184 @see Registry#useExtensions(net.sf.basedb.util.extensions.ClientContext, net.sf.basedb.util.extensions.ExtensionsFilter, String...) 185 185 */ 186 186 public static ExtensionsInvoker<?> useExtensions(JspContext context, String...extensionPoints) -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsDirectory.java
r4202 r4207 333 333 numDeleted++; 334 334 } 335 catch ( Exceptionex)335 catch (Throwable ex) 336 336 { 337 337 extFile.setError(true); … … 482 482 } 483 483 } 484 catch ( Exceptionex)484 catch (Throwable ex) 485 485 { 486 486 extFile.setError(true); … … 528 528 } 529 529 } 530 catch ( Exceptionex)530 catch (Throwable ex) 531 531 { 532 532 extFile.setError(true); … … 561 561 } 562 562 } 563 catch ( Exceptionex)563 catch (Throwable ex) 564 564 { 565 565 extFile.setError(true); … … 580 580 results.addMessage(extFile, num + " extensions registered."); 581 581 } 582 catch ( Exceptionex)582 catch (Throwable ex) 583 583 { 584 584 extFile.setError(true); -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/JspContext.java
r4202 r4207 33 33 import net.sf.basedb.core.SessionControl; 34 34 import net.sf.basedb.util.extensions.ActionFactory; 35 import net.sf.basedb.util.extensions.C ontext;35 import net.sf.basedb.util.extensions.ClientContext; 36 36 import net.sf.basedb.util.extensions.Extension; 37 import net.sf.basedb.util.extensions.InvokationContext; 37 38 import net.sf.basedb.util.extensions.RendererFactory; 38 39 39 40 /** 40 41 Context object for the web application. Instances of this class 41 are always used for passing c ontext information to web extensions.42 This means that it is always safe to cast the c ontext to this43 class in the {@link ActionFactory#prepareContext( Context, Extension)}44 and {@link ActionFactory#getActions( Context, Extension)} methods42 are always used for passing client context information to web extensions. 43 This means that it is always safe to cast the client context to this 44 class in the {@link ActionFactory#prepareContext(InvokationContext)} 45 and {@link ActionFactory#getActions(InvokationContext)} methods 45 46 and other methods that has a context parameter. 46 47 47 48 <pre class="code"> 48 49 @Override 49 public boolean prepareContext( Context context, Extension extension)50 public boolean prepareContext(InvokationContext context) 50 51 { 51 JspContext jspContext = (JspContext)context ;52 JspContext jspContext = (JspContext)context.getClientContext(); 52 53 jspContext.addStylesheet("/base/include/styles/mystylesheet.css"); 53 54 // Do other things … … 68 69 */ 69 70 public class JspContext 70 extends C ontext71 extends ClientContext 71 72 { 72 73 … … 100 101 Note! The writer is only intended to be used by render 101 102 objects when rendering the extensions. Using the writer 102 from the ActionFactory#prepareContext(Context, Extension)} or103 {@link RendererFactory#prepareContext( Context, Extension)}103 from the {@link ActionFactory#prepareContext(InvokationContext)} or 104 {@link RendererFactory#prepareContext(InvokationContext)} 104 105 method may produce unpredictable results. 105 106 … … 138 139 <p> 139 140 Note 1! This method must be called from the {@link 140 ActionFactory#prepareContext( Context, Extension)} or141 {@link RendererFactory#prepareContext( Context, Extension)}141 ActionFactory#prepareContext(InvokationContext)} or 142 {@link RendererFactory#prepareContext(InvokationContext)} 142 143 methods. Changes to the context after that will not be reflected 143 144 in the output. … … 162 163 <p> 163 164 Note 1! This method must be called from the {@link 164 ActionFactory#prepareContext( Context, Extension)} or165 {@link RendererFactory#prepareContext( Context, Extension)}165 ActionFactory#prepareContext(InvokationContext)} or 166 {@link RendererFactory#prepareContext(InvokationContext)} 166 167 methods. Changes to the context after that will not be reflected 167 168 in the output. -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/Settings.java
r4202 r4207 53 53 This class also implements the {@link ExtensionsFilter} 54 54 interface, and can be used on the 55 {@link Registry#useExtensions(net.sf.basedb.util.extensions.C ontext, ExtensionsFilter, String...)}55 {@link Registry#useExtensions(net.sf.basedb.util.extensions.ClientContext, ExtensionsFilter, String...)} 56 56 method. This means that disabling/enabling extensions and extension points 57 57 will immediately be visible in the web interface. Sorting is delegated -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/menu/FixedMenuItemFactory.java
r4198 r4207 26 26 import net.sf.basedb.clients.web.extensions.AbstractJspActionFactory; 27 27 import net.sf.basedb.util.Values; 28 import net.sf.basedb.util.extensions.Context; 29 import net.sf.basedb.util.extensions.Extension; 28 import net.sf.basedb.util.extensions.InvokationContext; 30 29 import net.sf.basedb.util.extensions.xml.PathSetter; 31 30 import net.sf.basedb.util.extensions.xml.VariableSetter; … … 40 39 the properties. Changes to the properties are immediately 41 40 visible in the menu items returned from the 42 {@link #getActions( Context, Extension)} method.41 {@link #getActions(InvokationContext)} method. 43 42 44 43 @author nicklas … … 78 77 */ 79 78 @Override 80 public MenuItemAction[] getActions(Context context, 81 Extension<? super MenuItemAction> extension) 79 public MenuItemAction[] getActions(InvokationContext<? super MenuItemAction> context) 82 80 { 83 81 return actions; -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/menu/PermissionMenuItemFactory.java
r4198 r4207 29 29 import net.sf.basedb.core.Permission; 30 30 import net.sf.basedb.core.SessionControl; 31 import net.sf.basedb.util.extensions.Context; 32 import net.sf.basedb.util.extensions.Extension; 31 import net.sf.basedb.util.extensions.InvokationContext; 33 32 import net.sf.basedb.util.extensions.xml.PathSetter; 34 33 import net.sf.basedb.util.extensions.xml.VariableSetter; … … 50 49 51 50 If the menu item is hidden this is indicated by returning 52 false from the {@link #prepareContext( Context, Extension)} method. Most51 false from the {@link #prepareContext(InvokationContext)} method. Most 53 52 properties can have different values for the enabled/disabled state. 54 53 For example: … … 102 101 */ 103 102 @Override 104 public MenuItemAction[] getActions( Context context, Extension<? super MenuItemAction> extension)105 { 106 SessionControl sc = context.get SessionControl();103 public MenuItemAction[] getActions(InvokationContext<? super MenuItemAction> context) 104 { 105 SessionControl sc = context.getClientContext().getSessionControl(); 107 106 MenuItemAction action = null; 108 107 if (!hasPermission(sc, visiblePermission)) … … 127 126 128 127 @Override 129 public boolean prepareContext( Context context, Extension<? super MenuItemAction> extension)130 { 131 SessionControl sc = context.get SessionControl();128 public boolean prepareContext(InvokationContext<? super MenuItemAction> context) 129 { 130 SessionControl sc = context.getClientContext().getSessionControl(); 132 131 boolean isEnabled = hasPermission(sc, visiblePermission); 133 return isEnabled && super.prepareContext(context , extension);132 return isEnabled && super.prepareContext(context); 134 133 } 135 134 // ------------------------------------ -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/toolbar/CompactButtonRendererFactory.java
r4202 r4207 26 26 import net.sf.basedb.clients.web.extensions.AbstractJspRendererFactory; 27 27 import net.sf.basedb.clients.web.extensions.JspContext; 28 import net.sf.basedb.util.extensions.Context; 29 import net.sf.basedb.util.extensions.Extension; 28 import net.sf.basedb.util.extensions.InvokationContext; 30 29 31 30 /** … … 45 44 46 45 @Override 47 public CompactButtonRenderer getRenderer( Context context, Extension extension)46 public CompactButtonRenderer getRenderer(InvokationContext context) 48 47 { 49 return new CompactButtonRenderer((JspContext)context );48 return new CompactButtonRenderer((JspContext)context.getClientContext()); 50 49 } 51 50 -
trunk/src/clients/web/net/sf/basedb/clients/web/extensions/toolbar/FixedButtonFactory.java
r4202 r4207 26 26 import net.sf.basedb.clients.web.extensions.AbstractJspActionFactory; 27 27 import net.sf.basedb.util.Values; 28 import net.sf.basedb.util.extensions.Context; 29 import net.sf.basedb.util.extensions.Extension; 28 import net.sf.basedb.util.extensions.InvokationContext; 30 29 import net.sf.basedb.util.extensions.xml.PathSetter; 31 30 import net.sf.basedb.util.extensions.xml.VariableSetter; … … 38 37 The button is by default both visible and enabled. Use the setter 39 38 method to change the properties. Changes to the properties are immediately 40 visible in the menu items returned from the {@link #getActions( Context, Extension)}39 visible in the menu items returned from the {@link #getActions(InvokationContext)} 41 40 method. 42 41 <p> … … 84 83 */ 85 84 @Override 86 public ButtonAction[] getActions( Context context, Extension extension)85 public ButtonAction[] getActions(InvokationContext context) 87 86 { 88 87 return actions; -
trunk/src/core/net/sf/basedb/util/extensions/ActionFactory.java
r4198 r4207 69 69 </ul> 70 70 71 @param context The current context to prepare 72 @param extension The extension to use 71 @param context The current invokation context 73 72 @return TRUE if the extension should be enabled, 74 73 FALSE if the extension should be disabled 75 74 */ 76 public boolean prepareContext( Context context, Extension<? super A> extension);75 public boolean prepareContext(InvokationContext<? super A> context); 77 76 78 77 /** … … 85 84 the extension point, including the current item, if any. 86 85 87 @param context The current context 88 @param extension The extension to create actions for 86 @param context The current invokation context 89 87 @return An array of actions that should be added to the extension point. 90 88 Returns null or an empty array if there are no actions in the current context. 91 89 */ 92 public A[] getActions( Context context, Extension<? super A> extension);90 public A[] getActions(InvokationContext<? super A> context); 93 91 94 92 } -
trunk/src/core/net/sf/basedb/util/extensions/ActionIterator.java
r4198 r4207 24 24 package net.sf.basedb.util.extensions; 25 25 26 import java.util.IdentityHashMap;27 26 import java.util.Iterator; 28 import java.util.Map;29 27 import java.util.NoSuchElementException; 30 28 31 import net.sf.basedb.util.extensions.Registry.RegisteredExtension;32 import net.sf.basedb.util.extensions.Registry.RegisteredExtensionPoint;33 29 34 30 /** 35 31 Iterator for iterating over all actions that <b>will be 36 32 created</b> by extensions after a call to {@link 37 Registry#useExtensions(C ontext, ExtensionsFilter, String...)}.33 Registry#useExtensions(ClientContext, ExtensionsFilter, String...)}. 38 34 That method returns an {@link ExtensionsInvoker} object which 39 35 in it's turn uses this iterator. … … 44 40 next item. This happens in the {@link #hasNext()} method, which, 45 41 for each extension, calls {@link Extension#getActionFactory()} 46 and then {@link ActionFactory#getActions( Context, Extension)}.42 and then {@link ActionFactory#getActions(InvokationContext)}. 47 43 48 44 <p> … … 62 58 63 59 // The current context 64 private final Context context;60 private InvokationContext<A> currentContext; 65 61 66 62 // An iterator over all usable extensions 67 private final Iterator< RegisteredExtension<A>> iterator;63 private final Iterator<InvokationContext<A>> iterator; 68 64 69 65 // The actions created by the current extension … … 71 67 // The iterator's offset in the actions array 72 68 private int offset; 73 74 // The currently active extension75 private RegisteredExtension<A> currentExtension;76 77 // The renderer for the current action78 private Renderer<? super A> currentRenderer;79 80 // Cache for created renderers81 private Map<Object, Renderer<? super A>> rendererCache;82 69 83 70 // Boolean flags to indicate if we have a next element and if … … 87 74 88 75 89 ActionIterator( Context context, Iterator<RegisteredExtension<A>> iterator)76 ActionIterator(Iterator<InvokationContext<A>> iterator) 90 77 { 91 this.context = context;92 78 this.iterator = iterator; 93 79 this.checkNext = true; 94 this.rendererCache = new IdentityHashMap<Object, Renderer<? super A>>();80 // this.rendererCache = new IdentityHashMap<Object, Renderer<? super A>>(); 95 81 } 96 82 /* … … 112 98 { 113 99 // No more actions in the array, move on to the next extension 114 currentExtension = null; 115 currentRenderer = null; 100 currentContext = null; 116 101 actions = null; 117 102 offset = 0; … … 122 107 while (iterator.hasNext()) 123 108 { 124 currentExtension = iterator.next(); 109 currentContext = iterator.next(); 110 125 111 // Get the actions for the extension 126 actions = current Extension.getActionFactory().getActions(context, currentExtension);112 actions = currentContext.getActions(); 127 113 if (actions != null && actions.length > 0) 128 114 { … … 158 144 public Extension<? extends A> getExtension() 159 145 { 160 return current Extension;146 return currentContext.getExtension(); 161 147 } 162 148 … … 166 152 Renderer<? super A> getRenderer() 167 153 { 168 if (currentRenderer == null) 169 { 170 RegisteredExtensionPoint<? super A> ep = currentExtension.getExtensionPoint(); 171 RendererFactory<? super A> rf = currentExtension.getRendererFactory(); 172 if (ep.allowRendererOverride() && rf != null) 173 { 174 // Use the extension's renderer factory if it is 175 // allowed and if one is provided 176 currentRenderer = rf.getRenderer(context, currentExtension); 177 } 178 else 179 { 180 // We must use the extensions points renderer factory 181 // First, check the cache if we already have a renderer 182 currentRenderer = rendererCache.get(ep); 183 if (currentRenderer == null) 184 { 185 currentRenderer = ep.getRendererFactory().getRenderer(context, currentExtension); 186 rendererCache.put(ep, currentRenderer); 187 } 188 } 189 } 190 return currentRenderer; 154 return currentContext.getRenderer(); 191 155 } 192 156 } -
trunk/src/core/net/sf/basedb/util/extensions/ClientContext.java
r4205 r4207 30 30 31 31 /** 32 Keeps information about the current context that33 extensions can use to decide what actions to generate.34 It is, for example, possible to check the permissions32 Keeps information about the current context in the client 33 application that extensions can use to decide what actions to 34 generate. It is, for example, possible to check the permissions 35 35 of logged in user and enable/disable certain actions 36 36 if a condition is not met. Or, the extension may inspect … … 41 41 The current context is passed to an {@link ActionFactory} twice, first 42 42 to check if an extension should be enabled or not 43 with the {@link ActionFactory#prepareContext( Context, Extension)}43 with the {@link ActionFactory#prepareContext(InvokationContext)} 44 44 method. This method also allows an extension to write 45 45 back information to the context. This may, for example, … … 50 50 <p> 51 51 The second time is when calling the {@link 52 ActionFactory#getActions( Context, Extension)} method. This method can52 ActionFactory#getActions(InvokationContext)} method. This method can 53 53 be called multiple times. For example, if an extension point 54 54 is in a list context, the <code>getActions</code> method may … … 65 65 @base.modified $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $ 66 66 */ 67 public class C ontext67 public class ClientContext 68 68 { 69 69 … … 77 77 @param sc The current session 78 78 */ 79 public C ontext(SessionControl sc)79 public ClientContext(SessionControl sc) 80 80 { 81 81 this.sc = sc; … … 89 89 @param item The current item 90 90 */ 91 public C ontext(SessionControl sc, Object item)91 public ClientContext(SessionControl sc, Object item) 92 92 { 93 93 this.sc = sc; -
trunk/src/core/net/sf/basedb/util/extensions/DefaultFilter.java
r4198 r4207 43 43 44 44 /** 45 Comparator used to order extensions by their index value. 45 Comparator used to order a list of invokation contexts by 46 the index value of the extension. 46 47 @see Extension#getIndex() 47 48 */ 48 public static final Comparator<Extension<?>> INDEX_COMPARATOR = 49 public static final Comparator<InvokationContext<?>> INDEX_COMPARATOR_CTX = 50 new Comparator<InvokationContext<?>>() 51 { 52 @Override 53 public int compare(InvokationContext<?> o1, InvokationContext<?> o2) 54 { 55 return Float.compare(o1.getExtension().getIndex(), o2.getExtension().getIndex()); 56 } 57 }; 58 59 /** 60 Comparator used to order a list of extensions by 61 the index value of the extension. 62 @see Extension#getIndex() 63 */ 64 public static final Comparator<Extension<?>> INDEX_COMPARATOR_EXT = 49 65 new Comparator<Extension<?>>() 50 66 { … … 55 71 } 56 72 }; 57 73 58 74 /** 59 75 Create a new default filter. … … 79 95 80 96 @Override 81 public void sort(List<? extends Extension<?>> extensions)97 public void sort(List<? extends InvokationContext<?>> extensions) 82 98 { 83 Collections.sort(extensions, INDEX_COMPARATOR );99 Collections.sort(extensions, INDEX_COMPARATOR_CTX); 84 100 } 85 101 // -------------------------------------------------- -
trunk/src/core/net/sf/basedb/util/extensions/ExtensionPoint.java
r4187 r4207 1 1 /** 2 $Id $2 $Id:ExtensionPoint.java 4187 2008-03-20 11:15:25Z nicklas $ 3 3 4 4 Copyright (C) Authors contributing to this file. … … 51 51 {@link Registry#registerExtension(Extension)}. To load and use all 52 52 registered extensions use 53 {@link Registry#useExtensions(C ontext, ExtensionsFilter, String...)}.53 {@link Registry#useExtensions(ClientContext, ExtensionsFilter, String...)}. 54 54 55 55 @author nicklas 56 56 @version 2.7 57 @base.modified $Date $57 @base.modified $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $ 58 58 @see ExtensionPointBean 59 59 @see XmlLoader -
trunk/src/core/net/sf/basedb/util/extensions/ExtensionsFilter.java
r4187 r4207 29 29 Allows extensions and extension points to be enabled/disabled 30 30 and sorted externally. An object of this class is used by the 31 {@link Registry#useExtensions(C ontext, ExtensionsFilter, String...)}31 {@link Registry#useExtensions(ClientContext, ExtensionsFilter, String...)} 32 32 method. 33 33 34 34 @author nicklas 35 35 @version 2.7 36 @base.modified $Date $36 @base.modified $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $ 37 37 */ 38 38 public interface ExtensionsFilter … … 56 56 57 57 /** 58 Sort a list of extensions according to some property.58 Sort a list of invoked extensions according to some property. 59 59 @param extensions The list of extensions to sort 60 60 */ 61 public void sort(List<? extends Extension<?>> extensions);61 public void sort(List<? extends InvokationContext<?>> extensions); 62 62 63 63 } -
trunk/src/core/net/sf/basedb/util/extensions/ExtensionsInvoker.java
r4187 r4207 1 1 /** 2 $Id $2 $Id:ExtensionsInvoker.java 4187 2008-03-20 11:15:25Z nicklas $ 3 3 4 4 Copyright (C) Authors contributing to this file. … … 27 27 import java.util.Iterator; 28 28 29 import net.sf.basedb.util.extensions.Registry.RegisteredExtension;30 31 32 29 /** 33 30 Object of this class handles a single invokation of the extensions 34 31 for one or several extension points. Call 35 {@link Registry#useExtensions(C ontext, ExtensionsFilter, String...)}32 {@link Registry#useExtensions(ClientContext, ExtensionsFilter, String...)} 36 33 to create an invoker object. With this object you can 37 34 {@link #iterate()} over all actions created by the extensions, or … … 55 52 @author nicklas 56 53 @version 2.7 57 @base.modified $Date $54 @base.modified $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $ 58 55 */ 59 56 public class ExtensionsInvoker<A extends Action> 60 57 { 61 58 62 final Collection<RegisteredExtension<A>> extensions; 63 final Context context; 64 private RendererFactory<A> currentRenderFactory; 59 final Collection<InvokationContext<A>> contexts; 65 60 66 61 /** 67 62 Creates a new invoker object. 68 63 */ 69 ExtensionsInvoker(Collection< RegisteredExtension<A>> extensions, Context context)64 ExtensionsInvoker(Collection<InvokationContext<A>> contexts) 70 65 { 71 this.extensions = extensions; 72 this.context = context; 66 this.contexts = contexts; 73 67 } 74 68 … … 81 75 public ActionIterator<A> iterate() 82 76 { 83 return new ActionIterator<A>(context , extensions.iterator());77 return new ActionIterator<A>(contexts.iterator()); 84 78 } 85 79 -
trunk/src/core/net/sf/basedb/util/extensions/Registry.java
r4202 r4207 319 319 /** 320 320 Get an iterator returning all registered extensions 321 for a given extension point. 321 for a given extension point. If the extension point is not found 322 322 an empty iterator is returned. The returned iterator doesn't 323 323 support removal and will not reflect changes made to the registry … … 341 341 List<Extension<?>> copy = 342 342 new ArrayList<Extension<?>>(rep.getExtensions()); 343 Collections.sort(copy, DefaultFilter.INDEX_COMPARATOR );343 Collections.sort(copy, DefaultFilter.INDEX_COMPARATOR_EXT); 344 344 return Collections.unmodifiableList(copy).iterator(); 345 345 } … … 358 358 get a chance to check the context object and to further initialise it 359 359 with extension-dependent information. This is a task for the 360 {@link ActionFactory#prepareContext( Context, Extension)} method. If this method360 {@link ActionFactory#prepareContext(InvokationContext)} method. If this method 361 361 returns false the extension will not be included in the invoker. Extensions 362 362 may for example use this to check if the logged in user has enough permissions … … 365 365 <p> 366 366 If the extension points and/or extensions also provide renderer factories, 367 the {@link RendererFactory#prepareContext( Context, Extension)} is called.367 the {@link RendererFactory#prepareContext(InvokationContext)} is called. 368 368 For renderer factories that are attached to extension points the method 369 369 is only called if at least one enabled extension exists. If the method is … … 378 378 an extension point should call this method to get a new invoker object. 379 379 380 @param c ontext Information about the current context380 @param clientContext Information about the current context 381 381 @param filter A filter object that can be used to filter out 382 382 disabled extensions and sort the extensions in a particular order. … … 390 390 */ 391 391 @SuppressWarnings("unchecked") 392 public ExtensionsInvoker<?> useExtensions(C ontext context, ExtensionsFilter filter,392 public ExtensionsInvoker<?> useExtensions(ClientContext clientContext, ExtensionsFilter filter, 393 393 String... extensionPointIds) 394 394 { 395 395 if (filter == null) filter = DEFAULT_FILTER; 396 List<RegisteredExtension<Action>> use = new LinkedList<RegisteredExtension<Action>>(); 396 397 List<InvokationContext<Action>> contexts = new LinkedList<InvokationContext<Action>>(); 397 398 for (String id : extensionPointIds) 398 399 { … … 400 401 RegisteredExtensionPoint<Action> rep = 401 402 (RegisteredExtensionPoint<Action>)extensionPoints.get(id); 402 if (rep != null && filter.isEnabled(rep)) 403 404 // Is there an enabled extension point? 405 if (rep == null || !filter.isEnabled(rep)) continue; 406 407 // YES! ... 408 ExtensionPointContext<Action> mainContext = 409 new ExtensionPointContext<Action>(this, clientContext, rep); 410 boolean allowRenderOverride = rep.allowRendererOverride(); 411 int enabledExtensions = 0; 412 413 // ... find the extensions for it 414 for (RegisteredExtension<Action> ext : rep.getExtensions()) 403 415 { 404 // The extension point is enabled... 405 boolean allowRenderOverride = rep.allowRendererOverride(); 406 int enabledExtensions = 0; 407 // ... find the extensions for it 408 for (RegisteredExtension<Action> ext : rep.getExtensions()) 409 { 410 // Check with the filter if the extension is enabled... 411 // ... and check with the action factory as well 412 if (filter.isEnabled(ext) && ext.getActionFactory().prepareContext(context, ext)) 413 { 414 use.add(ext); 415 enabledExtensions++; 416 // Prepare the renderer factory if it is allowed and there is one 417 if (allowRenderOverride) 418 { 419 RendererFactory<? super Action> factory = ext.getRendererFactory(); 420 if (factory != null) factory.prepareContext(context, ext); 421 } 422 } 423 } 424 // Prepare the renderer factory if there is at least one extension 425 RendererFactory<? super Action> factory = rep.getRendererFactory(); 426 if (enabledExtensions > 0 && factory != null) 427 { 428 factory.prepareContext(context, null); 429 } 416 // Check with the filter if the extension is enabled 417 if (!filter.isEnabled(ext)) continue; 418 419 // Create invokation context for the extension 420 ExtensionContext<Action> context = 421 new ExtensionContext<Action>(mainContext, ext); 422 423 // Check with the action factory as well 424 if (!context.prepareActionFactory()) continue; 425 426 // Yippi, this extension is enabled!!! 427 if (allowRenderOverride) context.prepareRendererFactory(); 428 contexts.add(context); 429 enabledExtensions++; 430 430 } 431 } 431 432 // Prepare the renderer factory for the extension point 433 // if there is at least one enabled extension 434 if (enabledExtensions > 0) mainContext.prepareRendererFactory(); 435 } 436 432 437 // Sort the extensions 433 filter.sort( use);434 return new ExtensionsInvoker<Action>( use, context);438 filter.sort(contexts); 439 return new ExtensionsInvoker<Action>(contexts); 435 440 } 436 441 437 442 /** 438 443 Default filter implementation for 439 {@link #useExtensions(C ontext, ExtensionsFilter, String...)}444 {@link #useExtensions(ClientContext, ExtensionsFilter, String...)} 440 445 */ 441 446 private static final ExtensionsFilter DEFAULT_FILTER = new DefaultFilter(); -
trunk/src/core/net/sf/basedb/util/extensions/RendererFactory.java
r4198 r4207 66 66 <p> 67 67 Note! This method has no return value as opposed to 68 {@link ActionFactory#prepareContext( Context, Extension)}. The68 {@link ActionFactory#prepareContext(InvokationContext)}. The 69 69 simple reason is that once we get to the point of rendering it 70 70 is already known that the extension is enabled. 71 71 72 @param context The current context to prepare 73 @param extension The extension to use, or null if this 74 factory is used from an extension point 72 @param context The current invokation context 75 73 */ 76 public void prepareContext( Context context, Extension<? extends A> extension);74 public void prepareContext(InvokationContext<? extends A> context); 77 75 78 76 /** … … 82 80 multiple threads may use the same renderer. 83 81 84 @param context The current context 85 @param extension The extension to create a renderer for 82 @param context The current invokation context 86 83 @return A renderer instance 87 84 */ 88 public Renderer<? super A> getRenderer( Context context, Extension<? extends A> extension);85 public Renderer<? super A> getRenderer(InvokationContext<? extends A> context); 89 86 90 87 } -
trunk/src/core/net/sf/basedb/util/extensions/xml/XmlLoader.java
r4202 r4207 91 91 </pre> 92 92 93 The setter methods must be public and accept a single <code>String</code> parameter. 93 The setter methods must be public and accept a single <code>String</code> 94 parameter. 95 <p> 96 97 The loader also looks for the <code>setParameter(String, String)</code> 98 method signature. If the method exists it will be called for each 99 parameter found with the tagname as the first parameter and the 100 value as the second parameter. Ccontinuing the above example: 101 102 <pre class="code"> 103 factory.setParameter("image", "button.png"); 104 factory.setParameter("title", "Click button"); 105 </pre> 106 107 <p> 94 108 Tags that doesn't have a corresponding setter method are simply ignored. 95 109 The XML file format allows any tags as parameters, but only the first level … … 651 665 factoryParameters.put(bean, xmlOut.outputString(root)); 652 666 667 // Check for generic setParameter(String, String) method 668 Method setParameter = getSetParameterMethod(beanClass); 669 653 670 // List all child tags 654 671 for (Element child : parameters) … … 661 678 if (value == null) continue; 662 679 680 // Call generic setParmeter(String, String) method 681 if (setParameter != null) 682 { 683 try 684 { 685 setParameter.invoke(bean, childName, value); 686 } 687 catch (IllegalAccessException ex) 688 {} 689 catch (InvocationTargetException ex) 690 {} 691 } 692 663 693 Method setter = getSetterMethod(beanClass, childName); 664 694 if (setter == null) continue; … … 689 719 @param beanClass The class to look for the setter method in 690 720 @param tagName The tag name in the XML file 691 @return A Method object or null,if no method is found721 @return A Method object, or null if no method is found 692 722 */ 693 723 protected Method getSetterMethod(Class<?> beanClass, String tagName) … … 705 735 706 736 /** 737 Check if the bean class has a <code>setParameter(String, String)</code> 738 method and return it's reference if it has. 739 @param beanClass The class to look for the method in 740 @return A Method object, or null if no method is found 741 */ 742 protected Method getSetParameterMethod(Class<?> beanClass) 743 { 744 Method setParameter = null; 745 try 746 { 747 setParameter = beanClass.getMethod("setParameter", String.class, String.class); 748 } 749 catch (NoSuchMethodException ex) 750 {} 751 return setParameter; 752 753 } 754 755 /** 707 756 Convert the tag name to a setter method name. 708 757 @param tagName The tag name -
trunk/src/test/TestExtensions.java
r4198 r4207 26 26 27 27 import net.sf.basedb.core.BaseException; 28 import net.sf.basedb.util.Values; 28 29 import net.sf.basedb.util.extensions.Action; 29 30 import net.sf.basedb.util.extensions.ActionFactory; 30 import net.sf.basedb.util.extensions.C ontext;31 import net.sf.basedb.util.extensions.ClientContext; 31 32 import net.sf.basedb.util.extensions.Extension; 32 33 import net.sf.basedb.util.extensions.ExtensionPoint; 33 34 import net.sf.basedb.util.extensions.ExtensionsInvoker; 35 import net.sf.basedb.util.extensions.InvokationContext; 34 36 import net.sf.basedb.util.extensions.Registry; 35 37 import net.sf.basedb.util.extensions.Renderer; 36 38 import net.sf.basedb.util.extensions.RendererFactory; 39 import net.sf.basedb.util.extensions.xml.PathSetter; 37 40 import net.sf.basedb.util.extensions.xml.VariableConverter; 38 41 import net.sf.basedb.util.extensions.xml.VariableSetter; … … 60 63 61 64 test_load_extension_points_from_xml(registry, "data/test.extensions.xml", 1); 62 test_load_extensions_from_xml(registry, "data/test.extensions.xml", 2);65 test_load_extensions_from_xml(registry, "data/test.extensions.xml", 3); 63 66 64 67 test_render_default(registry, "test.tools"); … … 164 167 try 165 168 { 166 C ontext context = newContext(TestUtil.getSessionControl());169 ClientContext clientContext = new ClientContext(TestUtil.getSessionControl()); 167 170 ExtensionsInvoker<ActionButton> manager = 168 (ExtensionsInvoker<ActionButton>)registry.useExtensions(c ontext, null, extensionPoint);171 (ExtensionsInvoker<ActionButton>)registry.useExtensions(clientContext, null, extensionPoint); 169 172 170 173 manager.renderDefault(); … … 181 184 } 182 185 186 public interface IActionButton 187 extends Action 188 { 189 190 public String getTitle(); 191 192 public String getIcon(); 193 194 public int getType(); 195 196 public boolean isDisabled(); 197 198 } 199 183 200 public static class ActionButton 184 implements Action201 implements IActionButton 185 202 { 186 203 private final String title; 187 204 private final String icon; 188 189 public ActionButton(String title, String icon) 205 private final int type; 206 private final boolean disabled; 207 208 public ActionButton(String title, String icon, int type, boolean disabled) 190 209 { 191 210 this.title = title; 192 211 this.icon = icon; 212 this.type = type; 213 this.disabled = disabled; 193 214 } 194 215 … … 202 223 return icon; 203 224 } 225 226 public int getType() 227 { 228 return type; 229 } 230 231 public boolean isDisabled() 232 { 233 return disabled; 234 } 204 235 } 205 236 206 237 public static class ActionButtonFactory 207 implements ActionFactory< ActionButton>238 implements ActionFactory<IActionButton> 208 239 { 209 240 210 241 private String title; 211 242 private String icon; 212 private ActionButton button; 243 private int type; 244 private boolean disabled; 245 246 private IActionButton button; 213 247 214 248 public ActionButtonFactory() … … 216 250 217 251 @Override 218 public ActionButton[] getActions(Context context, Extension<? super ActionButton> extension)252 public IActionButton[] getActions(InvokationContext<? super IActionButton> context) 219 253 { 220 254 if (button == null) 221 255 { 222 button = new ActionButton(title, icon );223 } 224 return new ActionButton[] { button };225 } 226 227 @Override 228 public boolean prepareContext( Context context, Extension<? super ActionButton> extension)256 button = new ActionButton(title, icon, type, disabled); 257 } 258 return new IActionButton[] { button }; 259 } 260 261 @Override 262 public boolean prepareContext(InvokationContext<? super IActionButton> context) 229 263 { 230 264 return true; … … 237 271 238 272 @VariableSetter 273 @PathSetter 239 274 public void setIcon(String icon) 240 275 { … … 242 277 } 243 278 279 public void setType(String type) 280 { 281 this.type = Values.getInt(type); 282 } 283 284 public void setDisabled(String disabled) 285 { 286 this.disabled = Values.getBoolean(disabled); 287 } 288 244 289 } 245 290 246 291 public static class ActionButtonRendererFactory 247 implements RendererFactory< ActionButton>, Renderer<ActionButton>292 implements RendererFactory<IActionButton>, Renderer<IActionButton> 248 293 { 249 294 … … 259 304 260 305 @Override 261 public void prepareContext( Context context, Extension<? extends ActionButton> extension)262 { 263 } 264 265 @Override 266 public Renderer< ActionButton> getRenderer(Context context, Extension<? extends ActionButton> extension)306 public void prepareContext(InvokationContext<? extends IActionButton> context) 307 { 308 } 309 310 @Override 311 public Renderer<IActionButton> getRenderer(InvokationContext<? extends IActionButton> context) 267 312 { 268 313 return this; … … 270 315 271 316 @Override 272 public void render( ActionButton action)273 { 274 if (!TestUtil.getSilent() )317 public void render(IActionButton action) 318 { 319 if (!TestUtil.getSilent() && !action.isDisabled()) 275 320 { 276 321 System.out.println("<div class=\"actionbutton\" style=\"color: " + 277 322 color + ";\"><img src=\"" + action.getIcon() + "\">" + 278 action.getTitle() + " </div>");323 action.getTitle() + " (type=" + action.getType() + ")</div>"); 279 324 } 280 325 } -
trunk/src/test/data/test.extensions.xml
r4187 r4207 30 30 id="test.tools" 31 31 > 32 <action-class>TestExtensions$ ActionButton</action-class>32 <action-class>TestExtensions$IActionButton</action-class> 33 33 <renderer-factory override="true"> 34 34 <factory-class>TestExtensions$ActionButtonRendererFactory</factory-class> … … 49 49 <title>Launch MeV</title> 50 50 <icon>$HOME$/images/mev.png</icon> 51 <type>11</type> 51 52 </parameters> 52 53 </action-factory> … … 73 74 </extension> 74 75 76 <extension 77 id="test.tools.proxy" 78 extends="test.tools" 79 > 80 <index>15</index> 81 <action-factory> 82 <factory-class>net.sf.basedb.util.extensions.debug.ProxyActionFactory</factory-class> 83 <parameters> 84 <title>Using proxy</title> 85 <icon>~/proxy.png</icon> 86 <type>2</type> 87 <disabled>false</disabled> 88 </parameters> 89 </action-factory> 90 </extension> 91 75 92 </extensions> -
trunk/www/admin/extensions/tree.jsp
r4202 r4207 51 51 String icon = ec.isEnabled(ep) ? "ExtensionPoint" : "ExtensionPointDisabled"; 52 52 ExtensionsFile f = ec.getFileByExtensionId(id); 53 if (f .hasError()) icon = "ExtensionPointError";53 if (f == null || f.hasError()) icon = "ExtensionPointError"; 54 54 String joust = "ep = JoustMenu.addChildItem(" + parentNode +", '" + icon + "', " + 55 55 "'" + HTML.javaScriptEncode(name) + "', 'extensionPointOnClick(\"" + id + "\")', " + … … 64 64 String icon = ec.isEnabled(ext) ? "Extension" : "ExtensionDisabled"; 65 65 ExtensionsFile f = ec.getFileByExtensionId(id); 66 if (f .hasError()) icon = "ExtensionError";66 if (f == null || f.hasError()) icon = "ExtensionError"; 67 67 String joust = "ext = JoustMenu.addChildItem(" + parentNode + ", '" + icon + "', " + 68 68 "'" + HTML.javaScriptEncode(name) + "', 'extensionOnClick(\"" + id + "\")', " +
Note: See TracChangeset
for help on using the changeset viewer.