Search in sources :

Example 6 with Externalizable

use of java.io.Externalizable in project wildfly by wildfly.

the class ValueAnalysis method doAnalyze.

protected void doAnalyze() throws RMIIIOPViolationException {
    super.doAnalyze();
    if (cls == String.class)
        throw IIOPLogger.ROOT_LOGGER.cannotAnalyzeStringType();
    if (cls == Class.class)
        throw IIOPLogger.ROOT_LOGGER.cannotAnalyzeClassType();
    if (Remote.class.isAssignableFrom(cls))
        throw IIOPLogger.ROOT_LOGGER.valueTypeCantImplementRemote(cls.getName(), "1.2.4");
    if (cls.getName().indexOf('$') != -1)
        throw IIOPLogger.ROOT_LOGGER.valueTypeCantBeProxy(cls.getName());
    externalizable = Externalizable.class.isAssignableFrom(cls);
    if (!externalizable) {
        // Look for serialPersistentFields field.
        Field spf = null;
        try {
            spf = cls.getField("serialPersistentFields");
        } catch (NoSuchFieldException ex) {
        // ignore
        }
        if (spf != null) {
            // Right modifiers?
            int mods = spf.getModifiers();
            if (!Modifier.isFinal(mods) || !Modifier.isStatic(mods) || !Modifier.isPrivate(mods))
                // wrong modifiers
                spf = null;
        }
        if (spf != null) {
            // Right type?
            Class type = spf.getType();
            if (type.isArray()) {
                type = type.getComponentType();
                if (type != ObjectStreamField.class)
                    // Array of wrong type
                    spf = null;
            } else
                // Wrong type: Not an array
                spf = null;
        }
        if (spf != null) {
            // Get this constant
            try {
                serialPersistentFields = (ObjectStreamField[]) spf.get(null);
            } catch (IllegalAccessException ex) {
                throw IIOPLogger.ROOT_LOGGER.unexpectedException(ex);
            }
            // Mark this in the fields array
            for (int i = 0; i < fields.length; ++i) {
                if (fields[i] == spf) {
                    f_flags[i] |= F_SPFFIELD;
                    break;
                }
            }
        }
        // Look for a writeObject Method
        Method wo = null;
        try {
            wo = cls.getMethod("writeObject", new Class[] { java.io.OutputStream[].class });
        } catch (NoSuchMethodException ex) {
        // ignore
        }
        if (wo != null) {
            // Right return type?
            if (wo.getReturnType() != Void.TYPE)
                // Wrong return type
                wo = null;
        }
        if (wo != null) {
            // Right modifiers?
            int mods = spf.getModifiers();
            if (!Modifier.isPrivate(mods))
                // wrong modifiers
                wo = null;
        }
        if (wo != null) {
            // Right arguments?
            Class[] paramTypes = wo.getParameterTypes();
            if (paramTypes.length != 1)
                // Bad number of parameters
                wo = null;
            else if (paramTypes[0] != java.io.OutputStream.class)
                // Bad parameter type
                wo = null;
        }
        if (wo != null) {
            // We have the writeObject() method.
            hasWriteObjectMethod = true;
            // Mark this in the methods array
            for (int i = 0; i < methods.length; ++i) {
                if (methods[i] == wo) {
                    m_flags[i] |= M_WRITEOBJECT;
                    break;
                }
            }
        }
    }
    // Map all fields not flagged constant or serialPersistentField.
    SortedSet m = new TreeSet(new ValueMemberComparator());
    for (int i = 0; i < fields.length; ++i) {
        if (f_flags[i] != 0)
            // flagged
            continue;
        int mods = fields[i].getModifiers();
        if (Modifier.isStatic(mods) || Modifier.isTransient(mods))
            // don't map this
            continue;
        ValueMemberAnalysis vma;
        vma = new ValueMemberAnalysis(fields[i].getName(), fields[i].getType(), Modifier.isPublic(mods));
        m.add(vma);
    }
    members = new ValueMemberAnalysis[m.size()];
    members = (ValueMemberAnalysis[]) m.toArray(members);
    // Get superclass analysis
    Class superClass = cls.getSuperclass();
    if (superClass == java.lang.Object.class)
        superClass = null;
    if (superClass == null)
        superAnalysis = null;
    else {
        superAnalysis = getValueAnalysis(superClass);
    }
    if (!Serializable.class.isAssignableFrom(cls))
        abstractValue = true;
    fixupCaseNames();
}
Also used : Serializable(java.io.Serializable) Method(java.lang.reflect.Method) SortedSet(java.util.SortedSet) Field(java.lang.reflect.Field) ObjectStreamField(java.io.ObjectStreamField) ObjectStreamField(java.io.ObjectStreamField) TreeSet(java.util.TreeSet) Externalizable(java.io.Externalizable)

Example 7 with Externalizable

use of java.io.Externalizable in project ignite by apache.

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByGridUuid.

/**
 * @throws Exception If failed.
 */
public void testSerializationTopicCreatedByGridUuid() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_GRID_UUID);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

Example 8 with Externalizable

use of java.io.Externalizable in project ignite by apache.

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByString.

/**
 * @throws Exception If failed.
 */
public void testSerializationTopicCreatedByString() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_STRING);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

Example 9 with Externalizable

use of java.io.Externalizable in project ignite by apache.

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByGridUuidAndLong.

/**
 * @throws Exception If failed.
 */
public void testSerializationTopicCreatedByGridUuidAndLong() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_GRID_UUID, A_LONG);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

Example 10 with Externalizable

use of java.io.Externalizable in project ignite by apache.

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByStringAndUUIDAndIntAndLong.

/**
 * @throws Exception If failed.
 */
public void testSerializationTopicCreatedByStringAndUUIDAndIntAndLong() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_STRING, AN_UUID, AN_INT, A_LONG);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

Aggregations

Externalizable (java.io.Externalizable)12 Marshaller (org.apache.ignite.marshaller.Marshaller)8 IOException (java.io.IOException)2 ObjectStreamField (java.io.ObjectStreamField)1 Serializable (java.io.Serializable)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 OptimizedMarshallerUtils.getObject (org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.getObject)1 OptimizedMarshallerUtils.setObject (org.apache.ignite.internal.marshaller.optimized.OptimizedMarshallerUtils.setObject)1