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

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

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

import javax.annotation.Nonnull;

/**
 * @author Ketoth Xupack
 * @since 2013-12-23 12:59
 */
public final class MetadataUtils {

    private MetadataUtils() {
    }

    /**
     * Returns value of call chain applied to given object.
     */
    @SuppressWarnings("unchecked")
    public static  V getValue(@Nonnull final IMetadataHolder object,
                                 @Nonnull final IDescriptor descriptor)
            throws CallException {
        IValueDescriptor current = object.getInstanceDescriptor();
        for (final IDescriptor d : descriptor) {
            if (d.getParent() == null) {
                continue;
            }
            if (current == null) {
                throw new CallException(descriptor,
                        "Unexpected null value in call chain",
                        new NullPointerException());
            }
            current = current.getChild(d.getName());
            if (current.getParent() == null) {
                break;
            }
        }

        return (V) current.getValue();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy