Java Code Examples for org.springframework.util.Assert#isInstanceOf()

The following examples show how to use org.springframework.util.Assert#isInstanceOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeferredResultMethodReturnValueHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public DeferredResult<?> adaptToDeferredResult(Object returnValue) {
	Assert.isInstanceOf(ListenableFuture.class, returnValue, "ListenableFuture expected");
	final DeferredResult<Object> result = new DeferredResult<Object>();
	((ListenableFuture<?>) returnValue).addCallback(new ListenableFutureCallback<Object>() {
		@Override
		public void onSuccess(Object value) {
			result.setResult(value);
		}
		@Override
		public void onFailure(Throwable ex) {
			result.setErrorResult(ex);
		}
	});
	return result;
}
 
Example 2
Source File: KvMap.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
void flush() {
    Object obj;
    synchronized (this) {
        if(this.value == null) {
            // no value set, nothing to flush
            return;
        }
        this.dirty = false;
        obj = adapter.get(this.key, this.value);
    }
    // Note that message will be concatenated with type of object by `Assert.isInstanceOf`
    Assert.isInstanceOf(mapper.getType(), obj, "Adapter " + adapter + " return object of inappropriate");
    Assert.notNull(obj, "Adapter " + adapter + " return null from " + this.value + " that is not allowed");
    mapper.save(key, obj, (name, res) -> {
        synchronized (this) {
            index.put(toIndexKey(name), res.getIndex());
        }
    });
}
 
Example 3
Source File: NettyDataBufferFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>This implementation uses Netty's {@link CompositeByteBuf}.
 */
@Override
public DataBuffer join(List<? extends DataBuffer> dataBuffers) {
	Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty");
	int bufferCount = dataBuffers.size();
	if (bufferCount == 1) {
		return dataBuffers.get(0);
	}
	CompositeByteBuf composite = this.byteBufAllocator.compositeBuffer(bufferCount);
	for (DataBuffer dataBuffer : dataBuffers) {
		Assert.isInstanceOf(NettyDataBuffer.class, dataBuffer);
		composite.addComponent(true, ((NettyDataBuffer) dataBuffer).getNativeBuffer());
	}
	return new NettyDataBuffer(composite, this);
}
 
Example 4
Source File: WebUtils.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Gets the http servlet response.
 *
 * @param context the context
 * @return the http servlet response
 */
public static HttpServletResponse getHttpServletResponse(
    final RequestContext context) {
    Assert.isInstanceOf(ServletExternalContext.class, context
        .getExternalContext(),
        "Cannot obtain HttpServletResponse from event of type: "
            + context.getExternalContext().getClass().getName());
    return (HttpServletResponse) context.getExternalContext()
        .getNativeResponse();
}
 
Example 5
Source File: NettyDataBufferFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>This implementation uses Netty's {@link CompositeByteBuf}.
 */
@Override
public DataBuffer join(List<? extends DataBuffer> dataBuffers) {
	Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty");
	int bufferCount = dataBuffers.size();
	if (bufferCount == 1) {
		return dataBuffers.get(0);
	}
	CompositeByteBuf composite = this.byteBufAllocator.compositeBuffer(bufferCount);
	for (DataBuffer dataBuffer : dataBuffers) {
		Assert.isInstanceOf(NettyDataBuffer.class, dataBuffer);
		composite.addComponent(true, ((NettyDataBuffer) dataBuffer).getNativeBuffer());
	}
	return new NettyDataBuffer(composite, this);
}
 
Example 6
Source File: GenericSchema.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@PostMapping(path = "genericMapListUser")
public Generic<Map<String, List<User>>> genericMapListUser(
    @RequestBody Generic<Map<String, List<User>>> mapListUserGeneric) {
  Assert.isInstanceOf(Generic.class, mapListUserGeneric);
  Assert.isInstanceOf(Map.class, mapListUserGeneric.value);
  return mapListUserGeneric;
}
 
Example 7
Source File: SessionStatusMethodArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
@Override
public Object resolveArgumentValue(
		MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) {

	Assert.isInstanceOf(InitBinderBindingContext.class, bindingContext);
	return ((InitBinderBindingContext) bindingContext).getSessionStatus();
}
 
