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

brooklyn.catalog.internal.CatalogItemDo Maven / Gradle / Ivy

package brooklyn.catalog.internal;

import com.google.common.base.Preconditions;

import brooklyn.catalog.CatalogItem;
import brooklyn.util.exceptions.Exceptions;

public class CatalogItemDo implements CatalogItem {

    protected final CatalogDo catalog;
    protected final CatalogItem itemDto;

    protected volatile Class javaClass; 
    
    public CatalogItemDo(CatalogDo catalog, CatalogItem itemDto) {
        this.catalog = Preconditions.checkNotNull(catalog, "catalog");
        this.itemDto = Preconditions.checkNotNull(itemDto, "itemDto");
    }

    public CatalogItem getDto() {
        return itemDto;
    }

    @Override
    public brooklyn.catalog.CatalogItem.CatalogItemType getCatalogItemType() {
        return itemDto.getCatalogItemType();
    }

    @Override
    public Class getCatalogItemJavaType() {
        return itemDto.getCatalogItemJavaType();
    }

    @Override
    public String getId() {
        return itemDto.getId();
    }

    @Override
    public String getJavaType() {
        return itemDto.getJavaType();
    }

    @Override
    public String getName() {
        return itemDto.getName();
    }

    @Override
    public String getDescription() {
        return itemDto.getDescription();
    }

    @Override
    public String getIconUrl() {
        return itemDto.getIconUrl();
    }
    
    public Class getJavaClass() {
        if (javaClass==null) loadJavaClass();
        return javaClass;
    }
    
    @SuppressWarnings("unchecked")
    protected Class loadJavaClass() {
        try {
            if (javaClass!=null) return javaClass;
            javaClass = (Class) catalog.getRootClassLoader().loadClass(getJavaType());
            return javaClass;
        } catch (ClassNotFoundException e) {
            throw Exceptions.propagate(e);
        }
    }

    @Override
    public String toString() {
        return getClass().getCanonicalName()+"["+itemDto+"]";
    }

    public String toXmlString() {
        return itemDto.toXmlString();
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy