[jboss-cvs] JBossAS SVN: r79160 - trunk/system/src/main/org/jboss/system/server/profileservice/repository.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 6 14:25:58 EDT 2008


Author: scott.stark at jboss.org
Date: 2008-10-06 14:25:58 -0400 (Mon, 06 Oct 2008)
New Revision: 79160

Added:
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/JavaBeanXmlAttachmentsSerializer.java
Log:
An AttachmentsSerializer that uses the java bean long term xml serialization format.

Added: trunk/system/src/main/org/jboss/system/server/profileservice/repository/JavaBeanXmlAttachmentsSerializer.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/JavaBeanXmlAttachmentsSerializer.java	                        (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/JavaBeanXmlAttachmentsSerializer.java	2008-10-06 18:25:58 UTC (rev 79160)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.repository;
+
+import java.beans.XMLDecoder;
+import java.beans.XMLEncoder;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+
+/**
+ * An AttachmentsSerializer that uses the java bean long term xml serialization
+ * format.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class JavaBeanXmlAttachmentsSerializer extends AbstractFileAttachmentsSerializer
+{
+   private static final Logger log = Logger.getLogger(JavaBeanXmlAttachmentsSerializer.class);
+
+   @Override
+   protected Map<String, Object> loadAttachments(File attachmentsStore,
+         ClassLoader loader) throws Exception
+   {
+      Thread.currentThread().setContextClassLoader(loader);
+      FileInputStream fis = new FileInputStream(attachmentsStore);
+      XMLDecoder ois = new XMLDecoder(fis);
+      Map<String, Object> map = null;
+      try
+      {
+         map = (Map<String, Object>) ois.readObject();
+      }
+      finally
+      {
+         try
+         {
+            ois.close();
+         }
+         catch(Exception igore)
+         {            
+         }
+         try
+         {
+            fis.close();
+         }
+         catch(Exception igore)
+         {            
+         }
+      }
+      return map;
+   }
+
+   @Override
+   protected void saveAttachments(File attachmentsStore,
+         Map<String, Object> map, ClassLoader loader) throws Exception
+   {
+      log.debug("saveAttachments, attachmentsStore="+attachmentsStore);
+      if( log.isTraceEnabled() )
+      {
+         log.trace("Attachments.size: "+map.size());
+         for(String key : map.keySet())
+         {
+            log.trace(key+", "+map.get(key));
+         }
+      }
+      FileOutputStream fos = new FileOutputStream(attachmentsStore);
+      XMLEncoder oos = new XMLEncoder(fos);
+      try
+      {
+         oos.writeObject(map);
+      }
+      finally
+      {
+         try
+         {
+            oos.close();
+         }
+         catch(Exception igore)
+         {            
+         }
+         try
+         {
+            fos.close();
+         }
+         catch(Exception igore)
+         {            
+         }
+      }
+   }
+
+}


Property changes on: trunk/system/src/main/org/jboss/system/server/profileservice/repository/JavaBeanXmlAttachmentsSerializer.java
___________________________________________________________________
Name: svn:keywords
   + Revision Id




More information about the jboss-cvs-commits mailing list