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

org.nakedobjects.headlessviewer.viewer.internal.MapInvocationHandler Maven / Gradle / Ivy

The newest version!
package org.nakedobjects.headlessviewer.viewer.internal;

import static org.nakedobjects.metamodel.commons.lang.MethodUtils.getMethod;

import java.util.Map;

import org.nakedobjects.metamodel.runtimecontext.RuntimeContext;
import org.nakedobjects.metamodel.spec.feature.OneToManyAssociation;


class MapInvocationHandler extends AbstractCollectionInvocationHandler {

    public MapInvocationHandler(
            final C collectionToProxy,
            final String collectionName,
            final DomainObjectInvocationHandler handler,
            final RuntimeContext runtimeContext,
            final OneToManyAssociation otma) {
        super(collectionToProxy, collectionName, handler, runtimeContext, otma);

        try {
            intercept(getMethod(collectionToProxy, "containsKey", Object.class));
            intercept(getMethod(collectionToProxy, "containsValue", Object.class));
            intercept(getMethod(collectionToProxy, "size"));
            intercept(getMethod(collectionToProxy, "isEmpty"));
            veto(getMethod(collectionToProxy, "put", Object.class, Object.class));
            veto(getMethod(collectionToProxy, "remove", Object.class));
            veto(getMethod(collectionToProxy, "putAll", Map.class));
            veto(getMethod(collectionToProxy, "clear"));
        } catch (final NoSuchMethodException e) {
            // ///CLOVER:OFF
            throw new RuntimeException("A Collection method could not be found: " + e.getMessage());
            // ///CLOVER:ON
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy