/** * Get the DataContentHandler for this DataHandler: * * <p>If a DataContentHandlerFactory is set, use it. Otherwise look for an object to serve DCH in * the following order: * * <p>1) if a factory is set, use it * * <p>2) if a CommandMap is set, use it * * <p>3) use the default CommandMap * * <p>In any case, wrap the real DataContentHandler with one of our own to handle any missing * cases, fill in defaults, and to ensure that we always have a non-null DataContentHandler. * * @return the requested DataContentHandler */ private synchronized DataContentHandler getDataContentHandler() { // make sure the factory didn't change if (factory != oldFactory) { oldFactory = factory; factoryDCH = null; dataContentHandler = null; transferFlavors = emptyFlavors; } if (dataContentHandler != null) return dataContentHandler; String simpleMT = getBaseType(); if (factoryDCH == null && factory != null) factoryDCH = factory.createDataContentHandler(simpleMT); if (factoryDCH != null) dataContentHandler = factoryDCH; if (dataContentHandler == null) { if (dataSource != null) dataContentHandler = getCommandMap().createDataContentHandler(simpleMT, dataSource); else dataContentHandler = getCommandMap().createDataContentHandler(simpleMT); } // getDataContentHandler always uses these 'wrapper' handlers // to make sure it returns SOMETHING meaningful... if (dataSource != null) dataContentHandler = new DataSourceDataContentHandler(dataContentHandler, dataSource); else dataContentHandler = new ObjectDataContentHandler(dataContentHandler, object, objectMimeType); return dataContentHandler; }
/** * Sets the DataContentHandlerFactory. The DataContentHandlerFactory is called first to find * DataContentHandlers. The DataContentHandlerFactory can only be set once. * * <p>If the DataContentHandlerFactory has already been set, this method throws an Error. * * @param newFactory the DataContentHandlerFactory * @exception Error if the factory has already been defined. * @see javax.activation.DataContentHandlerFactory */ public static synchronized void setDataContentHandlerFactory( DataContentHandlerFactory newFactory) { if (factory != null) throw new Error("DataContentHandlerFactory already defined"); SecurityManager security = System.getSecurityManager(); if (security != null) { try { // if it's ok with the SecurityManager, it's ok with me... security.checkSetFactory(); } catch (SecurityException ex) { // otherwise, we also allow it if this code and the // factory come from the same class loader (e.g., // the JAF classes were loaded with the applet classes). if (DataHandler.class.getClassLoader() != newFactory.getClass().getClassLoader()) throw ex; } } factory = newFactory; }