Java Code Examples for org.springframework.util.ObjectUtils#getIdentityHexString()

The following examples show how to use org.springframework.util.ObjectUtils#getIdentityHexString() . 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: BeanDefinitionParserDelegate.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Nullable
private BeanDefinitionHolder parseNestedCustomElement(Element ele, @Nullable BeanDefinition containingBd) {
	BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
	if (innerDefinition == null) {
		error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " +
				"This tag cannot be used nested inside <property>.", ele);
		return null;
	}
	String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR +
			ObjectUtils.getIdentityHexString(innerDefinition);
	if (logger.isTraceEnabled()) {
		logger.trace("Using generated bean name [" + id +
				"] for nested custom element '" + ele.getNodeName() + "'");
	}
	return new BeanDefinitionHolder(innerDefinition, id);
}
 
Example 2
Source File: BeanDefinitionParserDelegate.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Nullable
private BeanDefinitionHolder parseNestedCustomElement(Element ele, @Nullable BeanDefinition containingBd) {
	BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
	if (innerDefinition == null) {
		error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " +
				"This tag cannot be used nested inside <property>.", ele);
		return null;
	}
	String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR +
			ObjectUtils.getIdentityHexString(innerDefinition);
	if (logger.isTraceEnabled()) {
		logger.trace("Using generated bean name [" + id +
				"] for nested custom element '" + ele.getNodeName() + "'");
	}
	return new BeanDefinitionHolder(innerDefinition, id);
}
 
Example 3
Source File: BeanDefinitionReaderUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Generate a bean name for the given bean definition, unique within the
 * given bean factory.
 * @param definition the bean definition to generate a bean name for
 * @param registry the bean factory that the definition is going to be
 * registered with (to check for existing bean names)
 * @param isInnerBean whether the given bean definition will be registered
 * as inner bean or as top-level bean (allowing for special name generation
 * for inner beans versus top-level beans)
 * @return the generated bean name
 * @throws BeanDefinitionStoreException if no unique name can be generated
 * for the given bean definition
 */
public static String generateBeanName(
		BeanDefinition definition, BeanDefinitionRegistry registry, boolean isInnerBean)
		throws BeanDefinitionStoreException {

	String generatedBeanName = definition.getBeanClassName();
	if (generatedBeanName == null) {
		if (definition.getParentName() != null) {
			generatedBeanName = definition.getParentName() + "$child";
		}
		else if (definition.getFactoryBeanName() != null) {
			generatedBeanName = definition.getFactoryBeanName() + "$created";
		}
	}
	if (!StringUtils.hasText(generatedBeanName)) {
		throw new BeanDefinitionStoreException("Unnamed bean definition specifies neither " +
				"'class' nor 'parent' nor 'factory-bean' - can't generate bean name");
	}

	String id = generatedBeanName;
	if (isInnerBean) {
		// Inner bean: generate identity hashcode suffix.
		id = generatedBeanName + GENERATED_BEAN_NAME_SEPARATOR + ObjectUtils.getIdentityHexString(definition);
	}
	else {
		// Top-level bean: use plain class name with unique suffix if necessary.
		return uniqueBeanName(generatedBeanName, registry);
	}
	return id;
}
 
Example 4
Source File: AbstractServerHttpRequest.java    From java-technology-stack with MIT License 5 votes vote down vote up
public String getId() {
	if (this.id == null) {
		this.id = initId();
		if (this.id == null) {
			this.id = ObjectUtils.getIdentityHexString(this);
		}
	}
	return this.id;
}
 
Example 5
Source File: BeanDefinitionParserDelegate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
	BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
	if (innerDefinition == null) {
		error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " +
				"This tag cannot be used nested inside <property>.", ele);
		return null;
	}
	String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR +
			ObjectUtils.getIdentityHexString(innerDefinition);
	if (logger.isDebugEnabled()) {
		logger.debug("Using generated bean name [" + id +
				"] for nested custom element '" + ele.getNodeName() + "'");
	}
	return new BeanDefinitionHolder(innerDefinition, id);
}
 
