/*
 *    Geotools2 - OpenSource mapping toolkit
 *    http://geotools.org
 *    (C) 2005-2006, GeoTools Project Managment Committee (PMC)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 */
package org.geotools.data.complex.config;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import org.opengis.feature.type.AttributeType;
import org.opengis.feature.type.Name;
import org.opengis.util.InternationalString;

/**
 * 
 * @author Gabriel Roldan, Axios Engineering
 * @version $Id: AttributeTypeProxy.java 27535 2007-10-17 23:46:43Z groldan $
 * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/community-schemas/community-schema-ds/src/main/java/org/geotools/data/complex/config/AttributeTypeProxy.java $
 * @since 2.4
 */
class AttributeTypeProxy implements AttributeType {

    private Name typeName;

    private Map registry;

    private AttributeType subject;

    public AttributeTypeProxy(Name typeName, Map registry) {
        this.typeName = typeName;
        this.registry = registry;
    }

    public AttributeType getSubject() {
        if (subject == null) {
            subject = (AttributeType) registry.get(typeName);
            if (subject == null) {
                throw new IllegalStateException("Subject type not loaded yet");
            }
        }
        return subject;
    }

    public Class getBinding() {
        return getSubject().getBinding();
    }

    public Collection getOperations() {
        return null;
    }

    public Set getRestrictions() {
        return getSubject().getRestrictions();
    }

    public AttributeType getSuper() {
        return getSubject().getSuper();
    }

    public boolean isAbstract() {
        return getSubject().isAbstract();
    }

    public boolean isIdentified() {
        return getSubject().isIdentified();
    }

    public InternationalString getDescription() {
        return getSubject().getDescription();
    }

    public Name getName() {
        return typeName;
    }

    public Object getUserData(Object key) {
        return getSubject().getUserData(key);
    }

    public void putUserData(Object key, Object value) {
        getSubject().putUserData(key, value);
    }

    public boolean equals(Object o) {
        AttributeType subject = getSubject();
        return subject.equals(o);
    }

    public int hashCode() {
        AttributeType subject = getSubject();
        return subject.hashCode();
    }
}
