/*
 * Copyright 2015, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.spine3.server.storage.filesystem;


import com.google.protobuf.Message;
import org.spine3.server.Entity;
import org.spine3.server.aggregate.Aggregate;
import org.spine3.server.storage.*;

public class FileSystemStorageFactory implements StorageFactory {

    @Override
    public CommandStorage createCommandStorage() {
        return FileSystemCommandStorage.newInstance();
    }

    @Override
    public EventStorage createEventStorage() {
        return FileSystemEventStorage.newInstance();
    }

    @Override
    public <I> AggregateStorage<I> createAggregateRootStorage(Class<? extends Aggregate<I, ?>> aggregateClass) {
        return null;
    }

    @Override
    public <I, M extends Message> EntityStorage<I, M> createEntityStorage(Class<? extends Entity<I, M>> entityClass) {
        return FileSystemEntityStorage.newInstance();
    }
}

@@ -1085,23 +1085,100 @@
 rotobuf.
-Message
+Descriptors;%0Aimport com.google.protobuf.Message;%0Aimport org.spine3.protobuf.Messages
 ;%0Aimport
@@ -1290,74 +1290,211 @@
 .*;%0A
-%0Apublic class FileSystemStorageFactory implements StorageFactory %7B
+import org.spine3.util.Classes;%0Aimport org.spine3.util.Identifiers;%0A%0Apublic class FileSystemStorageFactory implements StorageFactory %7B%0A%0A    private static final int AGGREGATE_MESSAGE_PARAMETER_INDEX = 1;
 %0A%0A  
@@ -1878,19 +1878,389 @@
     
-return null
+final Class%3CMessage%3E messageClazz =%0A                Classes.getGenericParameterType(aggregateClass, AGGREGATE_MESSAGE_PARAMETER_INDEX);%0A        final Descriptors.GenericDescriptor msgClassDescriptor = Messages.getClassDescriptor(messageClazz);%0A        final String msgDescriptorName = msgClassDescriptor.getName();%0A        return new FileSystemAggregateStorage%3C%3E(msgDescriptorName)
 ;%0A  

Implement FileSystemStorageFactory.createAggregateRootStorage.