Example 6
Source File: BeanDefinitionParserDelegate.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
	BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
	if (innerDefinition == null) {
		error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " +
				"This tag cannot be used nested inside <property>.", ele);
		return null;
	}
	String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR +
			ObjectUtils.getIdentityHexString(innerDefinition);
	if (logger.isDebugEnabled()) {
		logger.debug("Using generated bean name [" + id +
				"] for nested custom element '" + ele.getNodeName() + "'");
	}
	return new BeanDefinitionHolder(innerDefinition, id);
}
 
Example 7
Source File: StubWebApplicationContext.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public void addBeans(@Nullable List<?> beans) {
	if (beans != null) {
		for (Object bean : beans) {
			String name = bean.getClass().getName() + "#" + ObjectUtils.getIdentityHexString(bean);
			this.beanFactory.addBean(name, bean);
		}
	}
}
 
Example 8
Source File: BeanDefinitionReaderUtils.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a bean name for the given bean definition, unique within the
 * given bean factory.
 * @param definition the bean definition to generate a bean name for
 * @param registry the bean factory that the definition is going to be
 * registered with (to check for existing bean names)
 * @param isInnerBean whether the given bean definition will be registered
 * as inner bean or as top-level bean (allowing for special name generation
 * for inner beans versus top-level beans)
 * @return the generated bean name
 * @throws BeanDefinitionStoreException if no unique name can be generated
 * for the given bean definition
 */
public static String generateBeanName(
		BeanDefinition definition, BeanDefinitionRegistry registry, boolean isInnerBean)
		throws BeanDefinitionStoreException {

	String generatedBeanName = definition.getBeanClassName();
	if (generatedBeanName == null) {
		if (definition.getParentName() != null) {
			generatedBeanName = definition.getParentName() + "$child";
		}
		else if (definition.getFactoryBeanName() != null) {
			generatedBeanName = definition.getFactoryBeanName() + "$created";
		}
	}
	if (!StringUtils.hasText(generatedBeanName)) {
		throw new BeanDefinitionStoreException("Unnamed bean definition specifies neither " +
				"'class' nor 'parent' nor 'factory-bean' - can't generate bean name");
	}

	String id = generatedBeanName;
	if (isInnerBean) {
		// Inner bean: generate identity hashcode suffix.
		id = generatedBeanName + GENERATED_BEAN_NAME_SEPARATOR + ObjectUtils.getIdentityHexString(definition);
	}
	else {
		// Top-level bean: use plain class name.
		// Increase counter until the id is unique.
		int counter = -1;
		while (counter == -1 || registry.containsBeanDefinition(id)) {
			counter++;
			id = generatedBeanName + GENERATED_BEAN_NAME_SEPARATOR + counter;
		}
	}
	return id;
}
 
Example 9
Source File: BeanDefinitionParserDelegate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
	BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
	if (innerDefinition == null) {
		error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " +
				"This tag cannot be used nested inside <property>.", ele);
		return null;
	}
	String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR +
			ObjectUtils.getIdentityHexString(innerDefinition);
	if (logger.isDebugEnabled()) {
		logger.debug("Using generated bean name [" + id +
				"] for nested custom element '" + ele.getNodeName() + "'");
	}
	return new BeanDefinitionHolder(innerDefinition, id);
}
 
Example 10
Source File: BeanDefinitionReaderUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate a bean name for the given bean definition, unique within the
 * given bean factory.
 * @param definition the bean definition to generate a bean name for
 * @param registry the bean factory that the definition is going to be
 * registered with (to check for existing bean names)
 * @param isInnerBean whether the given bean definition will be registered
 * as inner bean or as top-level bean (allowing for special name generation
 * for inner beans versus top-level beans)
 * @return the generated bean name
 * @throws BeanDefinitionStoreException if no unique name can be generated
 * for the given bean definition
 */
