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

org.nohope.jaxb2.plugin.metadata.ValueDescriptor Maven / Gradle / Ivy

There is a newer version: 0.2.3
Show newest version
package org.nohope.jaxb2.plugin.metadata;

import org.nohope.reflection.TypeReference;

import javax.annotation.Nullable;

/**
 * @author Ketoth Xupack
 * @since 2013-10-30 16:25
 */
public class ValueDescriptor
        extends Descriptor
        implements IValueDescriptor {

    private final IValueGetter getter;

    public ValueDescriptor(
            @Nullable final ValueDescriptor parent,
            @Nullable final String name, final TypeReference type,
            final IValueGetter getter) {
        super(parent, name, type);
        this.getter = getter;
    }

    @Override
    public IValueDescriptor getChild(final String name) {
        throw new IllegalArgumentException("No children found");
    }

    @Override
    public T getValue() throws CallException {
        try {
            return getter.get();
        } catch (final Exception e) {
            if (e instanceof CallException) {
                throw (CallException) e;
            }
            throw new CallException(this, "Error while getting value of descriptor " + this, e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy