org.springframework.lang.Nullable源码实例Demo

javax.servlet.http.PushBuilder#org.springframework.lang.Nullable源码实例Demo

下面列出了javax.servlet.http.PushBuilder#org.springframework.lang.Nullable 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Look up a handler instance for the given URL lookup path.
 * <p>Supports direct matches, e.g. a registered "/test" matches "/test",
 * and various path pattern matches, e.g. a registered "/t*" matches
 * both "/test" and "/team". For details, see the PathPattern class.
 * @param lookupPath the URL the handler is mapped to
 * @param exchange the current exchange
 * @return the associated handler instance, or {@code null} if not found
 * @see org.springframework.web.util.pattern.PathPattern
 */
@Nullable
protected Object lookupHandler(PathContainer lookupPath, ServerWebExchange exchange) throws Exception {

	List<PathPattern> matches = this.handlerMap.keySet().stream()
			.filter(key -> key.matches(lookupPath))
			.collect(Collectors.toList());

	if (matches.isEmpty()) {
		return null;
	}

	if (matches.size() > 1) {
		matches.sort(PathPattern.SPECIFICITY_COMPARATOR);
		if (logger.isTraceEnabled()) {
			logger.debug(exchange.getLogPrefix() + "Matching patterns " + matches);
		}
	}

	PathPattern pattern = matches.get(0);
	PathContainer pathWithinMapping = pattern.extractPathWithinPattern(lookupPath);
	return handleMatch(this.handlerMap.get(pattern), pattern, pathWithinMapping, exchange);
}
 
/**
 * Find the JTA UserTransaction through a default JNDI lookup:
 * "java:comp/UserTransaction".
 * @return the JTA UserTransaction reference, or {@code null} if not found
 * @see #DEFAULT_USER_TRANSACTION_NAME
 */
@Nullable
protected UserTransaction findUserTransaction() {
	String jndiName = DEFAULT_USER_TRANSACTION_NAME;
	try {
		UserTransaction ut = getJndiTemplate().lookup(jndiName, UserTransaction.class);
		if (logger.isDebugEnabled()) {
			logger.debug("JTA UserTransaction found at default JNDI location [" + jndiName + "]");
		}
		this.userTransactionObtainedFromJndi = true;
		return ut;
	}
	catch (NamingException ex) {
		if (logger.isDebugEnabled()) {
			logger.debug("No JTA UserTransaction found at default JNDI location [" + jndiName + "]", ex);
		}
		return null;
	}
}
 
/**
 * Bind the given RequestAttributes to the current thread.
 * @param attributes the RequestAttributes to expose,
 * or {@code null} to reset the thread-bound context
 * @param inheritable whether to expose the RequestAttributes as inheritable
 * for child threads (using an {@link InheritableThreadLocal})
 */
public static void setRequestAttributes(@Nullable RequestAttributes attributes, boolean inheritable) {
	if (attributes == null) {
		resetRequestAttributes();
	}
	else {
		if (inheritable) {
			inheritableRequestAttributesHolder.set(attributes);
			requestAttributesHolder.remove();
		}
		else {
			requestAttributesHolder.set(attributes);
			inheritableRequestAttributesHolder.remove();
		}
	}
}
 
/**
 * Return the (raw) singleton object registered under the given name.
 * <p>Checks already instantiated singletons and also allows for an early
 * reference to a currently created singleton (resolving a circular reference).
 * @param beanName the name of the bean to look for
 * @param allowEarlyReference whether early references should be created or not
 * @return the registered singleton object, or {@code null} if none found
 */
@Nullable
protected Object getSingleton(String beanName, boolean allowEarlyReference) {
	Object singletonObject = this.singletonObjects.get(beanName);
	if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {
		synchronized (this.singletonObjects) {
			singletonObject = this.earlySingletonObjects.get(beanName);
			if (singletonObject == null && allowEarlyReference) {
				ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName);
				if (singletonFactory != null) {
					singletonObject = singletonFactory.getObject();
					this.earlySingletonObjects.put(beanName, singletonObject);
					this.singletonFactories.remove(beanName);
				}
			}
		}
	}
	return singletonObject;
}
 
