Package java.beans

Examples of java.beans.XMLDecoder


    }

  }

  public static MapredWork deserializeMapRedWork(InputStream in, Configuration conf) {
    XMLDecoder d = null;
    try {
      d = new XMLDecoder(in, null, null, conf.getClassLoader());
      MapredWork ret = (MapredWork) d.readObject();
      return (ret);
    } finally {
      if (null != d) {
        d.close();
      }
    }
  }
View Full Code Here


      }
    }
  }

  public static MapredLocalWork deserializeMapRedLocalWork(InputStream in, Configuration conf) {
    XMLDecoder d = null;
    try {
      d = new XMLDecoder(in, null, null, conf.getClassLoader());
      MapredLocalWork ret = (MapredLocalWork) d.readObject();
      return (ret);
    } finally {
      if (null != d) {
        d.close();
      }
    }
  }
View Full Code Here

                 + " - decode.readObject(): unexpected exception occured during decoding: "
                 + e);
  }
      };

    XMLDecoder decoder = null;

    // tries to initialize the XMLDecoder
    try
      {
  decoder = new XMLDecoder(harness.getResourceStream(xmlFile), null,
                           exListener);
      }
    catch (ResourceNotFoundException e)
      {
  harness.fail(name
               + " - create XMLDecoder: unable to load resource from classpath: "
               + xmlFile);
  return;
      }

    /* compares each object of the XMLDecoder with the one that is expected either using
     * Object.equals() or using a specialized EqualityChecker instance
     */
    Iterator ite = expectedObjects.iterator();
    while (ite.hasNext())
      {
  Object expectedObject = ite.next();

  try
    {
      Object decodedObject = decoder.readObject();

      if (checkers.containsKey(expectedObject))
        {
    EqualityChecker eq = (EqualityChecker) checkers.get(expectedObject);

    harness.check(eq.areEqual(decodedObject, expectedObject),
                  name + " - decoder.readObject()-loop");
        }
      else
        harness.check(decodedObject, expectedObject,
                      name + " - decoder.readObject()-loop");
    }
  catch (ArrayIndexOutOfBoundsException aioobe)
    {
      decoder.close();

      // that means that not enough objects where decoded
      harness.fail(name + " - decoder.close()");

      harness.verbose(name
                      + "decoder.close(): no more objects provided by XMLDecoder "
                      + "although at least one more was expected");

      return;
    }
      }

    /* After all expected objects have been compared there should not be any object left in the decoder.
     * Since there is no query method for this we have to invoke readObject() which should throw an
     * ArrayIndexOutOfBoundsException if there is no object left.
     */
    try
      {
  decoder.readObject();
      }
    catch (ArrayIndexOutOfBoundsException aioobe)
      {
  // this exception is expected
  decoder.close();

  return;
      }

    // there was at least one object left if we reach this code
    harness.fail(name
                 + " - readObject()-final: at least one unexpected object was left in the decoder");

    decoder.close();
  }
View Full Code Here

        return loadPainter(file.toURI().toURL(), file.toURI().toURL());
    }
   
    private static Painter loadPainter(final URL in, URL baseURL) throws FileNotFoundException, IOException {
        Thread.currentThread().setContextClassLoader(PainterUtil.class.getClassLoader());
        XMLDecoder dec = new XMLDecoder(in.openStream());
//        p("creating a persistence owner with the base url: " + baseURL);
        dec.setOwner(new PersistenceOwner(baseURL));
        dec.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception ex) {
                System.out.println(ex.getMessage());
                ex.printStackTrace();
            }
        });
        Object obj = dec.readObject();
        return (Painter)obj;
    }
View Full Code Here

   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
   
         XMLDecoder d = new XMLDecoder(
                   new BufferedInputStream(
                       new FileInputStream("Test.xml")));
         Object result = d.readObject();
         System.out.println(result);
         d.close();
   
  }
View Full Code Here

* Decode the current workspace (currently using XML though could be binary)
* @return workspace object decoded from lastWorkspace static
*/
  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;
  }