public static String generateBeanName(
		BeanDefinition definition, BeanDefinitionRegistry registry, boolean isInnerBean)
		throws BeanDefinitionStoreException {

	String generatedBeanName = definition.getBeanClassName();
	if (generatedBeanName == null) {
		if (definition.getParentName() != null) {
			generatedBeanName = definition.getParentName() + "$child";
		}
		else if (definition.getFactoryBeanName() != null) {
			generatedBeanName = definition.getFactoryBeanName() + "$created";
		}
	}
	if (!StringUtils.hasText(generatedBeanName)) {
		throw new BeanDefinitionStoreException("Unnamed bean definition specifies neither " +
				"'class' nor 'parent' nor 'factory-bean' - can't generate bean name");
	}

	String id = generatedBeanName;
	if (isInnerBean) {
		// Inner bean: generate identity hashcode suffix.
		id = generatedBeanName + GENERATED_BEAN_NAME_SEPARATOR + ObjectUtils.getIdentityHexString(definition);
	}
	else {
		// Top-level bean: use plain class name.
		// Increase counter until the id is unique.
		int counter = -1;
		while (counter == -1 || registry.containsBeanDefinition(id)) {
			counter++;
			id = generatedBeanName + GENERATED_BEAN_NAME_SEPARATOR + counter;
		}
	}
	return id;
}
 
Example 11
Source File: StubWebApplicationContext.java    From java-technology-stack with MIT License 5 votes vote down vote up
public void addBeans(@Nullable List<?> beans) {
	if (beans != null) {
		for (Object bean : beans) {
			String name = bean.getClass().getName() + "#" + ObjectUtils.getIdentityHexString(bean);
			this.beanFactory.addBean(name, bean);
		}
	}
}
 
Example 12
Source File: AbstractMethodMessageHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public String getBeanName() {
	return this.beanName != null ? this.beanName :
			getClass().getSimpleName() + "@" + ObjectUtils.getIdentityHexString(this);
}
 
Example 13
Source File: AbstractMessageChannel.java    From java-technology-stack with MIT License 4 votes vote down vote up
public AbstractMessageChannel() {
	this.beanName = getClass().getSimpleName() + "@" + ObjectUtils.getIdentityHexString(this);
}
 
Example 14
Source File: VertxWebSocketSession.java    From vertx-spring-boot with Apache License 2.0 4 votes vote down vote up
public VertxWebSocketSession(WebSocketBase delegate, HandshakeInfo handshakeInfo, BufferConverter bufferConverter) {
    super(delegate, ObjectUtils.getIdentityHexString(delegate), handshakeInfo,
        bufferConverter.getDataBufferFactory());
    this.bufferConverter = bufferConverter;
}
 
Example 15
Source File: UndertowWebSocketSession.java    From java-technology-stack with MIT License 4 votes vote down vote up
public UndertowWebSocketSession(WebSocketChannel channel, HandshakeInfo info,
		DataBufferFactory factory, @Nullable MonoProcessor<Void> completionMono) {

	super(channel, ObjectUtils.getIdentityHexString(channel), info, factory, completionMono);
	suspendReceiving();
}
 
Example 16
Source File: NettyWebSocketSessionSupport.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected NettyWebSocketSessionSupport(T delegate, HandshakeInfo info, NettyDataBufferFactory factory) {
	super(delegate, ObjectUtils.getIdentityHexString(delegate), info, factory);
}
 
Example 17
Source File: ResponseBodyEmitter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public String toString() {
	return "ResponseBodyEmitter@" + ObjectUtils.getIdentityHexString(this);
}
 
Example 18
Source File: SseEmitter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public String toString() {
	return "SseEmitter@" + ObjectUtils.getIdentityHexString(this);
}
 
Example 19
Source File: UndertowServerHttpRequest.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected String initId() {
	return ObjectUtils.getIdentityHexString(this.exchange.getConnection());
}
 
Example 20
Source File: AbstractMessageChannel.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public AbstractMessageChannel() {
	this.beanName = getClass().getSimpleName() + "@" + ObjectUtils.getIdentityHexString(this);
}