@Nullable
private SpelNodeImpl eatPrimaryExpression() {
	SpelNodeImpl start = eatStartNode();  // always a start node
	List<SpelNodeImpl> nodes = null;
	SpelNodeImpl node = eatNode();
	while (node != null) {
		if (nodes == null) {
			nodes = new ArrayList<>(4);
			nodes.add(start);
		}
		nodes.add(node);
		node = eatNode();
	}
	if (start == null || nodes == null) {
		return start;
	}
	return new CompoundExpression(start.getStartPosition(), nodes.get(nodes.size() - 1).getEndPosition(),
			nodes.toArray(new SpelNodeImpl[0]));
}
 
源代码6 项目: java-technology-stack   文件: ObjectUtils.java
/**
 * Return a String representation of the contents of the specified array.
 * <p>The String representation consists of a list of the array's elements,
 * enclosed in curly braces ({@code "{}"}). Adjacent elements are separated
 * by the characters {@code ", "} (a comma followed by a space). Returns
 * {@code "null"} if {@code array} is {@code null}.
 * @param array the array to build a String representation for
 * @return a String representation of {@code array}
 */
public static String nullSafeToString(@Nullable short[] array) {
	if (array == null) {
		return NULL_STRING;
	}
	int length = array.length;
	if (length == 0) {
		return EMPTY_ARRAY;
	}
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < length; i++) {
		if (i == 0) {
			sb.append(ARRAY_START);
		}
		else {
			sb.append(ARRAY_ELEMENT_SEPARATOR);
		}
		sb.append(array[i]);
	}
	sb.append(ARRAY_END);
	return sb.toString();
}
 
/**
 * Locate or create the RMI registry for this exporter.
 * @param registryHost the registry host to use (if this is specified,
 * no implicit creation of a RMI registry will happen)
 * @param registryPort the registry port to use
 * @param clientSocketFactory the RMI client socket factory for the registry (if any)
 * @param serverSocketFactory the RMI server socket factory for the registry (if any)
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(String registryHost, int registryPort,
		@Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (registryHost != null) {
		// Host explicitly specified: only lookup possible.
		if (logger.isDebugEnabled()) {
			logger.debug("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]");
		}
		Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory);
		testRegistry(reg);
		return reg;
	}

	else {
		return getRegistry(registryPort, clientSocketFactory, serverSocketFactory);
	}
}
 
@Override
@Nullable
public InputStream getResourceAsStream(String path) {
	Resource resource = this.resourceLoader.getResource(getResourceLocation(path));
	if (!resource.exists()) {
		return null;
	}
	try {
		return resource.getInputStream();
	}
	catch (IOException ex) {
		if (logger.isWarnEnabled()) {
			logger.warn("Could not open InputStream for " + resource, ex);
		}
		return null;
	}
}
 
@Override
public boolean equals(@Nullable Object other) {
	if (this == other) {
		return true;
	}
	if (other == null || getClass() != other.getClass()) {
		return false;
	}
	return this.path.equals(((DefaultPathContainer) other).path);
}
 
/**
 * Constructor with converters and {@code Request~} and {@code ResponseBodyAdvice}.
 * @since 4.2
 */
public AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters,
		@Nullable List<Object> requestResponseBodyAdvice) {

	Assert.notEmpty(converters, "'messageConverters' must not be empty");
	this.messageConverters = converters;
	this.allSupportedMediaTypes = getAllSupportedMediaTypes(converters);
	this.advice = new RequestResponseBodyAdviceChain(requestResponseBodyAdvice);
}
 
/**
 * Configure the complete list of supported return value types thus
 * overriding handlers that would otherwise be configured by default.
 */
public void setReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers) {
	if (returnValueHandlers == null) {
		this.returnValueHandlers = null;
	}
	else {
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
		this.returnValueHandlers.addHandlers(returnValueHandlers);
	}
}
 