Example 8
Source File: MappingJackson2XmlHttpMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Construct a new {@code MappingJackson2XmlHttpMessageConverter} with a custom {@link ObjectMapper}
 * (must be a {@link XmlMapper} instance).
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#xml()
 */
public MappingJackson2XmlHttpMessageConverter(ObjectMapper objectMapper) {
	super(objectMapper, new MediaType("application", "xml"),
			new MediaType("text", "xml"),
			new MediaType("application", "*+xml"));
	Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
}
 
Example 9
Source File: ParameterizedTypeReference.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ParameterizedTypeReference() {
	Class<?> parameterizedTypeReferenceSubclass = findParameterizedTypeReferenceSubclass(getClass());
	Type type = parameterizedTypeReferenceSubclass.getGenericSuperclass();
	Assert.isInstanceOf(ParameterizedType.class, type, "Type must be a parameterized type");
	ParameterizedType parameterizedType = (ParameterizedType) type;
	Assert.isTrue(parameterizedType.getActualTypeArguments().length == 1, "Number of type arguments must be 1");
	this.type = parameterizedType.getActualTypeArguments()[0];
}
 
Example 10
Source File: MappingJackson2XmlHttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct a new {@code MappingJackson2XmlHttpMessageConverter} with a custom {@link ObjectMapper}
 * (must be a {@link XmlMapper} instance).
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#xml()
 */
public MappingJackson2XmlHttpMessageConverter(ObjectMapper objectMapper) {
	super(objectMapper, new MediaType("application", "xml"),
			new MediaType("text", "xml"),
			new MediaType("application", "*+xml"));
	Assert.isInstanceOf(XmlMapper.class, objectMapper, "XmlMapper required");
}
 
Example 11
Source File: WebUtils.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
public static HttpServletResponse getHttpServletResponse(
    final RequestContext context) {
    Assert.isInstanceOf(ServletExternalContext.class, context
        .getExternalContext(),
        "Cannot obtain HttpServletResponse from event of type: "
            + context.getExternalContext().getClass().getName());
    return (HttpServletResponse) context.getExternalContext()
        .getNativeResponse();
}
 
Example 12
Source File: ReactiveFirestoreTransactionManager.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
private static ReactiveFirestoreTransactionObject extractFirestoreTransaction(Object transaction) {

		Assert.isInstanceOf(ReactiveFirestoreTransactionObject.class, transaction,
				() -> String.format("Expected to find a %s but it turned out to be %s.",
						ReactiveFirestoreTransactionObject.class,
						transaction.getClass()));

		return (ReactiveFirestoreTransactionObject) transaction;
	}
 
Example 13
Source File: MappingJackson2SmileHttpMessageConverter.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 * The {@code ObjectMapper} must be configured with a {@code SmileFactory} instance.
 */
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
	Assert.isInstanceOf(SmileFactory.class, objectMapper.getFactory(), "SmileFactory required");
	super.setObjectMapper(objectMapper);
}
 
Example 14
Source File: DubboInterceptorTest.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Test
public void testServiceOverrideFromPlugin() {
    ContextManagerExtendService service = ServiceManager.INSTANCE.findService(ContextManagerExtendService.class);

    Assert.isInstanceOf(ContextManagerExtendOverrideService.class, service);
}
 
Example 15
Source File: AbstractStandardUpgradeStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected final HttpServletResponse getHttpServletResponse(ServerHttpResponse response) {
	Assert.isInstanceOf(ServletServerHttpResponse.class, response, "ServletServerHttpResponse required");
	return ((ServletServerHttpResponse) response).getServletResponse();
}
 
Example 16
Source File: JettyRequestUpgradeStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
private HttpServletRequest getHttpServletRequest(ServerHttpRequest request) {
	Assert.isInstanceOf(AbstractServerHttpRequest.class, request);
	return ((AbstractServerHttpRequest) request).getNativeRequest();
}
 