View Full Code Here

                                }
                                if (!error) {
                                    CertificateProfile cprofile = null;
                                    EndEntityProfile eprofile = null;
                                    FileInputStream is = new FileInputStream(infiles[i]);
                                    XMLDecoder decoder = new XMLDecoder( is );
                                    if (entityprofile) {
                                        eprofile = new EndEntityProfile();
                                        eprofile.loadData(decoder.readObject());
                                        // Translate cert profile ids that have changed after import
                                        String availableCertProfiles = "";
                                        String defaultCertProfile = eprofile.getValue(EndEntityProfile.DEFAULTCERTPROFILE,0);
                                      //getLogger().debug("Debug: Org - AVAILCERTPROFILES " + eprofile.getValue(EndEntityProfile.AVAILCERTPROFILES,0) + " DEFAULTCERTPROFILE "+defaultCertProfile);
                                        for (String currentCertProfile : (Collection<String>) eprofile.getAvailableCertificateProfileIds()) {
                                          Integer currentCertProfileId = Integer.parseInt(currentCertProfile);
                                          Integer replacementCertProfileId = certificateProfileIdMapping.get(currentCertProfileId);
                                          if ( replacementCertProfileId != null ) {
                                            if (!replacementCertProfileId.toString().equals(currentCertProfile)) {
                                              getLogger().warn("Replacing cert profile with id "+currentCertProfile+" with " + replacementCertProfileId + ".");
                                            }
                                            availableCertProfiles += (availableCertProfiles.equals("") ? "" : ";" ) + replacementCertProfileId;
                                            if (currentCertProfile.equals(defaultCertProfile)) {
                                              defaultCertProfile = ""+replacementCertProfileId;
                                            }
                                          } else {
                                            if (ejb.getCertificateProfileSession().getCertificateProfile(getAdmin(), currentCertProfileId) != null ||
                                                SecConst.isFixedCertificateProfile(currentCertProfileId)) {
                                                availableCertProfiles += (availableCertProfiles.equals("") ? "" : ";" ) + currentCertProfile;
                                             } else {
                                               getLogger().warn("End Entity Profile '"+profilename+"' references certificate profile " + currentCertProfile + " that does not exist.");
                                                if (currentCertProfile.equals(defaultCertProfile)) {
                                                  defaultCertProfile = "";
                                                }
                                             }
                                          }
                                        }
                                        if (availableCertProfiles.equals("")) {
                                          getLogger().warn("End Entity Profile only references certificate profile(s) that does not exist. Using ENDUSER profile.");
                                            availableCertProfiles = "1"; // At least make sure the default profile is available
                                        }
                                        if (defaultCertProfile.equals("")) {
                                          defaultCertProfile = availableCertProfiles.split(";")[0]// Use first available profile from list as default if original default was missing
                                        }
                                        eprofile.setValue(EndEntityProfile.AVAILCERTPROFILES, 0, availableCertProfiles);
                                        eprofile.setValue(EndEntityProfile.DEFAULTCERTPROFILE,0, defaultCertProfile);
                                        // Remove any unknown CA and break if none is left
                                        String defaultCA = eprofile.getValue(EndEntityProfile.DEFAULTCA,0);
                                        String availableCAs = eprofile.getValue(EndEntityProfile.AVAILCAS,0);
                                      //getOutputStream().println("Debug: Org - AVAILCAS " + availableCAs + " DEFAULTCA "+defaultCA);
                                        List<String> cas = Arrays.asList(availableCAs.split(";"));
                                        availableCAs = "";
                                        for ( String currentCA : cas ) {
                                          Integer currentCAInt = Integer.parseInt(currentCA);
                                          // The constant ALLCAS will not be searched for among available CAs
                                          if ( (currentCAInt.intValue() != SecConst.ALLCAS) && (ejb.getCAAdminSession().getCAInfo(getAdmin(), currentCAInt) == null) ) {
                                            getLogger().warn("CA with id " + currentCA + " was not found and will not be used in end entity profile '" + profilename + "'.");
                                                if (defaultCA.equals(currentCA)) {
                                                  defaultCA = "";
                                                }
                                          } else {
                                            availableCAs += (availableCAs.equals("") ? "" : ";" ) + currentCA;
                                          }
                                        }
                                        if (availableCAs.equals("")) {
                                          if (caid == null) {
                                            getLogger().error("No CAs left in end entity profile '" + profilename + "' and no CA specified on command line. Using ALLCAs.");
                                            availableCAs = Integer.toString(SecConst.ALLCAS);
                                          } else {
                                            availableCAs = Integer.toString(caid);
                                            getLogger().warn("No CAs left in end entity profile '" + profilename + "'. Using CA supplied on command line with id '"+caid+"'.");
                                          }
                                        }
                                        if (defaultCA.equals("")) {
                                          defaultCA = availableCAs.split(";")[0]// Use first available
                                          getLogger().warn("Changing default CA in end entity profile '" + profilename + "' to "+defaultCA+".");
                                        }
                                      //getLogger().debug("New - AVAILCAS " + availableCAs + " DEFAULTCA "+defaultCA);
                                        eprofile.setValue(EndEntityProfile.AVAILCAS, 0, availableCAs);
                                        eprofile.setValue(EndEntityProfile.DEFAULTCA, 0, defaultCA);
                                        try{                                       
                                            ejb.getEndEntityProfileSession().addEndEntityProfile(getAdmin(),profileid,profilename,eprofile);
                                            getLogger().info("Added entity profile '"+profilename+"' to database.");
                                        }catch(EndEntityProfileExistsException eepee){ 
                                          getLogger().error("Error adding entity profile '"+profilename+"' to database.");
                                        }                                       
                                    } else {
                                        cprofile = new CertificateProfile();
                                        cprofile.loadData(decoder.readObject());
                                        // Make sure CAs in profile exist
                                        Collection<Integer> cas = cprofile.getAvailableCAs();
                                        ArrayList<Integer> casToRemove = new ArrayList<Integer>();
                                        for (Integer currentCA : cas) {
                                          if (currentCA != CertificateProfile.ANYCA && ejb.getCAAdminSession().getCAInfo(getAdmin(), currentCA) == null) {
                                            casToRemove.add(currentCA);
                                          }
                                        }
                                        for (Integer toRemove : casToRemove) {
                                          getLogger().warn("Warning: CA with id " + toRemove + " was not found and will not be used in certificate profile '" + profilename + "'.");
                                          cas.remove(toRemove);
                                        }
                                        if (cas.size() == 0) {
                                          if (caid == null) {
                                            getLogger().error("Error: No CAs left in certificate profile '" + profilename + "' and no CA specified on command line. Using ANYCA.");
                                            cas.add(Integer.valueOf(CertificateProfile.ANYCA));
                                          } else {
                                            getLogger().warn("Warning: No CAs left in certificate profile '" + profilename + "'. Using CA supplied on command line with id '"+caid+"'.");
                                              cas.add(caid);
                                          }
                                        }
                                        cprofile.setAvailableCAs(cas);
                                        // Remove and warn about unknown publishers
                                        Collection<Integer> publishers = cprofile.getPublisherList();
                                        ArrayList<Integer> allToRemove = new ArrayList<Integer>();
                                        for (Integer publisher : publishers) {
                                          BasePublisher pub = null;
                                          try {
                                            pub = ejb.getPublisherSession().getPublisher(getAdmin(), publisher);
                                          } catch (Exception e) {
                                            String msg = e.getMessage();
                                            if (e.getCause() != null) {
                                              msg += ": "+e.getCause().getMessage();
                                            }
                                            getLogger().warn("Warning: There was an error loading publisher with id " + publisher + ". Use debug logging to see stack trace: "+e.getMessage());
                                            getLogger().debug("Full stack trace: ", e);
                                          }
                                          if (pub == null) {
                                            allToRemove.add(publisher);
                                          }
                                        }
                                        for (Integer toRemove : allToRemove) {
                                          getLogger().warn("Warning: Publisher with id " + toRemove + " was not found and will not be used in certificate profile '" + profilename + "'.");
                                          publishers.remove(toRemove);
                                        }
                                        cprofile.setPublisherList(publishers);
                                        // Add profile
                                        try{
                                            ejb.getCertificateProfileSession().addCertificateProfile(getAdmin(),profileid,profilename,cprofile);
                                            certificateProfileIdMapping.put(profileid, ejb.getCertificateProfileSession().getCertificateProfileId(getAdmin(),profilename));
                                            getLogger().info("Added certificate profile '"+profilename+"' to database.");
                                        }catch(CertificateProfileExistsException cpee){
                                          getLogger().error("Error adding certificate profile '"+profilename+"' to database.");
                                        }                                         
                                    }
                                    decoder.close();
                                    is.close();
                                }
                            }
                        }
                    }