@Override
@SuppressWarnings("resource")
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
	Assert.state(response != null, "No HttpServletResponse");
	ServerHttpResponse outputMessage = new ServletServerHttpResponse(response);

	if (returnValue instanceof ResponseEntity) {
		ResponseEntity<?> responseEntity = (ResponseEntity<?>) returnValue;
		response.setStatus(responseEntity.getStatusCodeValue());
		outputMessage.getHeaders().putAll(responseEntity.getHeaders());
		returnValue = responseEntity.getBody();
		if (returnValue == null) {
			mavContainer.setRequestHandled(true);
			outputMessage.flush();
			return;
		}
	}

	ServletRequest request = webRequest.getNativeRequest(ServletRequest.class);
	Assert.state(request != null, "No ServletRequest");
	ShallowEtagHeaderFilter.disableContentCaching(request);

	Assert.isInstanceOf(StreamingResponseBody.class, returnValue, "StreamingResponseBody expected");
	StreamingResponseBody streamingBody = (StreamingResponseBody) returnValue;

	Callable<Void> callable = new StreamingResponseBodyTask(outputMessage.getBody(), streamingBody);
	WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(callable, mavContainer);
}
 
@Nullable
private Object assertExistsAndReturn(String content) {
	Object value = evaluateJsonPath(content);
	String reason = "No value at JSON path \"" + this.expression + "\"";
	AssertionErrors.assertTrue(reason, value != null);
	if (pathIsIndefinite() && value instanceof List) {
		AssertionErrors.assertTrue(reason, !((List<?>) value).isEmpty());
	}
	return value;
}
 
源代码14 项目: spring-analysis-note   文件: ExpressionState.java
@Nullable
public Object lookupLocalVariable(String name) {
	for (VariableScope scope : initVariableScopes()) {
		if (scope.definesVariable(name)) {
			return scope.lookupVariable(name);
		}
	}
	return null;
}
 
@Override
@Nullable
public V getOrDefault(Object key, V defaultValue) {
	if (key instanceof String) {
		String caseInsensitiveKey = this.caseInsensitiveKeys.get(convertKey((String) key));
		if (caseInsensitiveKey != null) {
			return this.targetMap.get(caseInsensitiveKey);
		}
	}
	return defaultValue;
}
 
源代码16 项目: spring-analysis-note   文件: StompHeaders.java
/**
 * Return the first header value for the given header name, if any.
 * @param headerName the header name
 * @return the first header value, or {@code null} if none
 */
@Override
@Nullable
public String getFirst(String headerName) {
	List<String> headerValues = this.headers.get(headerName);
	return headerValues != null ? headerValues.get(0) : null;
}
 
源代码17 项目: spring-analysis-note   文件: RestTemplate.java
@Override
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
		Class<T> responseType) throws RestClientException {

	RequestCallback requestCallback = httpEntityCallback(requestEntity, responseType);
	ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
	return nonNull(execute(url, method, requestCallback, responseExtractor));
}
 
@Override
public void contributeMethodArgument(MethodParameter parameter, @Nullable Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	Class<?> paramType = parameter.getNestedParameterType();
	if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType || Part.class == paramType) {
		return;
	}

	RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class);
	String name = (requestParam != null && StringUtils.hasLength(requestParam.name()) ?
			requestParam.name() : parameter.getParameterName());
	Assert.state(name != null, "Unresolvable parameter name");

	parameter = parameter.nestedIfOptional();
	if (value instanceof Optional) {
		value = ((Optional<?>) value).orElse(null);
	}

	if (value == null) {
		if (requestParam != null &&
				(!requestParam.required() || !requestParam.defaultValue().equals(ValueConstants.DEFAULT_NONE))) {
			return;
		}
		builder.queryParam(name);
	}
	else if (value instanceof Collection) {
		for (Object element : (Collection<?>) value) {
			element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
			builder.queryParam(name, element);
		}
	}
	else {
		builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
	}
}
 
