Java Code Examples for java.io.ObjectStreamClass.getName()

The following are Jave code examples for showing how to use getName() of the java.io.ObjectStreamClass class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: myfaces-trinidad   File: ObjectInputStreamResolveClass.java   View Source Code Vote up 6 votes
protected Class<?> resolveClass(ObjectStreamClass desc)
                         throws IOException,
                                ClassNotFoundException
{
  Class<?> cls = null;
  String className = desc.getName();

  // if it is primitive class, for example, long.class
  // we resolve them by getting them from the hashMaps
  cls = _PRIMITIVE_CLASSES.get(className);

  if (null == cls)
  {
    // TRINIDAD-1062 It has been noticed that in OC4J and Weblogic that the
    // classes being resolved are having problems by not finding
    // them using the context class loader. Therefore, we are adding
    // this work-around until the problem with these application
    // servers can be better understood
    cls = ClassLoaderUtils.loadClass(desc.getName());
  }
  return cls;
}
 
Example 2
Project: openjdk-jdk10   File: TestObjectStreamClass.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 3
Project: monarch   File: InternalDataSerializer.java   View Source Code Vote up 6 votes
@Override
protected Class resolveClass(ObjectStreamClass desc)
    throws IOException, ClassNotFoundException {

  String className = desc.getName();
  OldClientSupportService svc = getOldClientSupportService();
  if (svc != null) {
    className = svc.processIncomingClassName(className);
  }
  try {
    Class clazz = getCachedClass(className);
    return clazz;
  } catch (ClassNotFoundException ex) {
    return super.resolveClass(desc);
  }
}
 
Example 4
Project: openjdk-jdk10   File: RMIJRMPServerImpl.java   View Source Code Vote up 5 votes
@Override
public void check(Method method, ObjectStreamClass descriptor,
        int paramIndex, int callID) {
    String type = descriptor.getName();
    if (!allowedTypes.contains(type)) {
        throw new ClassCastException("Unsupported type: " + type);
    }
}
 
Example 5
Project: uavstack   File: CustomClassLoaderObjectInputStream.java   View Source Code Vote up 5 votes
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws ClassNotFoundException, IOException {

    try {
        String name = desc.getName();
        return Class.forName(name, false, classLoader);
    }
    catch (ClassNotFoundException e) {
        return super.resolveClass(desc);
    }
}
 
Example 6
Project: jmonkeybuilder   File: SSObjectInputStream.java   View Source Code Vote up 5 votes
@Override
protected Class<?> resolveClass(@NotNull final ObjectStreamClass desc) throws IOException, ClassNotFoundException {
    try {
        return super.resolveClass(desc);
    } catch (final ClassNotFoundException e) {

        final String name = desc.getName();

        try (final Reference ref = ReferenceFactory.takeFromTLPool(ReferenceType.OBJECT)) {

            final PluginManager pluginManager = PluginManager.getInstance();
            pluginManager.handlePlugins(plugin -> {

                if (ref.getObject() != null) return;

                final ClassLoader classLoader = plugin.getClassLoader();
                try {
                    ref.setObject(classLoader.loadClass(name));
                } catch (final ClassNotFoundException ex) {
                }
            });

            if (ref.getObject() != null) {
                return (Class<?>) ref.getObject();
            }

        }

        throw e;
    }
}
 
Example 7
Project: AgentWorkbench   File: SerialClone.java   View Source Code Vote up 5 votes
@Override
protected Class<?> resolveClass(ObjectStreamClass osc) throws IOException, ClassNotFoundException {
	Class<?> c = output.classQueue.poll();
	String expected = osc.getName();
	String found = (c == null) ? null : c.getName();
	if (!expected.equals(found)) {
		throw new InvalidClassException("Classes desynchronized: found " + found + " when expecting " + expected);
	}
	return c;
}
 
Example 8
Project: JRediClients   File: CustomObjectInputStream.java   View Source Code Vote up 5 votes
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
    try {
        String name = desc.getName();
        return Class.forName(name, false, classLoader);
    } catch (ClassNotFoundException e) {
        return super.resolveClass(desc);
    }
}
 
Example 9
Project: openjdk-jdk10   File: FailureAtomicity.java   View Source Code Vote up 5 votes
@Override
protected Class<?> resolveClass(ObjectStreamClass desc)
    throws IOException, ClassNotFoundException {
    try {
        return super.resolveClass(desc);
    } catch (ClassNotFoundException x) {
        String name = desc.getName();
        return Class.forName(name, false, loader);
    }
}
 
