org.ops4j.pax.wicket.util
Class AbstractAggregatedSource<E extends org.apache.wicket.Component>

java.lang.Object
  extended by org.ops4j.pax.wicket.util.AbstractAggregatedSource<E>
All Implemented Interfaces:
ContentAggregator, ContentSource<E>, ContentTrackingCallback, org.osgi.service.cm.ManagedService
Direct Known Subclasses:
FloorAggregatedSource

public abstract class AbstractAggregatedSource<E extends org.apache.wicket.Component>
extends java.lang.Object
implements ContentAggregator, ContentSource<E>, ContentTrackingCallback, org.osgi.service.cm.ManagedService

This is a convenient superclass for creation of a ContentAggregator.

Normal use only requires the overriding of a single abstract method;

 protected abstract E createSourceComponent( String wicketId )
     throws IllegalArgumentException;
 

The subclass looks something like this;

         public class PrinterContentAggregator<E extends Component> extends AbstractContentAggregator
         {
             public PrinterContentAggregator( BundleContext context, String applicationName,
                                              String aggregationPoint, String destination )
                 throws IllegalArgumentException
             {
                 super( context, applicationName, aggregationPoint, destination );
             }
             protected abstract E createSourceComponent( String wicketId )
                 throws IllegalArgumentException
             {
                 return new PrintersPanel( wicketId, this );
             }
         }
 
And the MyPanel handles the generation of the Wicket Panel instance. Example;
 public class PrintersPanel extends Panel
 {
     private static final long serialVersionUID = 1L;
     public static final String WICKET_ID_NAME_LABEL = "name";
     private static final String WICKET_ID_PRINTER = "printer";
     private static final String WICKET_ID_PRINTERS = "printers";

     FloorPanel( String id, ContentAggregator container, Floor floor )
     {
         super( id, new Model( "printers" ) );
         ListView listView = new ListView( WICKET_ID_PRINTERS )
         {
             private static final long serialVersionUID = 1L;

             protected void populateItem( final ListItem item )
             {
                 Component modelObject = (Component) item.getModelObject();
                 item.add( modelObject );
             }
         };
         List<Component> printers = container.createComponents( WICKET_ID_PRINTER, listView );
         if ( printers.isEmpty() )
         {
             Label tLabel = new Label( WICKET_ID_PRINTER, "No Printers are available at the moment." );
             printers.add( tLabel );
         }
         Model listViewModel = new Model( (Serializable) printers );
         listView.setModel( listViewModel );
         add( listView );
     }
 }
 
In the above example, we are wiring printer ContentSources to a printers panel. The rendering of each Printer view is up to the wired printer, and the aggregator just need a little bit of html to define its own panel. Something like this;
           <html xmlns="http://www.w3.org/1999/xhtml"
                    xmlns:wicket="http://wicket.sourceforge.net/"
                    xml:lang="en"
                    lang="en"
           >
               <body>
                   <wicket:panel>
                       <div class="printerspanel">
                           <div class="printer-row" wicket:id="printers">
                               <span class="printer-item" wicket:id="printer"></span>
                           </div>
                       </div>
                   </wicket:panel>
               </body>
           </html>
 


Field Summary
protected  Logger LOGGER
           
 
Fields inherited from interface org.ops4j.pax.wicket.api.ContentSource
AGGREGATION_POINT, APPLICATION_NAME, BASIC_ROLES, DESTINATION_UNKNOWN, DESTINATIONS, HOMEPAGE_CLASSNAME, MOUNTPOINT, PAGE_ID, PAGE_NAME, REQUIRED_ROLES, SOURCE_ID
 
Constructor Summary
protected AbstractAggregatedSource(org.osgi.framework.BundleContext bundleContext, java.lang.String applicationName, java.lang.String aggregationPoint, java.lang.String destination)
          Construct an instance of AbstractContentAggregator with the specified arguments.
 
Method Summary
 void addContent(java.lang.String wicketId, ContentSource source)
          Add the specified source to this RootContentAggregator and mapped it as wicketId.
protected abstract  E createComponent(java.lang.String wicketId)
          Create component represented by this AbstractContentAggregator with the specified wicketId.
protected
<T extends org.apache.wicket.MarkupContainer>
E
createComponent(java.lang.String wicketId, T parent)
          Default implementation that ignores the parent component.
protected  java.util.List<org.apache.wicket.Component> createComponents(java.lang.String wicketId)
           
 E createSourceComponent(java.lang.String wicketId)
          Create the wicket component represented by this ContentSource instance.
