/** * Common initialization code called from various constructors. * * @param mimeType the MIME Content Type (must have a class= param) * @param humanPresentableName the human Presentable Name or <code>null</code> * @param classLoader the fallback class loader to resolve against * @throws MimeTypeParseException * @throws ClassNotFoundException * @throws NullPointerException if <code>mimeType</code> is null * @see tryToLoadClass */ private void initialize(String mimeType, String humanPresentableName, ClassLoader classLoader) throws MimeTypeParseException, ClassNotFoundException { if (mimeType == null) { throw new NullPointerException("mimeType"); } this.mimeType = new MimeType(mimeType); // throws String rcn = getParameter("class"); if (rcn == null) { if ("application/x-java-serialized-object".equals(this.mimeType.getBaseType())) throw new IllegalArgumentException("no representation class specified for:" + mimeType); else representationClass = java.io.InputStream.class; // default } else { // got a class name representationClass = DataFlavor.tryToLoadClass(rcn, classLoader); } this.mimeType.setParameter("class", representationClass.getName()); if (humanPresentableName == null) { humanPresentableName = this.mimeType.getParameter("humanPresentableName"); if (humanPresentableName == null) humanPresentableName = this.mimeType.getPrimaryType() + "/" + this.mimeType.getSubType(); } this.humanPresentableName = humanPresentableName; // set it. this.mimeType.removeParameter("humanPresentableName"); // just in case }
/** Restores this <code>DataFlavor</code> from a Serialized state. */ public synchronized void readExternal(ObjectInput is) throws IOException, ClassNotFoundException { String rcn = null; mimeType = (MimeType) is.readObject(); if (mimeType != null) { humanPresentableName = mimeType.getParameter("humanPresentableName"); mimeType.removeParameter("humanPresentableName"); rcn = mimeType.getParameter("class"); if (rcn == null) { throw new IOException("no class parameter specified in: " + mimeType); } } try { representationClass = (Class) is.readObject(); } catch (OptionalDataException ode) { if (!ode.eof || ode.length != 0) { throw ode; } // Ensure backward compatibility. // Old versions didn't write the representation class to the stream. if (rcn != null) { representationClass = DataFlavor.tryToLoadClass(rcn, getClass().getClassLoader()); } } }