Example 10
Project: tomcat7   File: ReplicationStream.java   View Source Code Vote up 5 votes
/**
 * Load the local class equivalent of the specified stream class
 * description, by using the class loader assigned to this Context.
 *
 * @param classDesc Class description from the input stream
 *
 * @exception ClassNotFoundException if this class cannot be found
 * @exception IOException if an input/output error occurs
 */
@Override
public Class<?> resolveClass(ObjectStreamClass classDesc)
    throws ClassNotFoundException, IOException {
    String name = classDesc.getName();
    try {
        return resolveClass(name);
    } catch (ClassNotFoundException e) {
        return super.resolveClass(classDesc);
    }
}
 
Example 11
Project: lazycat   File: CustomObjectInputStream.java   View Source Code Vote up 5 votes
/**
 * Load the local class equivalent of the specified stream class
 * description, by using the class loader assigned to this Context.
 *
 * @param classDesc
 *            Class description from the input stream
 *
 * @exception ClassNotFoundException
 *                if this class cannot be found
 * @exception IOException
 *                if an input/output error occurs
 */
@Override
public Class<?> resolveClass(ObjectStreamClass classDesc) throws ClassNotFoundException, IOException {

	String name = classDesc.getName();
	if (allowedClassNamePattern != null) {
		boolean allowed = allowedClassNamePattern.matcher(name).matches();
		if (!allowed) {
			boolean doLog = warnOnFailure && reportedClasses.add(name);
			String msg = sm.getString("customObjectInputStream.nomatch", name, allowedClassNameFilter);
			if (doLog) {
				log.warn(msg);
			} else if (log.isDebugEnabled()) {
				log.debug(msg);
			}
			throw new InvalidClassException(msg);
		}
	}

	try {
		return Class.forName(name, false, classLoader);
	} catch (ClassNotFoundException e) {
		try {
			// Try also the superclass because of primitive types
			return super.resolveClass(classDesc);
		} catch (ClassNotFoundException e2) {
			// Rethrow original exception, as it can have more information
			// about why the class was not found. BZ 48007
			throw e;
		}
	}
}
 
Example 12
Project: openjdk-jdk10   File: UnnamedPackageSwitchTest.java   View Source Code Vote up 5 votes
protected Class resolveClass(ObjectStreamClass desc)
    throws IOException, ClassNotFoundException
{
    String name = desc.getName();
    if (name.equals("A")) {
        return pkg.A.class;
    } else if (name.equals("pkg.A")) {
        return A.class;
    } else {
        return super.resolveClass(desc);
    }
}
 
Example 13
Project: jdk8u-jdk   File: TransferableProxy.java   View Source Code Vote up 5 votes
protected Class<?> resolveClass(ObjectStreamClass classDesc)
  throws IOException, ClassNotFoundException {
    String className = classDesc.getName();

    Set<String> s = new HashSet<String>(1);
    s.add(className);

    ClassLoader classLoader = map.get(s);
    if (classLoader != null) {
        return Class.forName(className, false, classLoader);
    } else {
        return super.resolveClass(classDesc);
    }
}
 
Example 14
Project: OpenJSharp   File: ObjectInputStreamWithLoader.java   View Source Code Vote up 5 votes
@Override
protected Class<?> resolveClass(ObjectStreamClass aClass)
        throws IOException, ClassNotFoundException {
    if (loader == null) {
        return super.resolveClass(aClass);
    } else {
        String name = aClass.getName();
        ReflectUtil.checkPackageAccess(name);
        // Query the class loader ...
        return Class.forName(name, false, loader);
    }
}
 
Example 15
Project: jdk8u-jdk   File: ObjectInputStreamWithLoader.java   View Source Code Vote up 5 votes
@Override
protected Class<?> resolveClass(ObjectStreamClass aClass)
        throws IOException, ClassNotFoundException {
    if (loader == null) {
        return super.resolveClass(aClass);
    } else {
        String name = aClass.getName();
        ReflectUtil.checkPackageAccess(name);
        // Query the class loader ...
        return Class.forName(name, false, loader);
    }
}
 
Example 16
Project: openjdk-jdk10   File: Beans.java   View Source Code Vote up 5 votes
/**
 * Use the given ClassLoader rather than using the system class
 */