@Nullable
public static MultipartRequest resolveMultipartRequest(NativeWebRequest webRequest) {
	MultipartRequest multipartRequest = webRequest.getNativeRequest(MultipartRequest.class);
	if (multipartRequest != null) {
		return multipartRequest;
	}
	HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
	if (servletRequest != null && isMultipartContent(servletRequest)) {
		return new StandardMultipartHttpServletRequest(servletRequest);
	}
	return null;
}
 
源代码20 项目: spring-analysis-note   文件: CodeFlow.java
/**
 * Determine if the supplied descriptor is for a supported number type or boolean. The
 * compilation process only (currently) supports certain number types. These are
 * double, float, long and int.
 * @param descriptor the descriptor for a type
 * @return {@code true} if the descriptor is for a supported numeric type or boolean
 */
public static boolean isPrimitiveOrUnboxableSupportedNumberOrBoolean(@Nullable String descriptor) {
	if (descriptor == null) {
		return false;
	}
	if (isPrimitiveOrUnboxableSupportedNumber(descriptor)) {
		return true;
	}
	return ("Z".equals(descriptor) || descriptor.equals("Ljava/lang/Boolean"));
}
 
源代码21 项目: java-technology-stack   文件: AbstractErrors.java
/**
 * Transform the given field into its full path,
 * regarding the nested path of this instance.
 */
protected String fixedField(@Nullable String field) {
	if (StringUtils.hasLength(field)) {
		return getNestedPath() + canonicalFieldName(field);
	}
	else {
		String path = getNestedPath();
		return (path.endsWith(Errors.NESTED_PATH_SEPARATOR) ?
				path.substring(0, path.length() - NESTED_PATH_SEPARATOR.length()) : path);
	}
}
 
public ResourceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) {
	super(member, pd);
	Resource resource = ae.getAnnotation(Resource.class);
	String resourceName = resource.name();
	Class<?> resourceType = resource.type();
	this.isDefaultName = !StringUtils.hasLength(resourceName);
	if (this.isDefaultName) {
		resourceName = this.member.getName();
		if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
			resourceName = Introspector.decapitalize(resourceName.substring(3));
		}
	}
	else if (embeddedValueResolver != null) {
		resourceName = embeddedValueResolver.resolveStringValue(resourceName);
	}
	if (Object.class != resourceType) {
		checkResourceType(resourceType);
	}
	else {
		// No resource type specified... check field/method.
		resourceType = getResourceType();
	}
	this.name = (resourceName != null ? resourceName : "");
	this.lookupType = resourceType;
	String lookupValue = resource.lookup();
	this.mappedName = (StringUtils.hasLength(lookupValue) ? lookupValue : resource.mappedName());
	Lazy lazy = ae.getAnnotation(Lazy.class);
	this.lazyLookup = (lazy != null && lazy.value());
}
 
@Substitute
public static Set<BeanDefinitionHolder> registerAnnotationConfigProcessors(BeanDefinitionRegistry registry,
        @Nullable Object source) {
    return Collections.emptySet();
}
 
@Override
public void setValue(EvaluationContext context, Object rootObject, @Nullable Object value) throws EvaluationException {
	throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression");
}
 
BadGateway(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
	super(HttpStatus.BAD_GATEWAY, statusText, headers, body, charset);
}
 
源代码26 项目: spring-analysis-note   文件: LiteralExpression.java
@Override
@Nullable
public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException {
	Object value = getValue();
	return ExpressionUtils.convertTypedValue(null, new TypedValue(value), expectedResultType);
}
 
/**
 * Return the configured Marshaller.
 */
@Nullable
public Marshaller getMarshaller() {
	return this.marshaller;
}
 
源代码28 项目: java-technology-stack   文件: ProtobufEncoder.java
@Override
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType) {
	return Message.class.isAssignableFrom(elementType.toClass()) && supportsMimeType(mimeType);
}
 
@Override
@Nullable
public JobDetail getObject() {
	return this.jobDetail;
}
 
@Alias
public static List<String> loadFactoryNames(Class<?> factoryType, @Nullable ClassLoader classLoader) {
	return null;
}