View Full Code Here

    try {
      baXML = sXML.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    }
    final XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(baXML));
    final UserDataVO useradmindata;
    try {
      useradmindata  = (UserDataVO) decoder.readObject();
    } catch( Throwable t ) {
      // try to repair the end of the XML string.
      // this will only succeed if a limited number of chars is lost in the end of the string
      // note that this code will not make anything worse and that it will not be run if the XML can be encoded.
      //
      try {
        if ( lastTry ) {
          return null;
        }
        final String sFixedXML = FixEndOfBrokenXML.fixXML(sXML, "string", "</void></object></java>");
        if ( sFixedXML==null ) {
          throw new NotPossibleToFixXML();         
        }
        final UserDataVO userDataVO = decodeXML(sFixedXML, true);
        if ( userDataVO==null ) {
          throw new NotPossibleToFixXML();
        }
        storeUserDataVO(userDataVO); // store it right so it does not have to be repaired again.
        log.warn(printUserDataVOXML("XML has been repaired. Trailing tags fixed. DB updated with correct XML.", sXML));
        return userDataVO;
      } catch ( NotPossibleToFixXML e ) {
        log.error(printUserDataVOXML("Not possible to decode UserDataVO. No way to fix the XML.", sXML), t);
        return null;
      }
    } finally {
      decoder.close();
    }
    if (log.isTraceEnabled() ) {
      log.trace(printUserDataVOXML("Successfully decoded UserDataVO XML.",sXML));
    }
    /* Code that fixes broken XML that has actually been parsed. It seems that the decoder is not checking for the java end tag.
View Full Code Here

    byte[] xml = decodeAndEncode(testXml);
    for ( int nrOfBytesMissing = 0; xml.length>nrOfBytesMissing; nrOfBytesMissing++ ) {
      final byte brokenXml[] = Arrays.copyOf(xml, xml.length-nrOfBytesMissing);
      final byte fixedXml[] = FixEndOfBrokenXML.fixXML(new String(brokenXml, CHAR_ENCODING), "string", "</void></object></java>").getBytes(CHAR_ENCODING);

      final XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(fixedXml));
      final ByteArrayOutputStream baos = new ByteArrayOutputStream();
      final XMLEncoder encoder = new XMLEncoder(baos);
      try {
        encoder.writeObject(decoder.readObject());
        encoder.close();
      } catch( Throwable t ) {
        log.error("Exception: ", t);
        notPossibleToRemoveMoreBytes(nrOfBytesMissing, brokenXml, limit);
        return;
View Full Code Here

    log.info("Repair tool not able to mend xml with "+nrOfBytesMissing+" missing chars in the end:\n" + new String(brokenXml, CHAR_ENCODING));
    assertFalse("Only possible to fix "+nrOfBytesMissing+" missing bytes. We should be able to handle "+limit+" missing bytes.", nrOfBytesMissing<limit);
  }

  private byte[] decodeAndEncode(final byte[] testXml) {
    final XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(testXml));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final XMLEncoder encoder = new XMLEncoder(baos);
    encoder.writeObject(dec.readObject());
    encoder.close();
    return baos.toByteArray();
  }
View Full Code Here

TOP

Related Classes of java.beans.XMLDecoder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.