<T extends org.apache.wicket.MarkupContainer>
E
createSourceComponent(java.lang.String wicketId, T parent)
          Create the wicket component represented by this ContentSource instance.
 org.apache.wicket.Component createWiredComponent(java.lang.String sourceId, java.lang.String wicketId)
           
 void dispose()
          Dispose this RootContentAggregator instance.
protected  void finalize()
           
 java.lang.String getAggregationPointName()
          Returns the aggregation point id of this AbstractContentAggregator instance.
 java.lang.String getApplicationName()
          Returns the application name of this ContentAggregator instance belongs to.
protected  PaxWicketAuthentication getAuthentication()
          Returns the Authentication of the current request.
 org.apache.wicket.authorization.strategies.role.Roles getBasicRoles()
           
protected  org.osgi.framework.BundleContext getBundleContext()
          Returns the BundleContext that this ContentAggregator belongs to.
 ContentSource<? extends org.apache.wicket.Component> getContentById(java.lang.String wicketId, java.lang.String sourceId)
           
<V extends ContentSource>
java.util.List<V>
getContents(java.lang.String wicketId)
          Returns list of ContentSource instnaces of the specified wicketId.
 java.lang.String[] getDestinations()
          Returns the destination of this ContentSource instance.
protected  java.lang.Object getObjectProperty(java.lang.String key)
           
 org.apache.wicket.authorization.strategies.role.Roles getRequiredRoles()
           
protected  java.lang.String[] getServiceNames()
           
 java.lang.String getSourceId()
          Returns the source id.
protected  java.lang.String[] getStringArrayProperty(java.lang.String key)
           
protected  java.lang.String getStringProperty(java.lang.String key, java.lang.String defaultValue)
           
 java.util.List<java.lang.String> getWiredSourceIds(java.lang.String wicketId, java.util.Comparator<ContentSource> comparator)
           
protected  void onDispose()
          Override this method to handle additional dispose.
protected  void onUpdated(java.util.Dictionary config)
           
 org.osgi.framework.ServiceRegistration register()
           
 boolean removeContent(java.lang.String wicketId, ContentSource content)
          Remove the specified content to this RootContentAggregator and unmapped it as wicketId.
 void setAggregationPointName(java.lang.String aggregationPoint)
          Set the aggregation id of this AbstractContentAggregator.
 void setApplicationName(java.lang.String applicationName)
          Sets the application name of this AbstractContentAggregator instant belongs to.
 void setDestination(java.lang.String... destinations)
          Set the destination of this ContentSource.
protected  void setProperty(java.lang.String key, java.lang.Object value)
           
 void setRoles(org.apache.wicket.authorization.strategies.role.Roles requiredRoles, org.apache.wicket.authorization.strategies.role.Roles basicRoles)
           
 void updated(java.util.Dictionary config)
           
protected  void updateRegistration()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.ops4j.pax.wicket.api.ContentAggregator
dispose, getAggregationPointName, getApplicationName
 
Methods inherited from interface org.ops4j.pax.wicket.internal.ContentTrackingCallback
addContent, removeContent
 
Methods inherited from interface org.osgi.service.cm.ManagedService
updated
 

Field Detail

LOGGER

protected final Logger LOGGER
Constructor Detail

AbstractAggregatedSource

protected AbstractAggregatedSource(org.osgi.framework.BundleContext bundleContext,
                                   java.lang.String applicationName,
                                   java.lang.String aggregationPoint,
                                   java.lang.String destination)
                            throws java.lang.IllegalArgumentException
Construct an instance of AbstractContentAggregator with the specified arguments.

Parameters:
bundleContext - The bundle context. This argument must not be null.
applicationName - The application name. This argument must not be null or empty.
aggregationPoint - The aggregation point id. This argument must not be null or empty.
destination - The destination id. This argument must not be null or empty.
Throws:
java.lang.IllegalArgumentException - Thrown if one or some or all arguments are null or empty.
Since:
1.0.0
Method Detail

getSourceId

public final java.lang.String getSourceId()
Returns the source id.

Specified by:
getSourceId in interface ContentSource<E extends org.apache.wicket.Component>
Returns:
The source id.
Since:
1.0.0

getDestinations

public final java.lang.String[] getDestinations()
Returns the destination of this ContentSource instance. This method must not return null object.

Specified by:
getDestinations in interface ContentSource<E extends org.apache.wicket.Component>
Returns:
The destination id of this ContentSource instance.
Since:
1.0.0

setDestination

public final void setDestination(java.lang.String... destinations)
                          throws java.lang.IllegalArgumentException
Set the destination of this ContentSource.

