List of usage examples for java.beans XMLDecoder readObject
public Object readObject()
From source file:org.ejbca.core.protocol.ws.CommonEjbcaWS.java
protected void getEndEntityProfileFromID() throws Exception { String profilename = "TESTPROFILEFORGETPROFILECOMMAND"; if (endEntityProfileSession.getEndEntityProfile(profilename) != null) { endEntityProfileSession.removeEndEntityProfile(intAdmin, profilename); }// w w w . j a va 2 s .c o m if (certificateProfileSession.getCertificateProfile(profilename) != null) { certificateProfileSession.removeCertificateProfile(intAdmin, profilename); } EndEntityProfile profile = new EndEntityProfile(); profile.setPrinterName("TestPrinter"); profile.addField(DnComponents.COMMONNAME); profile.setUse(EndEntityProfile.KEYRECOVERABLE, 0, true); profile.setValue(EndEntityProfile.KEYRECOVERABLE, 0, EndEntityProfile.TRUE); endEntityProfileSession.addEndEntityProfile(intAdmin, profilename, profile); int profileid = endEntityProfileSession.getEndEntityProfileId(profilename); try { try { ejbcaraws.getProfile(profileid, "ccp"); } catch (UnknownProfileTypeException_Exception e) { String expectedmsg = "Unknown profile type 'ccp'. Recognized types are 'eep' for End Entity Profiles and 'cp' for Certificate Profiles"; assertEquals(expectedmsg, e.getMessage()); } try { ejbcaraws.getProfile(profileid, "cp"); } catch (EjbcaException_Exception e) { String expectedmsg = "Could not find certificate profile with ID '" + profileid + "' in the database."; assertEquals(expectedmsg, e.getMessage()); } byte[] profilebytes = ejbcaraws.getProfile(profileid, "eep"); 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 EndEntityProfile(); assertFalse(StringUtils.equals("TestPrinter", profile.getPrinterName())); assertFalse(profile.getUse(EndEntityProfile.KEYRECOVERABLE, 0)); // Load the data from the retrieved profile and verify that the data is correct profile.loadData(h); assertEquals("TestPrinter", profile.getPrinterName()); assertTrue(profile.getUse(EndEntityProfile.KEYRECOVERABLE, 0)); } finally { endEntityProfileSession.removeEndEntityProfile(intAdmin, profilename); } }
From source file:org.wso2.connector.integration.test.base.ConnectorIntegrationTestBase.java
/** * This method de-serialize XML object graph. In addition if there are parameterized strings such as * <code>%s(accessToken)</code> in the XML file, those will be parsed and and replace with the values * specified in the Connection Properties resource file or the parameter map passed in to this method. <br> * <br>//www . ja v a 2s .co m * <b>Example XML file.</b><br> * * <pre> * {@code * <?xml version="1.0" encoding="UTF-8"?> * <java class="java.beans.XMLDecoder"> * <object class="test.base.Person"> * <void property="address"> * <object class="test.base.Address"> * <void property="city"> * <string>Test City</string> * </void> * <void property="country"> * <string>Test Country</string> * </void> * <void property="street"> * <string>Test street</string> * </void> * </object> * </void> * <void property="age"> * <int>20</int> * </void> * <void property="name"> * <string>Test Person Name</string> * </void> * </object> * </java> * } * </pre> * * @param filePath file name including path to the XML serialized file. * @param paramMap map containing key value pairs where key being the parameter specified in the XML file * if parameter in XML is <code>%s(accessToken)</code>, the key should be just * <code>accessToken</code>. * @return the de-serialized object, user can cast this to the object type specified in the XML. * @throws IOException if file path is null or empty as well as if there's any exception while reading the * XML file. */ protected Object loadObjectFromFile(String fileName, Map<String, String> paramMap) throws IOException { String filePath = pathToRequestsDirectory + fileName; if (filePath == null || filePath.isEmpty()) { throw new IOException("File path cannot be null or empty."); } Object retObj = null; BufferedInputStream bi = null; XMLDecoder decoder = null; try { bi = new BufferedInputStream(new FileInputStream(filePath)); byte[] buf = new byte[bi.available()]; bi.read(buf); String content = new String(buf); if (connectorProperties != null) { // We don't need to change the original connection properties in case same key is sent with // different value. Properties prop = (Properties) connectorProperties.clone(); if (paramMap != null) { prop.putAll(paramMap); } Matcher matcher = Pattern.compile("%s\\(([A-Za-z0-9]*)\\)", Pattern.DOTALL).matcher(content); while (matcher.find()) { String key = matcher.group(1); content = content.replaceAll("%s\\(" + key + "\\)", Matcher.quoteReplacement(prop.getProperty(key))); } } ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes(Charset.defaultCharset())); decoder = new XMLDecoder(in); retObj = decoder.readObject(); } finally { if (bi != null) { bi.close(); } if (decoder != null) { decoder.close(); } } return retObj; }
From source file:com.projity.pm.graphic.frames.GraphicManager.java
/** * Decode the current workspace (currently using XML though could be binary) * @return workspace object decoded from lastWorkspace static *///from ww w.ja v a 2 s. co m private Workspace decodeWorkspaceXML() { ByteArrayInputStream stream = new ByteArrayInputStream(((String) lastWorkspace).getBytes()); XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(stream)); Workspace workspace = (Workspace) decoder.readObject(); decoder.close(); return workspace; }
From source file:uk.ac.ebi.sail.server.data.DataManager.java
private void loadExpressions(Statement stmt) throws SQLException { IntMap<GroupRequestItem> exprMap = new IntTreeMap<GroupRequestItem>(); ResultSet rst = stmt.executeQuery("SELECT * FROM " + TBL_EXPRESSION); while (rst.next()) { String name = rst.getString(FLD_NAME); GroupRequestItem expr = null;// w w w. j av a 2 s . c o m if (name == null) expr = new GroupRequestItem(); else expr = new ExpressionRequestItem(); expr.setId(rst.getInt(FLD_ID)); expr.setName(rst.getString(FLD_NAME)); expr.setDepth(rst.getInt(FLD_EXPRESSION_DEPTH)); expr.setDescription(rst.getString(FLD_DESCRIPTION)); exprMap.put(expr.getId(), expr); } rst.close(); int rid = 1; rst = stmt.executeQuery("SELECT * FROM " + TBL_EXPRESSION_CONTENT); while (rst.next()) { int rpId = rst.getInt(FLD_EXPRESSION_ID); GroupRequestItem expr = exprMap.get(rpId); if (expr == null) { logger.warn("Abandoned subexpression ExpressionID=" + rpId); continue; } int sid = rst.getInt(FLD_PARAMETER_ID); if (sid > 0) { Parameter p = params.get(sid); if (p == null) { logger.warn("Invalid parameter subexpression ExpressionID=" + rpId + " ParameterID=" + sid); continue; } String filtTxt = rst.getString(FLD_EXPRESSION_FILTER); RequestItem ri = null; if (filtTxt != null && filtTxt.length() > 0) { Object fo = null; try { XMLDecoder dec = new XMLDecoder(new StringInputStream(filtTxt)); fo = dec.readObject(); dec.close(); } catch (Exception e) { } if (fo instanceof ComplexFilter) { ComplexFilter cf = (ComplexFilter) fo; cf.setParameter(p); ri = new ComplexFilteredRequestItem(p.getName(), cf); } } else ri = new ParameterRequestItem(p.getName(), p); ri.setId(rid++); expr.addItem(ri); } else { sid = rst.getInt(FLD_SUBEXPRESSION_ID); if (sid <= 0) { logger.warn("Invalid subexpression ExpressionID=" + rpId + " ParameterID or SubexpressionID must be non-zero"); continue; } GroupRequestItem sbexp = exprMap.get(sid); if (sbexp == null) { logger.warn("Invalid parameter subexpression ExpressionID=" + rpId + " SubexpressionID=" + sid); continue; } expr.addItem(sbexp); } } rst.close(); expressions.clear(); for (GroupRequestItem expi : exprMap.values()) { if (expi.getName() != null) expressions.add((ExpressionRequestItem) expi); } }