org.jclouds.reflect.Invokable



API Populatity

2 Client projects

Project: org.jclouds

Project jclouds/jclouds in file ...ore.src.main.java.org.jclouds.reflect.Element.java (2013-01-08)
@@ -1,180 +0,0 @@
-/**
- * Licensed to jclouds, Inc. (jclouds) under one or more
- * contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  jclouds 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.reflect;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Member;
-import java.lang.reflect.Modifier;
-
-import org.jclouds.javax.annotation.Nullable;
-
-import org.jclouds.reflect.Invokable;
-
-/**
- * 
- * based on the {@link com.google.reflect.AccessibleObject} copied in as {@link com.google.reflect.Invokable} is package
- * private.
- * 
- * @author Adrian Cole
- * @since 1.6
- */
-class Element extends AccessibleObject implements Member {
-
-   private final AccessibleObject accessibleObject;
-   protected final Member member;
-
-   <M extends AccessibleObject & Member> Element( M member) {
-      this.member = checkNotNull(member, "member");
-      this.accessibleObject = member;
-   }
-
-   @Override
-   public final boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
-      return accessibleObject.isAnnotationPresent(annotationClass);
-   }
-
-   @Override
-   public final <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
-      return accessibleObject.getAnnotation(annotationClass);
-   }
-
-   @Override
-   public final Annotation[] getAnnotations() {
-      return accessibleObject.getAnnotations();
-   }
-
-   @Override
-   public final Annotation[] getDeclaredAnnotations() {
-      return accessibleObject.getDeclaredAnnotations();
-   }
-
-   @Override
-   public final void setAccessible(boolean flag) throws SecurityException {
-      accessibleObject.setAccessible(flag);
-   }
-
-   @Override
-   public final boolean isAccessible() {
-      return accessibleObject.isAccessible();
-   }
-
-   @Override
-   public Class<?> getDeclaringClass() {
-      return member.getDeclaringClass();
-   }
-
-   @Override
-   public final String getName() {
-      return member.getName();
-   }
-
-   @Override
-   public final int getModifiers() {
-      return member.getModifiers();
-   }
-
-   @Override
-   public final boolean isSynthetic() {
-      return member.isSynthetic();
-   }
-
-   /** Returns true if the element is public. */
-   public final boolean isPublic() {
-      return Modifier.isPublic(getModifiers());
-   }
-
-   /** Returns true if the element is protected. */
-   public final boolean isProtected() {
-      return Modifier.isProtected(getModifiers());
-   }
-
-   /** Returns true if the element is package-private. */
-   public final boolean isPackagePrivate() {
-      return !isPrivate() && !isPublic() && !isProtected();
-   }
-
-   /** Returns true if the element is private. */
-   public final boolean isPrivate() {
-      return Modifier.isPrivate(getModifiers());
-   }
-
-   /** Returns true if the element is static. */
-   public final boolean isStatic() {
-      return Modifier.isStatic(getModifiers());
-   }
-
-   /**
-    * Returns {@code true} if this method is final, per {@code Modifier.isFinal(getModifiers())}.
-    * 
-    * <p>
-    * Note that a method may still be effectively "final", or non-overridable when it has no {@code final} keyword. For
-    * example, it could be private, or it could be declared by a final class. To tell whether a method is overridable,
-    * use {@link Invokable#isOverridable}.
-    */
-   public final boolean isFinal() {
-      return Modifier.isFinal(getModifiers());
-   }
-
-   /** Returns true if the method is abstract. */
-   public final boolean isAbstract() {
-      return Modifier.isAbstract(getModifiers());
-   }
-
-   /** Returns true if the element is native. */
-   public final boolean isNative() {
-      return Modifier.isNative(getModifiers());
-   }
-
-   /** Returns true if the method is synchronized. */
-   public final boolean isSynchronized() {
-      return Modifier.isSynchronized(getModifiers());
-   }
-
-   /** Returns true if the field is volatile. */
-   final boolean isVolatile() {
-      return Modifier.isVolatile(getModifiers());
-   }
-
-   /** Returns true if the field is transient. */
-   final boolean isTransient() {
-      return Modifier.isTransient(getModifiers());
-   }
-
-   @Override
-   public boolean equals(@Nullable Object obj) {
-      if (obj instanceof Element) {
-         Element that = (Element) obj;
-         return member.equals(that.member);
-      }
-      return false;
-   }
-
-   @Override
-   public int hashCode() {
-      return member.hashCode();
-   }
-
-   @Override
-   public String toString() {
-      return member.toString();
-   }
-}
Project jclouds/jclouds in file ...n.java.org.jclouds.rest.config.ClientProvider.java (2013-01-08)
@@ -1,59 +0,0 @@
-/**
- * Licensed to jclouds, Inc. (jclouds) under one or more
- * contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  jclouds 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.config;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.jclouds.reflect.FunctionalReflection;
-import org.jclouds.reflect.Invokable;
-import org.jclouds.rest.internal.InvokeSyncApi;
-
-import com.google.common.cache.Cache;
-import com.google.common.reflect.TypeToken;
-import com.google.inject.Provider;
-
-/**
- * ClientProvider makes the primary interface for the provider context. ex.
- * {@code context.getProviderSpecificContext().getApi()} is created by ClientProvider, which is a singleton
- * 
- * @author Adrian Cole
- */
-@Singleton
-public class ClientProvider<S, A> implements Provider<S> {
-
-   private final InvokeSyncApi.Factory factory;
-   private final Class<S> syncClientType;
-   private final A asyncClient;
-
-   @Inject
-   private ClientProvider(Cache<Invokable<?, ?>, Invokable<?, ?>> invokables, InvokeSyncApi.Factory factory,
-         Class<S> syncClientType, Class<A> asyncClientType, A asyncClient) {
-      this.factory = factory;
-      this.asyncClient = asyncClient;
-      this.syncClientType = syncClientType;
-      RestModule.putInvokables(TypeToken.of(syncClientType), TypeToken.of(asyncClientType), invokables);
-   }
-
-   @Override
-   @Singleton
-   public S get() {
-      return FunctionalReflection.newProxy(syncClientType, factory.create(asyncClient));
-   }
-}
Project jclouds/jclouds in file ....jclouds.rest.internal.BaseInvocationFunction.java (2013-01-08)
@@ -1,127 +0,0 @@
-package org.jclouds.rest.internal;
-
-import static com.google.common.base.Throwables.propagate;
-import static com.google.common.collect.Iterables.find;
-import static com.google.inject.util.Types.newParameterizedType;
-import static org.jclouds.util.Optionals2.isReturnTypeOptional;
-import static org.jclouds.util.Optionals2.unwrapIfOptional;
-import static org.jclouds.util.Throwables2.getFirstThrowableOfType;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-
-import javax.inject.Qualifier;
-
-import org.jclouds.reflect.FunctionalReflection;
-import org.jclouds.reflect.Invocation;
-import org.jclouds.reflect.Invocation.Result;
-import org.jclouds.reflect.InvocationSuccess;
-import org.jclouds.reflect.Invokable;
-import org.jclouds.rest.AuthorizationException;
-import org.jclouds.rest.annotations.Delegate;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Function;
-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.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;
-
-@Beta
-abstract class BaseInvocationFunction implements Function<Invocation, Result> {
-   protected final Injector injector;
-   protected final Function<InvocationSuccess, Optional<Object>> optionalConverter;
-
-   protected BaseInvocationFunction(Injector injector, Function<InvocationSuccess, Optional<Object>> optionalConverter) {
-      this.injector = injector;
-      this.optionalConverter = optionalConverter;
-   }
-
-   protected abstract Result invoke(Invocation in);
-
-   protected abstract Function<Invocation, Result> forwardInvocations(Invocation invocation, Class<?> returnType);
-
-   @Override
-   public Result apply(Invocation invocation) {
-      if (invocation.getInvokable().isAnnotationPresent(Provides.class))
-         return Result.success(lookupValueFromGuice(invocation.getInvokable()));
-      else if (invocation.getInvokable().isAnnotationPresent(Delegate.class))
-         return Result.success(propagateContextToDelegate(invocation));
-      return invoke(invocation);
-   }
-
-   private Object propagateContextToDelegate(Invocation invocation) {
-      Class<?> returnType = unwrapIfOptional(invocation.getInvokable().getReturnType());
-      Object result = FunctionalReflection.newProxy(returnType, forwardInvocations(invocation, returnType));
-      if (isReturnTypeOptional(invocation.getInvokable())) {
-         result = optionalConverter.apply(InvocationSuccess.create(invocation, result));
-      }
-      return result;
-   }
-
-   static final Predicate<Annotation> isQualifierPresent = new Predicate<Annotation>() {
-      public boolean apply(Annotation input) {
-         return input.annotationType().isAnnotationPresent(Qualifier.class);
-      }
-   };
-
-   private Object lookupValueFromGuice(Invokable<?, ?> invoked) {
-      try {
-         Type genericReturnType = invoked.getReturnType().getType();
-         try {
-            Annotation qualifier = find(ImmutableList.copyOf(invoked.getAnnotations()), isQualifierPresent);
-            return getInstanceOfTypeWithQualifier(genericReturnType, qualifier);
-         } catch (ProvisionException e) {
-            throw propagate(e.getCause());
-         } catch (RuntimeException e) {
-            return instanceOfTypeOrPropagate(genericReturnType, e);
-         }
-      } catch (ProvisionException e) {
-         AuthorizationException aex = getFirstThrowableOfType(e, AuthorizationException.class);
-         if (aex != null)
-            throw aex;
-         throw e;
-      }
-   }
-
-   Object instanceOfTypeOrPropagate(Type genericReturnType, RuntimeException e) {
-      try {
-         // look for an existing binding
-         Binding<?> binding = injector.getExistingBinding(Key.get(genericReturnType));
-         if (binding != null)
-            return binding.getProvider().get();
-
-         // then, try looking via supplier
-         binding = injector.getExistingBinding(Key.get(newParameterizedType(Supplier.class, genericReturnType)));
-         if (binding != null)
-            return Supplier.class.cast(binding.getProvider().get()).get();
-
-         // else try to create an instance
-         return injector.getInstance(Key.get(genericReturnType));
-      } catch (ConfigurationException ce) {
-         throw e;
-      }
-   }
-
-   Object getInstanceOfTypeWithQualifier(Type genericReturnType, Annotation qualifier) {
-      // look for an existing binding
-      Binding<?> binding = injector.getExistingBinding(Key.get(genericReturnType, qualifier));
-      if (binding != null)
-         return binding.getProvider().get();
-
-      // then, try looking via supplier
-      binding = injector
-            .getExistingBinding(Key.get(newParameterizedType(Supplier.class, genericReturnType), qualifier));
-      if (binding != null)
-         return Supplier.class.cast(binding.getProvider().get()).get();
-
-      // else try to create an instance
-      return injector.getInstance(Key.get(genericReturnType, qualifier));
-   }
-}
\ No newline at end of file