All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.tweeenveertig.openstack.client.impl.AccountImpl Maven / Gradle / Ivy

There is a newer version: 0.7.0
Show newest version
package nl.tweeenveertig.openstack.client.impl;

import nl.tweeenveertig.openstack.command.identity.access.AccessImpl;
import nl.tweeenveertig.openstack.model.Container;
import nl.tweeenveertig.openstack.client.core.AbstractAccount;
import nl.tweeenveertig.openstack.command.account.AccountInformationCommand;
import nl.tweeenveertig.openstack.command.account.AccountMetadataCommand;
import nl.tweeenveertig.openstack.command.account.ListContainersCommand;
import nl.tweeenveertig.openstack.command.identity.AuthenticationCommand;
import org.apache.http.client.HttpClient;

import java.util.ArrayList;
import java.util.Collection;

public class AccountImpl extends AbstractAccount {

    private AuthenticationCommand command;
    private HttpClient httpClient;
    private AccessImpl access;

    public AccessImpl authenticate() {
        return access = command.call();
    }

    public AccountImpl(AuthenticationCommand command, HttpClient httpClient, AccessImpl access, boolean allowCaching) {
        super(allowCaching);
        this.command = command;
        this.httpClient = httpClient;
        this.access = access;
    }

    public Collection listContainers() {
        Collection containerNames = new ListContainersCommand(this, httpClient, access).call();
        Collection containers = new ArrayList();
        for (String containerName : containerNames) {
            containers.add(this.getContainer(containerName));
        }
        return containers;
    }

    public Container getContainer(String containerName) {
        return new ContainerImpl(this, containerName, isAllowCaching());
    }

    @Override
    protected void saveMetadata() {
        new AccountMetadataCommand(this, getClient(), getAccess(), info.getMetadata()).call();
    }

    protected void getInfo() {
        this.info = new AccountInformationCommand(this, httpClient, access).call();
        this.setInfoRetrieved();
    }

    public HttpClient getClient() {
        return httpClient;
    }

    public AccessImpl getAccess() {
        return access;
    }

    public String getPublicURL() {
        return access.getPublicURL();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy