org.openrdf.repository.object.composition.helpers.InvocationMessageContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alibaba-composition-object Show documentation
Show all versions of alibaba-composition-object Show documentation
The Object Composition library merges multiple Java objects into a single multi-subject object.
The newest version!
/*
* Copyright (c) 2007-2009, James Leigh All rights reserved.
* Copyright (c) 2011 Talis Inc., Some rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the openrdf.org nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
package org.openrdf.repository.object.composition.helpers;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.openrdf.annotations.Iri;
import org.openrdf.repository.object.exceptions.BehaviourException;
import org.openrdf.repository.object.traits.BooleanMessage;
import org.openrdf.repository.object.traits.ByteMessage;
import org.openrdf.repository.object.traits.CharacterMessage;
import org.openrdf.repository.object.traits.DoubleMessage;
import org.openrdf.repository.object.traits.FloatMessage;
import org.openrdf.repository.object.traits.IntegerMessage;
import org.openrdf.repository.object.traits.LongMessage;
import org.openrdf.repository.object.traits.MessageContext;
import org.openrdf.repository.object.traits.ObjectMessage;
import org.openrdf.repository.object.traits.ShortMessage;
import org.openrdf.repository.object.traits.VoidMessage;
/**
* Implements the Message interface(s) through an InvocationHandler.
*
* @author James Leigh
*
*/
public class InvocationMessageContext implements ObjectMessage {
private static class Invocation implements MessageContext {
protected final ObjectMessage delegate;
public Invocation(ObjectMessage delegate) {
this.delegate = delegate;
}
public Object getTarget() {
return delegate.getTarget();
}
public Method getMethod() {
return delegate.getMethod();
}
public Object[] getParameters() {
return delegate.getParameters();
}
public void setParameters(Object[] parameters) {
delegate.setParameters(parameters);
}
}
private static class BooleanInvocation extends Invocation implements
BooleanMessage {
public BooleanInvocation(ObjectMessage delegate) {
super(delegate);
}
public boolean proceed() throws Exception {
return (Boolean) delegate.proceed();
}
}
private static class ByteInvocation extends Invocation implements
ByteMessage {
public ByteInvocation(ObjectMessage delegate) {
super(delegate);
}
public byte proceed() throws Exception {
return (Byte) delegate.proceed();
}
}
private static class CharacterInvocation extends Invocation implements
CharacterMessage {
public CharacterInvocation(ObjectMessage delegate) {
super(delegate);
}
public char proceed() throws Exception {
return (Character) delegate.proceed();
}
}
private static class DoubleInvocation extends Invocation implements
DoubleMessage {
public DoubleInvocation(ObjectMessage delegate) {
super(delegate);
}
public double proceed() throws Exception {
return (Double) delegate.proceed();
}
}
private static class FloatInvocation extends Invocation implements
FloatMessage {
public FloatInvocation(ObjectMessage delegate) {
super(delegate);
}
public float proceed() throws Exception {
return (Float) delegate.proceed();
}
}
private static class IntegerInvocation extends Invocation implements
IntegerMessage {
public IntegerInvocation(ObjectMessage delegate) {
super(delegate);
}
public int proceed() throws Exception {
return (Integer) delegate.proceed();
}
}
private static class LongInvocation extends Invocation implements
LongMessage {
public LongInvocation(ObjectMessage delegate) {
super(delegate);
}
public long proceed() throws Exception {
return (Long) delegate.proceed();
}
}
private static class ShortInvocation extends Invocation implements
ShortMessage {
public ShortInvocation(ObjectMessage delegate) {
super(delegate);
}
public short proceed() throws Exception {
return (Short) delegate.proceed();
}
}
private static class VoidInvocation extends Invocation implements
VoidMessage {
public VoidInvocation(ObjectMessage delegate) {
super(delegate);
}
public void proceed() throws Exception {
delegate.proceed();
}
}
private final Object target;
private final Method method;
private Object[] parameters;
private final List