Note: Destination property must not be set after this ContentSource instance is registered to OSGi framework.

Parameters:
destinations - The destinations. This argument must not be null.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified destination argument is null or empty.
Since:
1.0.0

getServiceNames

protected java.lang.String[] getServiceNames()

createSourceComponent

public final E createSourceComponent(java.lang.String wicketId)
                                                                  throws java.lang.IllegalArgumentException
Create the wicket component represented by this ContentSource instance. This method must not return null object.

General convention:

Specified by:
createSourceComponent in interface ContentSource<E extends org.apache.wicket.Component>
Parameters:
wicketId - The wicket id. This argument must not be null.
Returns:
The wicket component represented by this ContentSource instance, or null if user has no access to this ContentSource.
Throws:
java.lang.IllegalArgumentException - Thrown if the wicketId argument is null.
Since:
1.0.0

createSourceComponent

public <T extends org.apache.wicket.MarkupContainer> E createSourceComponent(java.lang.String wicketId,
                                                                             T parent)
                                                            throws java.lang.IllegalArgumentException
Create the wicket component represented by this ContentSource instance. This method must not return null object.

General convention:

Specified by:
createSourceComponent in interface ContentSource<E extends org.apache.wicket.Component>
Parameters:
wicketId - The wicket id. This argument must not be null.
parent - the parent MarkupContainer
Returns:
The wicket component represented by this ContentSource instance, or null if user has no access to this ContentSource.
Throws:
java.lang.IllegalArgumentException - Thrown if the wicketId argument is null.
Since:
1.0.0

createComponent

protected abstract E createComponent(java.lang.String wicketId)
                                                                  throws java.lang.IllegalArgumentException
Create component represented by this AbstractContentAggregator with the specified wicketId.

General convention:

Parameters:
wicketId - The wicketId. This argument must not be null nor empty. It maps to the wicket:id of the rendering process in Wicket.
Returns:
A new instance of wicket component represented by this AbstractContentAggregator.
Throws:
java.lang.IllegalArgumentException - Thrown if argument is null.
Since:
1.0.0

createComponent

protected <T extends org.apache.wicket.MarkupContainer> E createComponent(java.lang.String wicketId,
                                                                          T parent)
Default implementation that ignores the parent component. Override this if you want to inject the parent component into your created Wicket Component

Parameters:
wicketId - The WicketId. This argument must not be null.
parent - the parent MarkupContainer
Returns:
The wicket component with the specified wicketId.
Throws:
java.lang.IllegalArgumentException - Thrown if the either or both arguments are null.
Since:
0.5.2

getRequiredRoles

public final org.apache.wicket.authorization.strategies.role.Roles getRequiredRoles()

getBasicRoles

public final org.apache.wicket.authorization.strategies.role.Roles getBasicRoles()

setRoles

public final void setRoles(org.apache.wicket.authorization.strategies.role.Roles requiredRoles,
                           org.apache.wicket.authorization.strategies.role.Roles basicRoles)

createComponents

protected final java.util.List<org.apache.wicket.Component> createComponents(java.lang.String wicketId)

getAggregationPointName

public final java.lang.String getAggregationPointName()
Returns the aggregation point id of this AbstractContentAggregator instance. This method must not return null object.

Specified by:
getAggregationPointName in interface ContentAggregator
Returns:
The aggregation point name.
Since:
1.0.0

setAggregationPointName

public final void setAggregationPointName(java.lang.String aggregationPoint)
Set the aggregation id of this AbstractContentAggregator.

Note: aggregation id property must not be set after this AbstractContentAggregator instance is registered to OSGi framework.

Parameters:
aggregationPoint - The aggregation point name. This argument must not be null.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified aggregationId argument is null or empty.
Since:
1.0.0

getApplicationName

public final java.lang.String getApplicationName()
Returns the application name of this ContentAggregator instance belongs to.

Specified by:
getApplicationName in interface ContentAggregator
Returns:
The application name of this ContentAggregator instance belongs to.
Since:
1.0.0

setApplicationName

public final void setApplicationName(java.lang.String applicationName)
Sets the application name of this AbstractContentAggregator instant belongs to.

Note: Application name property must not be set after this AbstractContentAggregator instance is registered to OSGi framework.

Parameters:
applicationName - The application name. This argument must not be null.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified applicationName argument is null or empty.
Since:
1.0.0

dispose

public final void dispose()
                   throws java.lang.IllegalStateException
Dispose this RootContentAggregator instance.

Note: Dispose does not unregister this RootContentAggregator, and ensure that dispose is only called after this RootContentAggregator instance is unregistered from OSGi container.

