View Javadoc

1   /*
2    * $Id: ObjectStoreFromRegistryFactoryBean.java 22178 2011-06-15 11:58:33Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.config.spring.factories;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.context.MuleContextAware;
15  import org.mule.api.store.ObjectStore;
16  
17  import java.io.Serializable;
18  
19  import org.springframework.beans.factory.config.AbstractFactoryBean;
20  
21  /**
22   * Lookup an {@link ObjectStore} from the registry.
23   */
24  public class ObjectStoreFromRegistryFactoryBean extends AbstractFactoryBean<ObjectStore<Serializable>> implements MuleContextAware
25  {
26      private String objectStoreName;
27      private MuleContext muleContext;
28  
29      public ObjectStoreFromRegistryFactoryBean(String name)
30      {
31          super();
32          objectStoreName = name;
33      }
34      
35      @Override
36      public Class<?> getObjectType()
37      {
38          return ObjectStore.class;
39      }
40  
41      @Override
42      protected ObjectStore<Serializable> createInstance() throws Exception
43      {
44          return muleContext.getRegistry().lookupObject(objectStoreName);
45      }
46  
47      @Override
48      public void setMuleContext(MuleContext context)
49      {
50          muleContext = context;
51      }
52  }