@SuppressWarnings("rawtypes")
protected Class resolveClass(ObjectStreamClass classDesc)
    throws IOException, ClassNotFoundException {

    String cname = classDesc.getName();
    return ClassFinder.resolveClass(cname, this.loader);
}
 
Example 17
Project: apache-tomcat-7.0.73-with-comment   File: ReplicationStream.java   View Source Code Vote up 5 votes
/**
 * Load the local class equivalent of the specified stream class
 * description, by using the class loader assigned to this Context.
 *
 * @param classDesc Class description from the input stream
 *
 * @exception ClassNotFoundException if this class cannot be found
 * @exception IOException if an input/output error occurs
 */
@Override
public Class<?> resolveClass(ObjectStreamClass classDesc)
    throws ClassNotFoundException, IOException {
    String name = classDesc.getName();
    try {
        return resolveClass(name);
    } catch (ClassNotFoundException e) {
        return super.resolveClass(classDesc);
    }
}
 
Example 18
Project: incubator-netbeans   File: NbObjectInputStream.java   View Source Code Vote up 4 votes
/** Provides a special handling for renaming of serialized classes.
 * <P>
 * Often, as the time goes the serialized classes evolve. They can be moved
 * to new packages, renamed or changed (by a mistake) to not reflect the
 * version of class stored in previous sessions.
 * <P>
 * This method deals with some of this incompatibilites and provides the
 * module owners a way how to fix some of them.
 * <P>
 * When a class is read, the <link>Utilities.translate</link> is consulted
 * to find out what whether the name of the class is listed there and
 * what new value is assigned to it. This allows complete rename of the
 * serialized class. For example:
 * <code>org.netbeans.core.NbMainExplorer</code>
 * can be renamed to
 * <code>org.netbeans.core.ui.NbExp</code> - of course supposing that
 * the new class is able to read the serialized fields of the old one.
 * <P>
 * Another useful feature of this method is the ability to supress wrong
 * <code>serialVersionUID</code>. This was causing us a lot of problems,
 * because people were forgetting to specify the <code>serialVersionUID</code>
 * field in their sources and then it was hard to recover from it. Right
 * now we have a solution: Just use <link>Utilities.translate</link> framework
 * to assing your class <code>org.yourpackage.YourClass</code> the same
 * name as it had e.g. <code>org.yourpackage.YourClass</code>. This will
 * be interpreted by this method as a hit to suppress <code>serialVersionUID</code>
 * and the <code>NbObjectInputStream</code> will ignore its value.
 * <P>
 * Please see <link>Utilities.translate</link> to learn how your module
 * can provide list of classes that changed name or want to suppress <code>serialVersionUID</code>.
 *
 */
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
    ObjectStreamClass ose = super.readClassDescriptor();

    String name = ose.getName();
    String newN = BaseUtilities.translate(name);

    if (name == newN) {
        // no translation
        return ose;
    }

    // otherwise reload the ObjectStreamClass to contain the local copy
    ClassLoader cl = getNBClassLoader();
    Class clazz = Class.forName(newN, false, cl);

    ObjectStreamClass newOse = ObjectStreamClass.lookup(clazz);

    // #28021 - it is possible that lookup return null. In that case the conversion
    // table contains class which is not Serializable or Externalizable.
    if (newOse == null) {
        throw new java.io.NotSerializableException(newN);
    }

    return newOse;
}
 
Example 19
Project: JDigitalSimulator   File: Utilities.java   View Source Code Vote up 4 votes
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
	ObjectStreamClass descriptor = super.readClassDescriptor(); String name = descriptor.getName();
	if(name.contains(LEGACY_PACKAGE_PREFIX)) descriptor = ObjectStreamClass.lookup(Class.forName(replaceLegacyPackage(name), false, alternateClassLoader));
	return descriptor;
}
 
Example 20
Project: lazycat   File: ReplicationStream.java   View Source Code Vote up 3 votes
/**
 * Load the local class equivalent of the specified stream class
 * description, by using the class loader assigned to this Context.
 *
 * @param classDesc
 *            Class description from the input stream
 *
 * @exception ClassNotFoundException
 *                if this class cannot be found
 * @exception IOException
 *                if an input/output error occurs
 */
@Override
public Class<?> resolveClass(ObjectStreamClass classDesc) throws ClassNotFoundException, IOException {
	String name = classDesc.getName();
	try {
		return resolveClass(name);
	} catch (ClassNotFoundException e) {
		return super.resolveClass(classDesc);
	}
}