Hi,

i tried this.
I added this in hivemodule.xml:

<contribution configuration-id="tapestry.state.ApplicationObjects">
       <state-object name="globalObject" scope="application">
           <create-instance class="my.package.Global"/>
         </state-object>
     </contribution>
<service-point id="Resource" interface="org.apache.tapestry.engine.IEngineService">
       <invoke-factory>
           <construct class="ResourceService">
<set-object property="sharedResourceProvider" value="aso:shared-resource-provider"/>
           </construct>
       </invoke-factory>
   </service-point>
<contribution configuration-id="hivemind.ObjectProviders">
       <provider prefix="aso" service-id="ApplicationStateObjectProvider"/>
   </contribution>
<service-point id="ApplicationStateObjectProvider" interface="org.apache.hivemind.service.ObjectProvider">
       <invoke-factory>
           <construct class="my.package.MyApplicationStateObjectProvider">
<set-object property="applicationStateManager" value="infrastructure:applicationStateManager"/>
           </construct>
       </invoke-factory>
   </service-point>

The MyApplicationStateObjectProvider is exactly like your class.
How can i access from a Service to the GlobalObject?

When i try:

cycle.getInfrastructure().getApplicationStateManager().exists("globalObject");

then i get a "false"! what is wrong?

Best regards

Rudolf B.




Dmitry Gusev wrote:

Here is an example of creating ApplicationStateObjectProvider which allows
you to inject ASOs via "aso" prefix, for instance:

   <service-point id="Resource"
interface="org.apache.tapestry.engine.IEngineService">
       <invoke-factory>
           <construct class="ResourceService">
               <set-object property="sharedResourceProvider"
value="aso:shared-resource-provider"/>
           </construct>
       </invoke-factory>
   </service-point>

In order to do this we need to define an "aso" prefix for Application State
Objects. We can do it like this in the hivemodule.xml:

   <contribution configuration-id="hivemind.ObjectProviders">
       <provider prefix="aso" service-id="ApplicationStateObjectProvider"/>
   </contribution>

   <service-point id="ApplicationStateObjectProvider"
interface="org.apache.hivemind.service.ObjectProvider">

       An object provider based on Application State Objects

       <invoke-factory>
           <construct class="ApplicationStateObjectProvider">
               <set-object property="applicationStateManager"
value="infrastructure:applicationStateManager"/>
           </construct>
       </invoke-factory>

   </service-point>

Here we creating an object provider service that will manage ASOs via
applicationStateManager. In fact we are injecting applicationStateManager
into it. Here is an example of the ApplicationStateObjectProvider class:

package org.keyintegrity.servicehub.csulengine.engine.state;

import org.apache.hivemind.Location;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.service.ObjectProvider;
import org.apache.tapestry.engine.state.ApplicationStateManager;

public class ApplicationStateObjectProvider implements ObjectProvider {

        private ApplicationStateManager applicationStateManager;
        
        
        public Object provideObject(Module contributingModule, Class 
propertyType,
           String locator, Location location) {

                return applicationStateManager.get(locator);
        }

        public void setApplicationStateManager(ApplicationStateManager
applicationStateManager) {
                this.applicationStateManager = applicationStateManager;
        }
}

Thats all. Hope this will help.


2006/1/16, Christian Haselbach <[EMAIL PROTECTED]>:
Hello,

injecting an ASO into a page or component is simple, but I cannot
figure out how to inject one into a service. Can anyone tell me
what to do?

Thanke

Regards, Christian

P.S.: Injecting the ApplicationStateManager and obtaining the state
object from the it by name works fine, but this is not very direct.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Reply via email to