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


Java Serializable.getClass方法代码示例

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


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

示例1: getCheckedParam

import java.io.Serializable; //导入方法依赖的package包/类
/**
 * Gets the value for the named parameter. Checks the type of the parameter
 * is correct and throws a {@link RenditionServiceException} if it isn't.
 * Returns <code>null</code> if the parameter value is <code>null</code>
 * 
 * @param paramName the name of the parameter being checked.
 * @param clazz the expected {@link Class} of the parameter value.
 * @param definition the {@link RenditionDefinition} containing the
 *            parameters.
 * @return the parameter value or <code>null</code>.
 */
@SuppressWarnings("unchecked")
public static <T> T getCheckedParam(String paramName, Class<T> clazz, RenditionDefinition definition)
{
    Serializable value = definition.getParameterValue(paramName);
    if (value == null)
        return null;
    else
    {
        if(clazz == null)
            throw new RenditionServiceException("The class must not be null!", new NullPointerException());
        Class<? extends Serializable> valueClass = value.getClass();
        if ( !clazz.isAssignableFrom(valueClass))
        {
            throw new RenditionServiceException("The parameter: " + paramName + " must be of type: "
                        + clazz.getName() + "but was of type: " + valueClass.getName());
        }
        else
            return (T) value;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:32,代码来源:AbstractRenderingEngine.java

示例2: isConstructable

import java.io.Serializable; //导入方法依赖的package包/类
/**
 * Determines if the value can be adequately recreated (to equality) by creating
 * a new instance.  For example, a <b>java.util.HashMap</b> is constructable provided
 * that the map is empty.
 * <p>
 * Subclasses can override this to handle any well-known types, and in conjunction with
 * {@link #constructInstance(String)}, even choose to return <tt>true</tt> if it needs a
 * non-default constructor.
 * 
 * @param value             the value to check
 * @return                  Returns <tt>true</tt> if the value can be reconstructed by
 *                          instantiation using a default constructor
 */
protected boolean isConstructable(Serializable value)
{
    // Is it in the set directly
    Class<?> valueClazz = value.getClass();
    // Check for default constructor
    try
    {
        valueClazz.getConstructor();
    }
    catch (NoSuchMethodException e)
    {
        // Can't reconstruct using just a type name
        return false;
    }
    // Maps and Collections
    if (value instanceof Map<?, ?>)
    {
        Map<?, ?> mapValue = (Map<?, ?>) value;
        return mapValue.isEmpty();
    }
    else if (value instanceof Collection<?>)
    {
        Collection<?> collectionValue = (Collection<?>) value;
        return collectionValue.isEmpty();
    }
    else
    {
        // We don't recognise it
        return false;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:45,代码来源:DefaultPropertyTypeConverter.java

示例3: makeNodePropertyValue

import java.io.Serializable; //导入方法依赖的package包/类
/**
 * Helper method to convert the <code>Serializable</code> value into a full, persistable {@link NodePropertyValue}.
 * <p>
 * Where the property definition is null, the value will take on the {@link DataTypeDefinition#ANY generic ANY}
 * value.
 * <p>
 * Collections are NOT supported. These must be split up by the calling code before calling this method. Map
 * instances are supported as plain serializable instances.
 * 
 * @param propertyDef the property dictionary definition, may be null
 * @param value the value, which will be converted according to the definition - may be null
 * @return Returns the persistable property value
 */
public NodePropertyValue makeNodePropertyValue(PropertyDefinition propertyDef, Serializable value)
{
    // get property attributes
    final QName propertyTypeQName;
    if (propertyDef == null) // property not recognised
    {
        // allow it for now - persisting excess properties can be useful sometimes
        propertyTypeQName = DataTypeDefinition.ANY;
    }
    else
    {
        propertyTypeQName = propertyDef.getDataType().getName();
    }
    try
    {
        NodePropertyValue propertyValue = null;
        propertyValue = new NodePropertyValue(propertyTypeQName, value);

        // done
        return propertyValue;
    }
    catch (TypeConversionException e)
    {
        throw new TypeConversionException(
                "The property value is not compatible with the type defined for the property: \n" +
                "   property: " + (propertyDef == null ? "unknown" : propertyDef) + "\n" +
                "   value: " + value + "\n" +
                "   value type: " + value.getClass(),
                e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:45,代码来源:NodePropertyHelper.java

示例4: instantiate

import java.io.Serializable; //导入方法依赖的package包/类
/**
 * Return a new instance initialized with the given identifier
 */
public Object instantiate(Serializable id) throws HibernateException {
	if ( hasEmbeddedIdentifier && id.getClass()==mappedClass ) {
		return id;
	}
	else {
		if (abstractClass) throw new HibernateException("Cannot instantiate abstract class or interface: " + className);
		final Object result;
		if (optimizer != null) { 
			try {
				result = fastClass.newInstance();
			}
			catch (Throwable t) {
				throw new InstantiationException("Could not instantiate entity with CGLIB: ", mappedClass, t);
			}
		}
		else {
			try {
				result = constructor.newInstance(null);
			}
			catch (Exception e) {
				throw new InstantiationException("Could not instantiate entity: ", mappedClass, e);
			}
		}
		setIdentifier(result, id);
		return result;
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:31,代码来源:AbstractEntityPersister.java

示例5: checkSerialClassName

import java.io.Serializable; //导入方法依赖的package包/类
/**
 * Checks that the given object serializes to the expected class.
 */
static void checkSerialClassName(Serializable obj, String expected) {
    String cn = serialClassName(obj);
    if (!cn.equals(expected))
        throw new RuntimeException(obj.getClass() + " serialized as " + cn
            + ", expected " + expected);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:Serial.java

示例6: factCheck

import java.io.Serializable; //导入方法依赖的package包/类
/**
 * Check ObjectStreamClass facts match between core serialization and CORBA.
 *
 * @param value
 */
@Test(dataProvider = "Objects")
void factCheck(Serializable value) {
    Class<?> clazz = value.getClass();
    java.io.ObjectStreamClass sOSC = java.io.ObjectStreamClass.lookup(clazz);
    java.io.ObjectStreamField[] sFields = sOSC.getFields();
    com.sun.corba.se.impl.io.ObjectStreamClass cOSC = corbaLookup(clazz);
    com.sun.corba.se.impl.io.ObjectStreamField[] cFields = cOSC.getFields();

    Assert.assertEquals(sFields.length, cFields.length, "Different number of fields");
    for (int i = 0; i < sFields.length; i++) {
        Assert.assertEquals(sFields[i].getName(), cFields[i].getName(),
                "different field names " + cFields[i].getName());
        Assert.assertEquals(sFields[i].getType(), cFields[i].getType(),
                "different field types " + cFields[i].getName());
        Assert.assertEquals(sFields[i].getTypeString(), cFields[i].getTypeString(),
                "different field typestrings " + cFields[i].getName());
    }

    Assert.assertEquals(baseMethod("hasReadObjectMethod", sOSC, (Class<?>[]) null),
            corbaMethod("hasReadObject", cOSC, (Class<?>[]) null),
            "hasReadObject: " + value.getClass());

    Assert.assertEquals(baseMethod("hasWriteObjectMethod", sOSC, (Class<?>[]) null),
            corbaMethod("hasWriteObject", cOSC, (Class<?>[]) null),
            "hasWriteObject: " + value.getClass());

    Assert.assertEquals(baseMethod("hasWriteReplaceMethod", sOSC, (Class<?>[]) null),
            corbaMethod("hasWriteReplaceMethod", cOSC, (Class<?>[]) null),
            "hasWriteReplace: " + value.getClass());

    Assert.assertEquals(baseMethod("hasReadResolveMethod", sOSC, (Class<?>[]) null),
            corbaMethod("hasReadResolveMethod", cOSC, (Class<?>[]) null),
            "hasReadResolve: " + value.getClass());

    Assert.assertEquals(baseMethod("getSerialVersionUID", sOSC, (Class<?>[]) null),
            corbaMethod("getSerialVersionUID", cOSC, (Class<?>[]) null),
            "getSerialVersionUID: " + value.getClass());

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:ObjectStreamTest.java

示例7: getPersistentType

import java.io.Serializable; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public PersistedType getPersistentType(Serializable value)
{
    ParameterCheck.mandatory("value", value);
    
    Class<?> clazz = value.getClass();
    PersistedType type = persistenceMapping.get(clazz);
    if (type != null)
    {
        // MNT-17523: Loss of information, field values truncated
        if (value instanceof String)
        {
            if (((String) value).length() > SchemaBootstrap.getMaxStringLength())
            {
                return PropertyValueEntity.PersistedType.SERIALIZABLE;
            }
        }
        return type;
    }
    // Before we give up, check if it is constructable
    if (isConstructable(value))
    {
        // It'll just be given back as a class name i.e. a CONSTRUCTABLE
        return PersistedType.CONSTRUCTABLE;
    }
    else if (value instanceof Enum<?>)
    {
        return PersistedType.ENUM;
    }
    else
    {
        // Check if there are converters to and from well-known types, just in case
        if (DefaultTypeConverter.INSTANCE.getConverter(clazz, Long.class) != null &&
                DefaultTypeConverter.INSTANCE.getConverter(Long.class, clazz) != null)
        {
            return PersistedType.LONG;
        }
        else if (DefaultTypeConverter.INSTANCE.getConverter(clazz, String.class) != null &&
                DefaultTypeConverter.INSTANCE.getConverter(String.class, clazz) != null)
        {
            return PersistedType.STRING;
        }
        // No hope of doing anything useful other than storing it
        return PersistedType.SERIALIZABLE;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:49,代码来源:DefaultPropertyTypeConverter.java

示例8: findPropertyValueByValue

import java.io.Serializable; //导入方法依赖的package包/类
@Override
protected PropertyValueEntity findPropertyValueByValue(Serializable value)
{
    // Get the actual type ID
    Class<?> clazz = (value == null ? Object.class : value.getClass());
    Pair<Long, Class<?>> clazzPair = getPropertyClass(clazz);
    if (clazzPair == null)
    {
        // Shortcut: There are no properties of this type
        return null;
    }
    Long actualTypeId = clazzPair.getFirst();
    
    // Construct the search parameters
    PropertyValueEntity queryEntity = new PropertyValueEntity();
    queryEntity.setValue(value, converter);
    queryEntity.setActualTypeId(actualTypeId);
    
    // How would it be persisted?
    PersistedType persistedType = queryEntity.getPersistedTypeEnum();
    Short persistedTypeId = queryEntity.getPersistedType();
    
    // Query based on the the persistable value type
    String query = null;
    Object queryObject = queryEntity;

    // Handle each persisted type individually

    switch (persistedType)
    {
    case NULL:
    case LONG:
        query = SELECT_PROPERTY_VALUE_BY_LOCAL_VALUE;
        break;
    case DOUBLE:
        query = SELECT_PROPERTY_VALUE_BY_DOUBLE_VALUE;
        break;
    case CONSTRUCTABLE:
        // The string value is the name of the class (e.g. 'java.util.HashMap')
    case ENUM:
        // The string-equivalent representation
    case STRING:
        // It's best to query using the CRC and short end-value
        query = SELECT_PROPERTY_VALUE_BY_STRING_VALUE;
        queryObject = new PropertyStringQueryEntity(
                persistedTypeId,
                actualTypeId,
                queryEntity.getStringValue());
        break;
    case SERIALIZABLE:
        // No query
        break;
    default:
        throw new IllegalStateException("Unhandled PersistedType value: " + persistedType);
    }
    
    // Now query
    PropertyValueEntity result = null;
    if (query != null)
    {
        // Uniqueness is guaranteed by the tables, so we get one value only
        result = template.selectOne(query, queryObject);
    }
    
    // Done
    return result;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:68,代码来源:PropertyValueDAOImpl.java

示例9: createPropertyValueInternal

import java.io.Serializable; //导入方法依赖的package包/类
private PropertyValueEntity createPropertyValueInternal(Serializable value)
{
    // Get the actual type ID
    Class<?> clazz = (value == null ? Object.class : value.getClass());
    Pair<Long, Class<?>> clazzPair = getOrCreatePropertyClass(clazz);
    Long actualTypeId = clazzPair.getFirst();
    
    // Construct the insert entity
    PropertyValueEntity insertEntity = new PropertyValueEntity();
    insertEntity.setValue(value, converter);
    insertEntity.setActualTypeId(actualTypeId);
    
    // Persist the persisted value
    switch (insertEntity.getPersistedTypeEnum())
    {
    case DOUBLE:
        Double doubleValue = insertEntity.getDoubleValue();
        Pair<Long, Double> insertDoublePair = getOrCreatePropertyDoubleValue(doubleValue);
        insertEntity.setLongValue(insertDoublePair.getFirst());
        break;
    case STRING:
    case CONSTRUCTABLE:
    case ENUM:
        String stringValue = insertEntity.getStringValue();
        Pair<Long, String> insertStringPair = getOrCreatePropertyStringValue(stringValue);
        insertEntity.setLongValue(insertStringPair.getFirst());
        break;
    case SERIALIZABLE:
        Pair<Long, Serializable> insertSerializablePair = createPropertySerializableValue(value);
        insertEntity.setLongValue(insertSerializablePair.getFirst());
        break;
    case NULL:
    case LONG:
        // Do nothing for these
        break;
    default:
        throw new IllegalStateException("Unknown PersistedType enum: " + insertEntity.getPersistedTypeEnum());
    }
    
    // Persist the entity
    template.insert(INSERT_PROPERTY_VALUE, insertEntity);
    // Done
    return insertEntity;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:45,代码来源:PropertyValueDAOImpl.java

示例10: writeRMIIIOPValueType

import java.io.Serializable; //导入方法依赖的package包/类
private void writeRMIIIOPValueType(Serializable object, Class clazz) {
    if (valueHandler == null)
        valueHandler = ORBUtility.createValueHandler(); //d11638

    Serializable key = object;

    // Allow the ValueHandler to call writeReplace on
    // the Serializable (if the method is present)
    object = valueHandler.writeReplace(key);

    if (object == null) {
        // Write null tag and return
        write_long(0);
        return;
    }

    if (object != key) {
        if (valueCache != null && valueCache.containsKey(object)) {
            writeIndirection(INDIRECTION_TAG, valueCache.getVal(object));
            return;
        }

        clazz = object.getClass();
    }

    if (mustChunk || valueHandler.isCustomMarshaled(clazz)) {
        mustChunk = true;
    }

    // Write value_tag
    int indirection = writeValueTag(mustChunk, true, Util.getCodebase(clazz));

    // Write rep. id
    write_repositoryId(repIdStrs.createForJavaType(clazz));

    // Add indirection for object to indirection table
    updateIndirectionTable(indirection, object, key);

    if (mustChunk) {
        // Write Value chunk
        end_flag--;
        chunkedValueNestingLevel--;
        start_block();
    } else
        end_flag--;

    if (valueHandler instanceof ValueHandlerMultiFormat) {
        ValueHandlerMultiFormat vh = (ValueHandlerMultiFormat)valueHandler;
        vh.writeValue(parent, object, streamFormatVersion);
    } else
        valueHandler.writeValue(parent, object);

    if (mustChunk)
        end_block();

    // Write end tag
    writeEndTag(mustChunk);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:59,代码来源:CDROutputStream_1_0.java

示例11: write_value

import java.io.Serializable; //导入方法依赖的package包/类
public void write_value(Serializable object, String repository_id) {

        // Handle null references
        if (object == null) {
            // Write null tag and return
            write_long(0);
            return;
        }

        // Handle shared references
        if (valueCache != null && valueCache.containsKey(object)) {
            writeIndirection(INDIRECTION_TAG, valueCache.getVal(object));
            return;
        }

        Class clazz = object.getClass();
        boolean oldMustChunk = mustChunk;

        if (mustChunk)
            mustChunk = true;

        if (inBlock)
            end_block();

        if (clazz.isArray()) {
            // Handle arrays
            writeArray(object, clazz);
        } else if (object instanceof org.omg.CORBA.portable.ValueBase) {
            // Handle IDL Value types
            writeValueBase((org.omg.CORBA.portable.ValueBase)object, clazz);
        } else if (shouldWriteAsIDLEntity(object)) {
            writeIDLEntity((IDLEntity)object);
        } else if (object instanceof java.lang.String) {
            writeWStringValue((String)object);
        } else if (object instanceof java.lang.Class) {
            writeClass(repository_id, (Class)object);
        } else {
            // RMI-IIOP value type
            writeRMIIIOPValueType(object, clazz);
        }

        mustChunk = oldMustChunk;

        // Check to see if we need to start another block for a
        // possible outer value
        if (mustChunk)
            start_block();

    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:50,代码来源:CDROutputStream_1_0.java


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