Package org.wso2.carbon.mediation.initializer.persistence

## Class AbstractStore<T>

- java.lang.Object
- - org.wso2.carbon.mediation.initializer.persistence.AbstractStore<T>

- Type Parameters:
    `T` -
  Direct Known Subclasses:
    `APIStore`, `EndpointStore`, `EndpointTemplateStore`, `EventSourceStore`, `ExecutorStore`, `ImportStore`, `InboundStore`, `LocalEntryStore`, `MessageProcessorStore`, `MessageStoreStore`, `ProxyServiceStore`, `SequenceStore`, `StartupStore`, `SynapseRegistryStore`, `TemplateStore`

      public abstract class AbstractStore<T>
      extends Object

  The abstract class which can be used to access a persistence storage of a specific type of mediation configuration elements. Implementations of this abstract class should ideally be parameterized to prevent it from handling more than one type of objects. This abstract class provides supports basic persistence activities of save and delete. Registry persistence activities can also be handled by this implementation if required.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected String` | `configPath` |
    `protected org.apache.commons.logging.Log` | `log` |
    `protected AbstractRegistryStore` | `registryStore` |
    `protected org.apache.synapse.config.xml.MultiXMLConfigurationSerializer` | `serializer` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `AbstractStore​(String configPath)` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `delete​(String name, String fileName, org.apache.synapse.config.SynapseConfiguration config)` |
    `protected abstract void` | `deleteFile​(String fileName, org.apache.synapse.config.SynapseConfiguration config)` | Delete the specified file from the persistence store.
    `protected void` | `deleteFromRegistry​(String name)` |
    `void` | `deleteItemFromRegistry​(String name)` |
    `protected abstract String` | `getFileName​(T obj)` | Inspect the given object and find the file name to which it should be serialized to
    `protected abstract T` | `getObjectToPersist​(String name, org.apache.synapse.config.SynapseConfiguration config)` | Find the specified object from the SynaspeConfiguration to be saved to the persistence store
    `protected void` | `handleException​(String msg, Exception e)` |
    `void` | `save​(String name, org.apache.synapse.config.SynapseConfiguration config)` |
    `void` | `saveItemToRegistry​(String name, org.apache.synapse.config.SynapseConfiguration config)` |
    `protected abstract org.apache.axiom.om.OMElement` | `saveToFile​(T obj, org.apache.synapse.config.SynapseConfiguration synapseConfig)` | Serialize and save the given object to the local file system
    `protected void` | `saveToRegistry​(String name, org.apache.axiom.om.OMElement element, String fileName)` |
    `protected abstract org.apache.axiom.om.OMElement` | `serialize​(T obj)` | Serialize the given object into XML

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### log

          protected org.apache.commons.logging.Log log

    - #### configPath

          protected String configPath

    - #### registryStore

          protected AbstractRegistryStore registryStore

    - #### serializer

          protected org.apache.synapse.config.xml.MultiXMLConfigurationSerializer serializer

  - ### Constructor Detail

    - #### AbstractStore

          public AbstractStore​(String configPath)

  - ### Method Detail

    - #### save

          public void save​(String name,
                           org.apache.synapse.config.SynapseConfiguration config)

    - #### delete

          public void delete​(String name,
                             String fileName,
                             org.apache.synapse.config.SynapseConfiguration config)

    - #### saveToFile

          protected abstract org.apache.axiom.om.OMElement saveToFile​(T obj,
                                                                      org.apache.synapse.config.SynapseConfiguration synapseConfig)

      Serialize and save the given object to the local file system
      Parameters:
        `obj` - Object to be saved
        `synapseConfig` - synapse configuration
      Returns:
        The OMElement generated as a result of the serialization or null

    - #### deleteFile

          protected abstract void deleteFile​(String fileName,
                                             org.apache.synapse.config.SynapseConfiguration config)

      Delete the specified file from the persistence store. File name is provided as an argument and it is up to the implementation to the calculate the exact file path using the file name and other available data.
      Parameters:
        `fileName` - Name of the file to be deleted
        `config` - synapse configuration

    - #### getObjectToPersist

          protected abstract T getObjectToPersist​(String name,
                                                  org.apache.synapse.config.SynapseConfiguration config)

      Find the specified object from the SynaspeConfiguration to be saved to the persistence store
      Parameters:
        `name` - Name or unique ID of the object
        `config` - Current SynapseConfiguration
      Returns:
        The named object or null if such an object doesn't exist

    - #### getFileName

          protected abstract String getFileName​(T obj)

      Inspect the given object and find the file name to which it should be serialized to
      Parameters:
        `obj` - The object to be inspected
      Returns:
        A file name as a string or null if no file name is specified

    - #### serialize

          protected abstract org.apache.axiom.om.OMElement serialize​(T obj)

      Serialize the given object into XML
      Parameters:
        `obj` - The object to be serialized
      Returns:
        The resulting OMElement

    - #### saveItemToRegistry

          public void saveItemToRegistry​(String name,
                                         org.apache.synapse.config.SynapseConfiguration config)

    - #### deleteItemFromRegistry

          public void deleteItemFromRegistry​(String name)

    - #### saveToRegistry

          protected void saveToRegistry​(String name,
                                        org.apache.axiom.om.OMElement element,
                                        String fileName)

    - #### deleteFromRegistry

          protected void deleteFromRegistry​(String name)

    - #### handleException

          protected void handleException​(String msg,
                                         Exception e)