List of usage examples for com.google.common.reflect Invokable getOwnerType
@SuppressWarnings("unchecked") @Override public TypeToken<T> getOwnerType()
From source file:org.jclouds.aws.filters.FormSignerUtils.java
private static Optional<String> getAnnotatedApiVersion(Invocation invocation) { final Invokable<?, ?> invokable = invocation.getInvokable(); if (invokable.isAnnotationPresent(ApiVersionOverride.class)) { return Optional.fromNullable(invokable.getAnnotation(ApiVersionOverride.class).value()); } else {//w w w . j a v a2 s . c o m final Class<?> owner = invokable.getOwnerType().getRawType(); if (owner.isAnnotationPresent(ApiVersionOverride.class)) { return Optional.fromNullable(owner.getAnnotation(ApiVersionOverride.class).value()); } } return Optional.absent(); }
From source file:org.jclouds.azurecompute.arm.filters.ApiVersionFilter.java
@Override public HttpRequest filter(HttpRequest request) throws HttpException { checkArgument(request instanceof GeneratedHttpRequest, "This filter can only be applied to GeneratedHttpRequest objects"); GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; // Look if there is a custom api version for the current method String commandName = config.getCommandName(generatedRequest.getInvocation()); String customApiVersion = versions.get(commandName); if (customApiVersion == null) { // No custom config for the specific method. Let's look for custom // config for the class Invokable<?, ?> invoked = generatedRequest.getInvocation().getInvokable(); String className = invoked.getOwnerType().getRawType().getSimpleName(); customApiVersion = versions.get(className); }//from ww w . j a v a 2 s.com if (customApiVersion != null) { return request.toBuilder().replaceQueryParam("api-version", customApiVersion).build(); } return request; }
From source file:org.jclouds.oauth.v2.functions.BuildTokenRequest.java
protected String getOAuthScopes(GeneratedHttpRequest request) { Invokable<?, ?> invokable = request.getInvocation().getInvokable(); OAuthScopes classScopes = invokable.getOwnerType().getRawType().getAnnotation(OAuthScopes.class); OAuthScopes methodScopes = invokable.getAnnotation(OAuthScopes.class); // if no annotations are present the rely on globally set scopes if (classScopes == null && methodScopes == null) { checkState(globalScopes != null, String.format("REST class or method should be annotated " + "with OAuthScopes specifying required permissions. Alternatively a global property " + "\"oauth.scopes\" may be set to define scopes globally. REST Class: %s, Method: %s", invokable.getOwnerType(), invokable.getName())); return globalScopes; }//w w w . j a va 2 s . c o m OAuthScopes scopes = methodScopes != null ? methodScopes : classScopes; return Joiner.on(",").join(scopes.value()); }
From source file:org.jclouds.rest.config.ReadAnnotationsAndProperties.java
@Override public Optional<Long> getTimeoutNanos(Invocation in) { String commandName = getCommandName(in); Optional<Long> defaultMillis = fromNullable(timeouts.get("default")); Optional<Long> timeoutMillis = fromNullable(timeouts.get(commandName)); Invokable<?, ?> invoked = in.getInvokable(); if (invoked.isAnnotationPresent(Named.class)) { timeoutMillis = timeoutMillis.or(defaultMillis); } else {// www. j a v a2s. co m // TODO: remove old logic once Named annotations are on all methods String className = invoked.getOwnerType().getRawType().getSimpleName().replace("AsyncClient", "Client") .replace("AsyncApi", "Api"); timeoutMillis = timeoutMillis.or(fromNullable(timeouts.get(className))).or(defaultMillis); } if (timeoutMillis.isPresent()) return Optional.of(MILLISECONDS.toNanos(timeoutMillis.get())); return Optional.absent(); }
From source file:org.jclouds.rest.config.ReadAnnotationsAndProperties.java
@Override public String getCommandName(Invocation invocation) { Invokable<?, ?> invoked = invocation.getInvokable(); if (invoked.isAnnotationPresent(Named.class)) { return invoked.getAnnotation(Named.class).value(); } else {/*from w w w .j a v a 2 s. com*/ // TODO: remove old logic once Named annotations are on all methods String className = invoked.getOwnerType().getRawType().getSimpleName().replace("AsyncClient", "Client") .replace("AsyncApi", "Api"); return className + "." + invoked.getName(); } }
From source file:org.jclouds.rest.internal.BlockOnFuture.java
private Optional<Long> timeoutInNanos(Invokable<?, ?> invoked, Map<String, Long> timeouts) { Optional<Long> defaultMillis = fromNullable(timeouts.get("default")); Optional<Long> timeoutMillis; if (invoked.isAnnotationPresent(Named.class)) { String commandName = invoked.getAnnotation(Named.class).value(); timeoutMillis = fromNullable(timeouts.get(commandName)).or(defaultMillis); } else {// w w w. ja v a2 s . co m // TODO: remove old logic, once Named annotations are present on all methods String className = invoked.getOwnerType().getRawType().getSimpleName().replace("AsyncClient", "Client") .replace("AsyncApi", "Api"); timeoutMillis = fromNullable(timeouts.get(className + "." + invoked.getName())) .or(fromNullable(timeouts.get(className))).or(defaultMillis); } if (timeoutMillis.isPresent()) return Optional.of(TimeUnit.MILLISECONDS.toNanos(timeoutMillis.get())); return Optional.absent(); }