List of usage examples for java.beans XMLDecoder readObject
public Object readObject()
From source file:statechum.analysis.learning.Visualiser.java
/** Loads the layout of the specific graph in the list. * * @param whether to ignore loading errors. * @param graphNumber the number of the graph to load. *///from w w w . j ava 2 s .c o m protected void restoreLayout(boolean ignoreErrors, int graphNumber) { XMLDecoder decoder = null; try { String fileName = getLayoutFileName(graphs.get(graphNumber)); if (propName >= 0 && (new File(fileName)).canRead()) { decoder = new XMLDecoder(new FileInputStream(fileName)); //@SuppressWarnings("unchecked") Map<Integer, DoublePair> map = (Map<Integer, DoublePair>) decoder.readObject(); // Most rotate/share/translate are stateless, so I only need to get the cumulative transform // for layout and view via getTransform() which should return AffineTransform // which I should be able to persist into XML. // Only ScalingGraphMousePlugin has a state // in the form of getIn()/setIn()/getOut()/setOut(). viewer.getViewTransformer().setToIdentity(); viewer.getViewTransformer() .concatenate(((XMLAffineTransformSerialised) decoder.readObject()).getAffineTransform()); viewer.getLayoutTransformer().setToIdentity(); viewer.getLayoutTransformer() .concatenate(((XMLAffineTransformSerialised) decoder.readObject()).getAffineTransform()); ((XMLModalGraphMouse) viewer.getGraphMouse()).restore(decoder); layoutOptions.put(propName, (LayoutOptions) decoder.readObject()); ((XMLPersistingLayout) viewer.getModel().getGraphLayout()).initialize(getSize()); ((XMLPersistingLayout) viewer.getModel().getGraphLayout()).restore(map); viewer.invalidate(); } } catch (Exception e1) { if (!ignoreErrors) { e1.printStackTrace(); } } finally { if (decoder != null) { decoder.close(); decoder = null; } } }
From source file:com.tao.realweb.util.StringUtil.java
/** * xml object // w w w .j a va2 s . c o m * * @param xml * @return */ public static Object xmlToObject(String xml) { try { ByteArrayInputStream in = new ByteArrayInputStream(xml.getBytes("UTF8")); XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(in)); return decoder.readObject(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:de.huxhorn.lilith.swing.ApplicationPreferences.java
private void initRecentFiles() { File appPath = getStartupApplicationPath(); File file = new File(appPath, RECENT_FILES_XML_FILENAME); if (file.isFile() && this.recentFiles == null) { XMLDecoder d = null; try {/* w w w .j ava 2s.co m*/ d = new XMLDecoder(new BufferedInputStream(new FileInputStream(file))); this.recentFiles = transformToList(String.class, d.readObject()); } catch (Throwable ex) { if (logger.isWarnEnabled()) logger.warn("Exception while loading recentFiles from file '" + file.getAbsolutePath() + "'!", ex); IOUtilities.interruptIfNecessary(ex); } finally { if (d != null) { d.close(); } } } if (this.recentFiles == null) { this.recentFiles = new ArrayList<>(); } }
From source file:de.huxhorn.lilith.swing.ApplicationPreferences.java
private void initPreviousSearchStrings() { File appPath = getStartupApplicationPath(); File file = new File(appPath, PREVIOUS_SEARCH_STRINGS_XML_FILENAME); if (file.isFile() && this.previousSearchStrings == null) { XMLDecoder d = null; try {/*w w w .ja va 2 s . c o m*/ d = new XMLDecoder(new BufferedInputStream(new FileInputStream(file))); this.previousSearchStrings = transformToList(String.class, d.readObject()); } catch (Throwable ex) { if (logger.isWarnEnabled()) logger.warn("Exception while loading previous search strings from file '" + file.getAbsolutePath() + "'!", ex); IOUtilities.interruptIfNecessary(ex); } finally { if (d != null) { d.close(); } } } if (this.previousSearchStrings == null) { this.previousSearchStrings = new ArrayList<>(); } }
From source file:de.huxhorn.lilith.swing.ApplicationPreferences.java
private void initConditions() { File appPath = getStartupApplicationPath(); File conditionsFile = new File(appPath, CONDITIONS_XML_FILENAME); if (conditionsFile.isFile()) { long lastModified = conditionsFile.lastModified(); if (conditions != null && lastConditionsModified >= lastModified) { if (logger.isDebugEnabled()) logger.debug("Won't reload conditions."); return; }/*w ww.j a va 2 s . c o m*/ XMLDecoder d = null; try { d = new XMLDecoder(new BufferedInputStream(new FileInputStream(conditionsFile))); conditions = transformToList(SavedCondition.class, d.readObject()); lastConditionsModified = lastModified; if (logger.isDebugEnabled()) logger.debug("Loaded conditions {}.", conditions); } catch (Throwable ex) { if (logger.isWarnEnabled()) logger.warn("Exception while loading conditions from file '" + conditionsFile.getAbsolutePath() + "'!", ex); IOUtilities.interruptIfNecessary(ex); } finally { if (d != null) { d.close(); } } } if (conditions == null) { conditions = new ArrayList<>(); } }
From source file:de.huxhorn.lilith.swing.ApplicationPreferences.java
private void initSourceLists() { File appPath = getStartupApplicationPath(); File sourceListsFile = new File(appPath, SOURCE_LISTS_XML_FILENAME); if (sourceListsFile.isFile()) { long lastModified = sourceListsFile.lastModified(); if (sourceLists != null && lastSourceListsModified >= lastModified) { if (logger.isDebugEnabled()) logger.debug("Won't reload source lists."); return; }/*from w w w .j a v a 2s. c o m*/ XMLDecoder d = null; try { d = new XMLDecoder(new BufferedInputStream(new FileInputStream(sourceListsFile))); Map<String, Set> interimMap = transformToMap(String.class, Set.class, d.readObject()); Map<String, Set<String>> resultMap = null; if (interimMap != null) { resultMap = new HashMap<>(); for (Map.Entry<String, Set> current : interimMap.entrySet()) { Set<String> value = transformToSet(String.class, current.getValue()); if (value == null) { continue; } resultMap.put(current.getKey(), value); } } sourceLists = resultMap; lastSourceListsModified = lastModified; } catch (Throwable ex) { if (logger.isWarnEnabled()) logger.warn("Exception while loading source lists from sourceListsFile '" + sourceListsFile.getAbsolutePath() + "'!", ex); sourceLists = new HashMap<>(); IOUtilities.interruptIfNecessary(ex); } finally { if (d != null) { d.close(); } } } else if (sourceLists == null) { sourceLists = new HashMap<>(); } }
From source file:de.huxhorn.lilith.swing.ApplicationPreferences.java
private void initStatusColors() { if (statusColors == null) { File appPath = getStartupApplicationPath(); File statusColorsFile = new File(appPath, STATUS_COLORS_XML_FILENAME); if (statusColorsFile.isFile()) { XMLDecoder d = null; try { d = new XMLDecoder(new BufferedInputStream(new FileInputStream(statusColorsFile))); statusColors = transformToMap(HttpStatus.Type.class, ColorScheme.class, d.readObject()); } catch (Throwable ex) { if (logger.isWarnEnabled()) logger.warn("Exception while loading status Status-ColorSchemes from file '" + statusColorsFile.getAbsolutePath() + "'!", ex); statusColors = null;/*w w w.j ava 2s. co m*/ IOUtilities.interruptIfNecessary(ex); } finally { if (d != null) { d.close(); } } } } if (statusColors != null && statusColors.size() != DEFAULT_STATUS_COLOR_SCHEMES.size()) { if (logger.isWarnEnabled()) logger.warn("Reverting Status-ColorSchemes to defaults."); statusColors = null; } if (statusColors == null) { statusColors = cloneStatusColors(DEFAULT_STATUS_COLOR_SCHEMES); } }
From source file:de.huxhorn.lilith.swing.ApplicationPreferences.java
private void initLevelColors() { if (levelColors == null) { File appPath = getStartupApplicationPath(); File levelColorsFile = new File(appPath, LEVEL_COLORS_XML_FILENAME); if (levelColorsFile.isFile()) { XMLDecoder d = null; try { d = new XMLDecoder(new BufferedInputStream(new FileInputStream(levelColorsFile))); levelColors = transformToMap(LoggingEvent.Level.class, ColorScheme.class, d.readObject()); } catch (Throwable ex) { if (logger.isWarnEnabled()) logger.warn("Exception while loading Level-ColorSchemes from file '" + levelColorsFile.getAbsolutePath() + "'!", ex); levelColors = null;//from w w w . j a v a 2 s.c o m IOUtilities.interruptIfNecessary(ex); } finally { if (d != null) { d.close(); } } } } if (levelColors != null && levelColors.size() != DEFAULT_LEVEL_COLOR_SCHEMES.size()) { if (logger.isWarnEnabled()) logger.warn("Reverting Level-ColorSchemes to defaults."); levelColors = null; } if (levelColors == null) { levelColors = cloneLevelColors(DEFAULT_LEVEL_COLOR_SCHEMES); } }
From source file:de.huxhorn.lilith.swing.ApplicationPreferences.java
private List<PersistentTableColumnModel.TableColumnLayoutInfo> readColumnLayout(File file) { XMLDecoder d = null; List<PersistentTableColumnModel.TableColumnLayoutInfo> result; try {// w w w . j a v a2 s . co m d = new XMLDecoder(new BufferedInputStream(new FileInputStream(file))); result = transformToList(PersistentTableColumnModel.TableColumnLayoutInfo.class, d.readObject()); } catch (Throwable ex) { if (logger.isInfoEnabled()) logger.info("Exception while loading layouts from file '{}'':", file.getAbsolutePath(), ex.getMessage()); result = null; IOUtilities.interruptIfNecessary(ex); } finally { if (d != null) { d.close(); } } return result; }
From source file:org.ejbca.core.protocol.ws.CommonEjbcaWS.java
protected void getCertificateProfileFromID() throws Exception { String profilename = "TESTPROFILEFORGETPROFILECOMMAND"; if (endEntityProfileSession.getEndEntityProfile(profilename) != null) { endEntityProfileSession.removeEndEntityProfile(intAdmin, profilename); }/*from w ww . ja va 2 s. c o m*/ if (certificateProfileSession.getCertificateProfile(profilename) != null) { certificateProfileSession.removeCertificateProfile(intAdmin, profilename); } CertificateProfile profile = new CertificateProfile(); profile.setAllowValidityOverride(true); profile.setAllowExtensionOverride(true); certificateProfileSession.addCertificateProfile(intAdmin, profilename, profile); int profileid = certificateProfileSession.getCertificateProfileId(profilename); try { try { ejbcaraws.getProfile(profileid, "eep"); } catch (EjbcaException_Exception e) { String expectedmsg = "Could not find end entity profile with ID '" + profileid + "' in the database."; assertEquals(expectedmsg, e.getMessage()); } byte[] profilebytes = ejbcaraws.getProfile(profileid, "cp"); java.beans.XMLDecoder decoder = new java.beans.XMLDecoder( new java.io.ByteArrayInputStream(profilebytes)); final Map<?, ?> h = (Map<?, ?>) decoder.readObject(); decoder.close(); // Check that the default data are different from the data in the profile we want to retrieve profile = new CertificateProfile(); assertFalse(profile.getAllowValidityOverride()); assertFalse(profile.getAllowExtensionOverride()); // Load the data from the retrieved profile and verify that the data is correct profile.loadData(h); assertTrue(profile.getAllowValidityOverride()); assertTrue(profile.getAllowExtensionOverride()); } finally { certificateProfileSession.removeCertificateProfile(intAdmin, profilename); } }