/*
 * Copyright 2011 Red Hat inc. and third party contributors as noted 
 * by the author tags.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.redhat.ceylon.cmr.impl;

import com.redhat.ceylon.cmr.api.ArtifactContext;
import com.redhat.ceylon.cmr.spi.ContentStore;
import com.redhat.ceylon.cmr.spi.Node;
import com.redhat.ceylon.cmr.spi.StructureBuilder;

import java.io.File;
import java.io.IOException;

/**
 * Simple repository.
 *
 * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
 */
public class SimpleRepository extends AbstractNodeRepository {

    private static StructureBuilder toStructureBuilder(ContentStore contentStore) {
        if (contentStore instanceof StructureBuilder == false)
            throw new IllegalArgumentException("ContentStore is not StructureBuilder: " + contentStore);
        return StructureBuilder.class.cast(contentStore);
    }

    public SimpleRepository(ContentStore contentStore) {
        this(contentStore, toStructureBuilder(contentStore));
    }

    public SimpleRepository(ContentStore contentStore, StructureBuilder structureBuilder) {
        if (contentStore == null)
            throw new IllegalArgumentException("Null content store!");
        if (structureBuilder == null)
            throw new IllegalArgumentException("Null structure builder!");

        setRoot(new RootNode(contentStore, structureBuilder));
    }

    public File getArtifact(ArtifactContext context) throws IOException {
        Node node = getLeafNode(context);
        return (node != null) ? node.getContent(File.class) : null;
    }

    @Override
    public String toString() {
        return "SimpleRepository: " + getRoot();
    }
}

@@ -740,55 +740,8 @@
 xt;%0A
-import com.redhat.ceylon.cmr.spi.ContentStore;%0A
 impo
@@ -775,16 +775,16 @@
 i.Node;%0A
+
 import c
@@ -1049,642 +1049,67 @@
    p
-rivate static StructureBuilder toStructureBuilder(ContentStore contentStore) %7B%0A        if (contentStore instanceof StructureBuilder == false)%0A            throw new IllegalArgumentException(%22ContentStore is not StructureBuilder: %22 + contentStore);%0A        return StructureBuilder.class.cast(contentStore);%0A    %7D%0A%0A    public SimpleRepository(ContentStore contentStore) %7B%0A        this(contentStore, toStructureBuilder(contentStore));%0A    %7D%0A%0A    public SimpleRepository(ContentStore contentStore, StructureBuilder structureBuilder) %7B%0A        if (contentStore == null)%0A            throw new IllegalArgumentException(%22Null content store!%22);
+ublic SimpleRepository(StructureBuilder structureBuilder) %7B
 %0A   
@@ -1239,35 +1239,8 @@
 oot(
-new RootNode(contentStore, 
 stru
@@ -1251,16 +1251,28 @@
 eBuilder
+.createRoot(
 ));%0A    

Simplify how repo is created from root / structure.