Specified by:
dispose in interface ContentAggregator
Throws:
java.lang.IllegalStateException - Thrown if this content tracker has not been registered.
Since:
1.0.0
See Also:
ServiceRegistration.unregister()

getBundleContext

protected final org.osgi.framework.BundleContext getBundleContext()
Returns the BundleContext that this ContentAggregator belongs to.

Returns:
the BundleContext that this ContentAggregator belongs to.

updated

public final void updated(java.util.Dictionary config)
                   throws org.osgi.service.cm.ConfigurationException
Specified by:
updated in interface org.osgi.service.cm.ManagedService
Throws:
org.osgi.service.cm.ConfigurationException

onUpdated

protected void onUpdated(java.util.Dictionary config)

addContent

public final void addContent(java.lang.String wicketId,
                             ContentSource source)
                      throws java.lang.IllegalArgumentException
Add the specified source to this RootContentAggregator and mapped it as wicketId.

Specified by:
addContent in interface ContentTrackingCallback
Parameters:
wicketId - The wicket id. This argument must not be null or empty.
source - The source. This argument must not be null.
Throws:
java.lang.IllegalArgumentException - Thrown if one or both arguments are null.
Since:
1.0.0

removeContent

public final boolean removeContent(java.lang.String wicketId,
                                   ContentSource content)
                            throws java.lang.IllegalArgumentException
Remove the specified content to this RootContentAggregator and unmapped it as wicketId.

Specified by:
removeContent in interface ContentTrackingCallback
Parameters:
wicketId - The wicket id. This argument must not be null or empty.
content - The content. This argument must not be null.
Returns:
A boolean indicator whether removal is successfull.
Throws:
java.lang.IllegalArgumentException - Thrown if one or both arguments are null.
Since:
1.0.0

register

public final org.osgi.framework.ServiceRegistration register()
                                                      throws java.lang.IllegalStateException
Throws:
java.lang.IllegalStateException

getStringArrayProperty

protected java.lang.String[] getStringArrayProperty(java.lang.String key)

getStringProperty

protected java.lang.String getStringProperty(java.lang.String key,
                                             java.lang.String defaultValue)

setProperty

protected void setProperty(java.lang.String key,
                           java.lang.Object value)

updateRegistration

protected void updateRegistration()

getObjectProperty

protected java.lang.Object getObjectProperty(java.lang.String key)

onDispose

protected void onDispose()
Override this method to handle additional dispose.

Since:
1.0.0

getWiredSourceIds

public final java.util.List<java.lang.String> getWiredSourceIds(java.lang.String wicketId,
                                                                java.util.Comparator<ContentSource> comparator)
                                                         throws java.lang.IllegalArgumentException
Parameters:
wicketId - The WicketID that we want to find the wiring for.
comparator - The sorting comparator.
Returns:
A List of SourceIDs, identifying the ContentSource that has been wired to this ContentAggregator.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified wicketId argument is null.
Since:
1.0.0
See Also:
createWiredComponent(String,String)

createWiredComponent

public final org.apache.wicket.Component createWiredComponent(java.lang.String sourceId,
                                                              java.lang.String wicketId)
                                                       throws java.lang.IllegalArgumentException
Parameters:
sourceId - The SourceID of the ContentSource that we want to create a component.
wicketId - The WicketID of the component to be created by the ContentSource. This responds to the wicket:id in the markup.
Returns:
The wicket component build for the specified sourceId and wicketId.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified sourceId (or/and) wicketId argument is null.
Since:
1.0.0
See Also:
getWiredSourceIds(String,java.util.Comparator)

getContents

public final <V extends ContentSource> java.util.List<V> getContents(java.lang.String wicketId)
                                                          throws java.lang.IllegalArgumentException
Returns list of ContentSource instnaces of the specified wicketId. Returns an empty list if there is no content for the specified wicketId.

Parameters:
wicketId - The wicket id. This argument must not be null or empty.
Returns:
List of ContentSource of the specified wicketId.
Throws:
java.lang.IllegalArgumentException - if the wicketId is null or empty.

getAuthentication

protected PaxWicketAuthentication getAuthentication()
Returns the Authentication of the current request. It is possible to obtain the Username of the logged in user as well as which roles that this user has assigned to it.

Returns:
the Authentication of the current request.

getContentById

public final ContentSource<? extends org.apache.wicket.Component> getContentById(java.lang.String wicketId,
                                                                                 java.lang.String sourceId)
                                                                          throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable


Copyright © 2008. All Rights Reserved.