Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.rest.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.all;
import static com.google.common.collect.Iterables.find;
import static com.google.inject.util.Types.newParameterizedType;
import static org.jclouds.reflect.Reflection2.method;
import static org.jclouds.reflect.Reflection2.typeToken;
import static org.jclouds.util.Optionals2.isReturnTypeOptional;
import static org.jclouds.util.Optionals2.unwrapIfOptional;
import static org.jclouds.util.Throwables2.getFirstThrowableOfType;
import static org.jclouds.util.Throwables2.propagateIfPossible;
import java.io.Closeable;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Qualifier;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.lifecycle.Closer;
import org.jclouds.reflect.FunctionalReflection;
import org.jclouds.reflect.Invocation;
import org.jclouds.reflect.InvocationSuccess;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.config.SetCaller;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.reflect.Invokable;
import com.google.common.reflect.TypeToken;
import com.google.inject.Binding;
import com.google.inject.ConfigurationException;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.ProvisionException;
import com.google.inject.util.Types;
/**
* @param
* The enclosing type of the interface that a dynamic proxy like this implements
* @param
* The function that implements this dynamic proxy
*/
@Beta
public class DelegatesToInvocationFunction> implements
InvocationHandler {
private static final Object[] NO_ARGS = {};
/**
* {@inheritDoc}
*
*
*
*
{@code proxy.hashCode()} delegates to {@link AbstractInvocationHandler#hashCode}
*
{@code proxy.toString()} delegates to {@link AbstractInvocationHandler#toString}
*
{@code proxy.equals(argument)} returns true if:
*
*
{@code proxy} and {@code argument} are of the same type
*
and {@link AbstractInvocationHandler#equals} returns true for the {@link InvocationHandler} of
* {@code argument}
*
*
other method calls are dispatched to {@link #handleInvocation}.
*
*
* @throws Throwable
*/
@Override
public final Object invoke(Object proxy, Method invoked, @Nullable Object[] argv) throws Throwable {
if (argv == null) {
argv = NO_ARGS;
}
if (argv.length == 0 && invoked.getName().equals("hashCode")) {
return hashCode();
}
if (argv.length == 1 && invoked.getName().equals("equals") && invoked.getParameterTypes()[0] == Object.class) {
Object arg = argv[0];
return proxy.getClass().isInstance(arg) && equals(Proxy.getInvocationHandler(arg));
}
if (argv.length == 0 && invoked.getName().equals("toString")) {
return toString();
}
List