当前位置: 首页>>代码示例>>Java>>正文


Java TypeUtils.isAssignable方法代码示例

本文整理汇总了Java中com.holonplatform.core.internal.utils.TypeUtils.isAssignable方法的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils.isAssignable方法的具体用法?Java TypeUtils.isAssignable怎么用?Java TypeUtils.isAssignable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.holonplatform.core.internal.utils.TypeUtils的用法示例。


在下文中一共展示了TypeUtils.isAssignable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> get(String resourceKey, Class<T> resourceType) throws TypeMismatchException {
	ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");
	ObjectUtils.argumentNotNull(resourceType, "Resource type must be not null");

	final VaadinSession session = VaadinSession.getCurrent();

	if (session != null) {

		Object value = session.getAttribute(resourceKey);
		if (value != null) {

			// check type
			if (!TypeUtils.isAssignable(value.getClass(), resourceType)) {
				throw new TypeMismatchException("<" + NAME + "> Actual resource type [" + value.getClass().getName()
						+ "] and required resource type [" + resourceType.getName() + "] mismatch");
			}

			return Optional.of((T) value);

		}
	}

	return Optional.empty();
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:27,代码来源:VaadinSessionScope.java

示例2: convert

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public R convert(Q result) throws QueryResultConversionException {
	try {
		final Object value = getResult(expression, result);

		// check type
		if (value != null && !TypeUtils.isAssignable(value.getClass(), expression.getType())) {
			throw new QueryResultConversionException("Expected a value of projection type ["
					+ expression.getType().getName() + "], got a value of type: " + value.getClass().getName());
		}

		return (R) value;

	} catch (Exception e) {
		throw new QueryResultConversionException(
				"Failed to convert query result for expression [" + expression + "]", e);
	}

}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:21,代码来源:SingleSelectionResultConverter.java

示例3: getAuthorizer

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Get {@link Authorizer} to use with given permission type
 * <p>
 * This first Authorizer registered in this Realm which is consistent with given <code>permissionType</code> is
 * used.
 * </p>
 * @param permissionType Permission type
 * @return Authorizer
 * @throws UnsupportedPermissionException If no {@link Authorizer} is available for given permission type
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Authorizer<Permission> getAuthorizer(Class<? extends Permission> permissionType)
		throws UnsupportedPermissionException {
	Authorizer<Permission> permissionAuthorizer = null;
	for (Authorizer authorizer : getAuthorizers()) {
		if (TypeUtils.isAssignable(permissionType, authorizer.getPermissionType())) {
			permissionAuthorizer = authorizer;
			break;
		}
	}

	if (permissionAuthorizer == null) {
		throw new UnsupportedPermissionException("Unsupported permission type: " + permissionType.getName()
				+ " - No suitable Authorizer available in Realm");
	}

	return permissionAuthorizer;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:29,代码来源:DefaultRealm.java

示例4: getAndCheckPropertyValue

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Get value for given property, checking type consistency and apply any {@link PropertyValueConverter} bound to
 * property.
 * <p>
 * Actual property value must be provided by subclasses through {@link #getPropertyValue(Property)} method.
 * </p>
 * @param <T> Property type
 * @param property Property for which obtain the value
 * @return Property value
 * @throws PropertyAccessException Error handling property value
 */
@SuppressWarnings("unchecked")
protected <T> T getAndCheckPropertyValue(Property<T> property) throws PropertyAccessException {
	// check value provider
	if (property instanceof VirtualProperty) {
		return getValueProviderPropertyValue((VirtualProperty<T>) property);
	}

	// use delegate method to obtain value
	Object value = getPropertyValue(property);

	// check type
	if (value != null) {
		if (!TypeUtils.isAssignable(value.getClass(), property.getType())) {
			throw new TypeMismatchException("Value type " + value.getClass().getName()
					+ " doesn't match property type " + property.getType().getName());
		}
	}

	return (T) value;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:32,代码来源:AbstractPropertyBox.java

示例5: get

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Get a value of given <code>type</code> identified by given <code>key</code>.
 * @param key Resource key
 * @param type Resource type
 * @return Resource value, or <code>null</code> if not found
 * @param <T> Resource type
 * @throws TypeMismatchException Expected and actual resource type mismatch
 */
@SuppressWarnings("unchecked")
public <T> T get(String key, Class<T> type) throws TypeMismatchException {
	ObjectUtils.argumentNotNull(key, "Resource key must be not null");
	ObjectUtils.argumentNotNull(type, "Resource type must be not null");

	LOGGER.debug(() -> "<" + scopeName + "> get resource with key [" + key + "]");

	Object resource = resources.get(key);
	if (resource != null) {
		// check type
		if (!TypeUtils.isAssignable(resource.getClass(), type)) {
			throw new TypeMismatchException(
					"<" + scopeName + "> Actual resource type [" + resource.getClass().getName()
							+ "] and required resource type [" + type.getName() + "] mismatch");
		}

		LOGGER.debug(() -> "<" + scopeName + "> Retrieved resource value of type [" + resource.getClass().getName()
				+ "] for key [" + key + "]");

		return (T) resource;
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:32,代码来源:ContextResourceMap.java

示例6: read

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <V> V read(String propertyName, T instance) {
	ObjectUtils.argumentNotNull(propertyName, "Property name must be not null");
	ObjectUtils.argumentNotNull(instance, "Bean instance must be not null");

	final BeanProperty<?> property = (BeanProperty<?>) requireProperty(propertyName);
	final Object value = read(property, instance, null);

	// check type
	if (value != null && !TypeUtils.isAssignable(value.getClass(), property.getType())) {
		throw new TypeMismatchException("Read value type " + value.getClass().getName()
				+ " doesn't match property type " + property.getType().getName());
	}

	return (V) value;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:18,代码来源:DefaultBeanPropertySet.java

示例7: getProperty

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T getProperty(String key, Class<T> targetType) throws IllegalArgumentException {
	ObjectUtils.argumentNotNull(key, "Property name must be not null");
	ObjectUtils.argumentNotNull(targetType, "Property type must be not null");

	Object value = properties.get(key);
	if (value != null) {
		if (TypeUtils.isAssignable(value.getClass(), targetType)) {
			return (T) value;
		} else if (TypeUtils.isString(value.getClass())) {
			return ConversionUtils.convertStringValue(value.toString(), targetType);
		} else {
			throw new IllegalArgumentException(
					"Property " + key + " type is not consistent " + "with required type: " + targetType.getName()
							+ " (got type: " + value.getClass().getName() + ")");
		}
	}

	return null;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:22,代码来源:MapConfigPropertyProvider.java

示例8: getParameterIf

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> getParameterIf(String name, Class<T> type, Predicate<T> condition) {
	ObjectUtils.argumentNotNull(name, "Parameter name must be not null");
	ObjectUtils.argumentNotNull(type, "Parameter type must be not null");
	ObjectUtils.argumentNotNull(condition, "Condition must be not null");

	Object value = getParameterValue(name);

	if (value != null && !TypeUtils.isAssignable(value.getClass(), type)) {
		throw new TypeMismatchException("Value type " + value.getClass().getName()
				+ " is not compatible with required type " + type.getName());
	}

	final T typedValue = (T) value;

	if (value != null && condition.test(typedValue)) {
		return Optional.of(typedValue);
	}

	return Optional.empty();
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:23,代码来源:DefaultParameterSet.java

示例9: convert

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public T convert(ResultSet resultSet) throws QueryResultConversionException {

	try {
		final Object value = dialect.getValueDeserializer().deserializeValue(expression,
				getResult(dialect, resultSet, selection));

		// check type
		if (value != null && !TypeUtils.isAssignable(value.getClass(), expression.getType())) {
			throw new QueryResultConversionException("Expected a value of projection type ["
					+ expression.getType().getName() + "], got a value of type: " + value.getClass().getName());
		}

		return (T) value;

	} catch (SQLException e) {
		throw new QueryResultConversionException(
				"Failed to convert query result for expression [" + expression + "]", e);
	}
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:22,代码来源:QueryExpressionResultSetConverter.java

示例10: checkParameterValue

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Check the given view parameter value, performing type conversions when applicable.
 * @param view View instance
 * @param definition Parameter definition
 * @param value Parameter value
 * @return Processed parameter value
 * @throws ViewConfigurationException Error processing value
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Object checkParameterValue(View view, ViewParameterDefinition definition, Object value)
		throws ViewConfigurationException {
	if (value != null) {
		// String
		if (TypeUtils.isString(definition.getType()) && !TypeUtils.isString(value.getClass())) {
			return value.toString();
		}
		if (!TypeUtils.isString(definition.getType()) && TypeUtils.isString(value.getClass())) {
			return ConversionUtils.convertStringValue((String) value, definition.getType());
		}
		// Numbers
		if (TypeUtils.isNumber(definition.getType()) && TypeUtils.isNumber(value.getClass())) {
			return ConversionUtils.convertNumberToTargetClass((Number) value, (Class<Number>) definition.getType());
		}
		// Enums
		if (TypeUtils.isEnum(definition.getType()) && !TypeUtils.isEnum(value.getClass())) {
			return ConversionUtils.convertEnumValue((Class<Enum>) definition.getType(), value);
		}
		// check type consistency
		if (!TypeUtils.isAssignable(value.getClass(), definition.getType())) {
			throw new ViewConfigurationException("Value type " + value.getClass().getName()
					+ " doesn't match view parameter type " + definition.getType().getName());
		}
	}
	return value;
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:36,代码来源:ViewNavigationUtils.java

示例11: checkDetailValue

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Check value is consistent with given <code>type</code>
 * @param <T> Detail value type
 * @param value Value to check
 * @param type Required type
 * @return Value
 * @throws IllegalArgumentException Types mismatch
 */
@SuppressWarnings("unchecked")
protected <T> T checkDetailValue(Object value, Class<T> type) {
	if (value != null) {
		if (!TypeUtils.isAssignable(value.getClass(), type)) {
			throw new IllegalArgumentException("Detail value type " + value.getClass().getName()
					+ " doesn't match required type " + type.getName());
		}
		return (T) value;
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:20,代码来源:DefaultAuthentication.java

示例12: supportsToken

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@Override
public boolean supportsToken(Class<? extends AuthenticationToken> authenticationTokenType) {
	if (authenticationTokenType != null) {
		for (Authenticator<?> authenticator : getAuthenticators()) {
			if (TypeUtils.isAssignable(authenticationTokenType, authenticator.getTokenType())) {
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:12,代码来源:DefaultRealm.java

示例13: supportsMessage

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@Override
public boolean supportsMessage(Class<? extends Message<?, ?>> messageType) {
	if (messageType != null) {
		for (AuthenticationTokenResolver<?> resolver : getAuthenticationTokenResolvers()) {
			if (TypeUtils.isAssignable(messageType, resolver.getMessageType())) {
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:12,代码来源:DefaultRealm.java

示例14: supportsPermission

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@Override
public boolean supportsPermission(Class<? extends Permission> permissionType) {
	if (permissionType != null) {
		for (Authorizer<?> authorizer : getAuthorizers()) {
			if (TypeUtils.isAssignable(permissionType, authorizer.getPermissionType())) {
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:12,代码来源:DefaultRealm.java

示例15: checkPropertyType

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Check the given property is of given type
 * @param property Property to check
 * @param type Required type
 * @return Typed property
 * @throws TypeMismatchException If the given type is not consistent with actual property type
 */
@SuppressWarnings("unchecked")
private static <PT> PathProperty<PT> checkPropertyType(PathProperty<?> property, Class<PT> type) {
	if (!TypeUtils.isAssignable(type, property.getType())) {
		throw new TypeMismatchException("Requested property type " + type.getName()
				+ " doesn't match property type " + property.getType().getName());
	}
	return (PathProperty<PT>) property;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:16,代码来源:DefaultBeanPropertySet.java


注:本文中的com.holonplatform.core.internal.utils.TypeUtils.isAssignable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。