Example 17
Source File: PropertySourcesPlaceholdersResolver.java    From spring-cloud-gray with Apache License 2.0 4 votes vote down vote up
private static PropertySources getSources(Environment environment) {
    Assert.notNull(environment, "Environment must not be null");
    Assert.isInstanceOf(ConfigurableEnvironment.class, environment,
            "Environment must be a ConfigurableEnvironment");
    return ((ConfigurableEnvironment) environment).getPropertySources();
}
 
Example 18
Source File: TomcatRequestUpgradeStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
private HttpServletResponse getHttpServletResponse(ServerHttpResponse response) {
	Assert.isInstanceOf(AbstractServerHttpResponse.class, response, "ServletServerHttpResponse required");
	return ((AbstractServerHttpResponse) response).getNativeResponse();
}
 
Example 19
Source File: MvcUriComponentsBuilder.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * An alternative to {@link #fromMethodCall(Object)} that accepts a
 * {@code UriComponentsBuilder} representing the base URL. This is useful
 * when using MvcUriComponentsBuilder outside the context of processing a
 * request or to apply a custom baseUrl not matching the current request.
 * <p><strong>Note:</strong> This method extracts values from "Forwarded"
 * and "X-Forwarded-*" headers if found. See class-level docs.
 * @param builder the builder for the base URL; the builder will be cloned
 * and therefore not modified and may be re-used for further calls.
 * @param info either the value returned from a "mock" controller
 * invocation or the "mock" controller itself after an invocation
 * @return a UriComponents instance
 */
public static UriComponentsBuilder fromMethodCall(UriComponentsBuilder builder, Object info) {
	Assert.isInstanceOf(MethodInvocationInfo.class, info, "MethodInvocationInfo required");
	MethodInvocationInfo invocationInfo = (MethodInvocationInfo) info;
	Class<?> controllerType = invocationInfo.getControllerType();
	Method method = invocationInfo.getControllerMethod();
	Object[] arguments = invocationInfo.getArgumentValues();
	return fromMethodInternal(builder, controllerType, method, arguments);
}
 
Example 20
Source File: MvcUriComponentsBuilder.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Create a {@link UriComponentsBuilder} by invoking a "mock" controller method.
 * The controller method and the supplied argument values are then used to
 * delegate to {@link #fromMethod(Class, Method, Object...)}.
 * <p>For example, given this controller:
 * <pre class="code">
 * &#064;RequestMapping("/people/{id}/addresses")
 * class AddressController {
 *
 *   &#064;RequestMapping("/{country}")
 *   public HttpEntity&lt;Void&gt; getAddressesForCountry(&#064;PathVariable String country) { ... }
 *
 *   &#064;RequestMapping(value="/", method=RequestMethod.POST)
 *   public void addAddress(Address address) { ... }
 * }
 * </pre>
 * A UriComponentsBuilder can be created:
 * <pre class="code">
 * // Inline style with static import of "MvcUriComponentsBuilder.on"
 *
 * MvcUriComponentsBuilder.fromMethodCall(
 * 		on(AddressController.class).getAddressesForCountry("US")).buildAndExpand(1);
 *
 * // Longer form useful for repeated invocation (and void controller methods)
 *
 * AddressController controller = MvcUriComponentsBuilder.on(AddressController.class);
 * controller.addAddress(null);
 * builder = MvcUriComponentsBuilder.fromMethodCall(controller);
 * controller.getAddressesForCountry("US")
 * builder = MvcUriComponentsBuilder.fromMethodCall(controller);
 * </pre>
 * <p><strong>Note:</strong> This method extracts values from "Forwarded"
 * and "X-Forwarded-*" headers if found. See class-level docs.
 * @param info either the value returned from a "mock" controller
 * invocation or the "mock" controller itself after an invocation
 * @return a UriComponents instance
 * @see #on(Class)
 * @see #controller(Class)
 */
public static UriComponentsBuilder fromMethodCall(Object info) {
	Assert.isInstanceOf(MethodInvocationInfo.class, info, "MethodInvocationInfo required");
	MethodInvocationInfo invocationInfo = (MethodInvocationInfo) info;
	Class<?> controllerType = invocationInfo.getControllerType();
	Method method = invocationInfo.getControllerMethod();
	Object[] arguments = invocationInfo.getArgumentValues();
	return fromMethodInternal(null, controllerType, method, arguments);
}