On Aug 29, 2008, at 9:16 AM, Marius Dumitru Florea wrote:
So, if I want to create MyService I'd have to:
myservice/
|_ internal/
| |_ DefaultMyService implements MyService
| |_ DefaultMyServiceVelocityBridge implements
MyServiceVelocityBridge
|_ MyService // component interface
|_ MyServiceVelocityBridge extends MyService, VelocityBridge // empty
And DefaultMyServiceVelocityBridge#doService will call
DefaultMyService#doService. Right?
yes exactly except that there's no MyServiceVelocityBridge interface
(so only 3 files). The component implementation will just implement
VelocityBridge.
The reason It'll work (I think) is because the velocity services
component will be able to lookup all components implementing
VelocityBridge ROLE and register them in the Velocity Context. Since
Velocity uses reflection to call the methods it'll work even though
the interface doesn't have any methods in it.
The pro (side effect but a great one) is that this will prevent anyone
from using DefaultMyServiceVelocityBridge from java! (since it would
require doing reflection).
Thanks
-Vincent
Looks great to me. +1
> Hi devs,
>
> Right now we have:
>
> platform/
> |_ core/
> |_ xwiki-core/
> |_ (others)/
> |_ plugins/
> |_ ...
>
> The problem I see is twofold:
> 1) We can have platform components that are not core components (for
> example I'd like to commit the office component done by Wang Ning).
> 2) I'd like that we decide to deprecate the plugins/ system going
> forward and that all new code only write components.
>
> For 1) I'd like to propose:
>
> platform/
> |_ components/ (contains (others)/ from above)
> |_ core/ (is the core/xwiki-core from above, to be removed once
> fully split into components)
> |_ plugins/ (to be removed once fully split into components)
> |_ ...
>
> For 2) I'd like to propose:
>
> * Create an interface for Velocity APIs. Something like
> VelocityBridge
> (or VelocityAccess or VelocityApi or...). It would be empty.
> * Each component that want to be accessed from velocity will need to
> implement a component implementing VelocityBridge. It'll have a role-
> hint being the name under which it'll be access from Velocity.
> * Create a VelocityService class (component) which has a single
> get(String name) method and which uses the ComponentManager to look
> up
> components which implement VelocityBridge using the name as the role
> hint.
> * Put that VelocityService in the Velocity context under the name
> "services".
>
> In practice this means that users will be able to access all our
> components through the VelocityBridge implementations with a syntax
> like:
>
> $services.office.convert(...)
> $services.translation.translate(...)
> ...
>
> Note1: We would need to be careful that it would be forbidden for any
> java code to use a VelocityBridge. This is to ensure all code logic
> is
> put into components and not into the bridges. We should use the maven
> enforcer plugin to enforce this rule.
> Note2: This means we'll have 2 APIs to maintain: the velocity one
> (the
> bridges) + the "Java"' one (the main components). But I don't see
any
> other way...
>
> WDYT?
>
> Thanks
> -Vincent