[jboss-cvs] JBossAS SVN: r57332 - in branches/JBoss_4_0_2_CP: common/src/main/org/jboss/util/file system/src/main/org/jboss/system/pm testsuite/imports testsuite/src/main/org/jboss/test/jmx/test testsuite/src/main/org/jboss/test/jmx/xmbean testsuite/src/resources/jmx/xmbean testsuite/src/resources/jmx/xmbean/xml-attr-pers testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Oct 1 19:12:39 EDT 2006
Author: ryan.campbell at jboss.com
Date: 2006-10-01 19:12:38 -0400 (Sun, 01 Oct 2006)
New Revision: 57332
Added:
branches/JBoss_4_0_2_CP/testsuite/src/main/org/jboss/test/jmx/test/XMLAttributePersistenceManagerUnitTestCase.java
branches/JBoss_4_0_2_CP/testsuite/src/main/org/jboss/test/jmx/xmbean/XMLAttributePersistenceManagerTestService.java
branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/
branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/
branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-service.xml
branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-xmbean.xml
Removed:
branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/
branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-service.xml
branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-xmbean.xml
Modified:
branches/JBoss_4_0_2_CP/common/src/main/org/jboss/util/file/Files.java
branches/JBoss_4_0_2_CP/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java
branches/JBoss_4_0_2_CP/testsuite/imports/test-jars.xml
Log:
ASPATCH-42: JBAS-2964: Backport XMBean persistence fixes to 4.0.2 (JBAS-1776, JBAS-1988)
Modified: branches/JBoss_4_0_2_CP/common/src/main/org/jboss/util/file/Files.java
===================================================================
--- branches/JBoss_4_0_2_CP/common/src/main/org/jboss/util/file/Files.java 2006-10-01 22:51:44 UTC (rev 57331)
+++ branches/JBoss_4_0_2_CP/common/src/main/org/jboss/util/file/Files.java 2006-10-01 23:12:38 UTC (rev 57332)
@@ -1,12 +1,24 @@
-/***************************************
- * *
- * JBoss: The OpenSource J2EE WebOS *
- * *
- * Distributable under LGPL license. *
- * See terms of license at gnu.org. *
- * *
- ***************************************/
-
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* 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.util.file;
import java.io.BufferedInputStream;
@@ -26,10 +38,10 @@
/**
* A collection of file utilities.
*
- * @version <tt>$Revision$</tt>
* @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
- * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:Scott.Stark at jboss.org">Scott Stark<a/>
* @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
+ * @version $Revision$
*/
public final class Files
{
@@ -225,9 +237,41 @@
*
* @param name the filename to encode
* @return a filesystem-friendly filename
- */
+ */
public static String encodeFileName(String name)
{
+ return encodeFileName(name, '@');
+ }
+
+ /**
+ * Used to decode a file system friendly filename produced
+ * by encodeFileName() method, above.
+ *
+ * Copied by Adrian's org.jboss.mq.pm.file.PersistenceManager
+ * and adapted to use hex instead of decimal digits
+ *
+ * Note:
+ * Decoding will not work if encoding produced
+ * multi-byte encoded characters. If this is truly
+ * needed we'll have to revise the encoding.
+ *
+ * @param name the filename to decode
+ * @return the original name
+ */
+ public static String decodeFileName(String name)
+ {
+ return decodeFileName(name, '@');
+ }
+
+ /**
+ * See encodeFileName(String) above.
+ *
+ * @param name the filename to encode
+ * @param escape the escape character to use
+ * @return a filesystem-friendly filename
+ */
+ public static String encodeFileName(String name, char escape)
+ {
StringBuffer rc = new StringBuffer();
for (int i = 0; i < name.length(); i++ )
{
@@ -252,16 +296,17 @@
// Any other character needs to be encoded.
default:
- // We encode the characters as %hh where
+ // We encode the characters as <esc>hh,
+ // where <esc> is the passed escape character and
// hh is the hex value of the UTF8 byte of the character.
- // You might get %hh%hh since UTF8 can produce multiple
- // bytes for a since character.
+ // You might get <esc>hh<esc>hh since UTF8 can produce multiple
+ // bytes for a single character.
try
{
byte data[] = ("" + name.charAt(i)).getBytes("UTF8");
for (int j = 0; j < data.length; j++)
{
- rc.append('%');
+ rc.append(escape);
rc.append(hexDigits[ (data[j] >> 4) & 0xF ]); // high order digit
rc.append(hexDigits[ (data[j] ) & 0xF ]); // low order digit
}
@@ -274,23 +319,15 @@
}
return rc.toString();
}
-
+
/**
- * Used to decode a file system friendly filename produced
- * by encodeFileName() method, above.
- *
- * Copied by Adrian's org.jboss.mq.pm.file.PersistenceManager
- * and adapted to use hex instead of decimal digits
- *
- * Note:
- * Decoding will not work if encoding produced
- * multi-byte encoded characters. If this is truly
- * needed we'll have to revise the encoding.
- *
+ * See decodeFileName(String) above.
+ *
* @param name the filename to decode
+ * @param escape the escape character to use
* @return the original name
*/
- public static String decodeFileName(String name)
+ public static String decodeFileName(String name, char escape)
{
if (name == null)
{
@@ -301,7 +338,7 @@
for (int i = 0; i < name.length(); i++)
{
char c = name.charAt(i);
- if (c == '%')
+ if (c == escape)
{
char h1 = name.charAt(++i);
char h2 = name.charAt(++i);
@@ -315,8 +352,8 @@
: ((h2 >= 'A') ? (10 + h2 - 'A')
: (h2 - '0'));
- // handling only the %hh case here, as we don't know
- // if %hh%hh belong to the same character
+ // handling only the <esc>hh case here, as we don't know
+ // if <esc>hh<esc>hh belong to the same character
// (and we are lazy to change the encoding) - REVISIT
byte[] bytes = new byte[] { (byte)(d1 * 16 + d2) };
Modified: branches/JBoss_4_0_2_CP/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java
===================================================================
--- branches/JBoss_4_0_2_CP/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java 2006-10-01 22:51:44 UTC (rev 57331)
+++ branches/JBoss_4_0_2_CP/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java 2006-10-01 23:12:38 UTC (rev 57332)
@@ -1,12 +1,24 @@
-/***************************************
- * *
- * JBoss: The OpenSource J2EE WebOS *
- * *
- * Distributable under LGPL license. *
- * See terms of license at gnu.org. *
- * *
- ***************************************/
-
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* 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.pm;
import java.beans.PropertyEditor;
@@ -14,10 +26,14 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.OutputStream;
import java.io.Serializable;
import java.net.URL;
import java.text.SimpleDateFormat;
@@ -50,7 +66,7 @@
import org.w3c.dom.Text;
/**
- * FileAttributePersistenceManager
+ * XMLAttributePersistenceManager
*
* @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
* @version $Revision$
@@ -106,8 +122,7 @@
**/
public XMLAttributePersistenceManager()
{
- if (log.isDebugEnabled())
- log.debug("Constructed");
+ log.debug("Constructed");
}
// AttributePersistenceManager Lifecycle -------------------------
@@ -164,12 +179,10 @@
// Initialize the data dir
this.dataDir = initDataDir(baseDir, version);
- if (log.isDebugEnabled()) {
- log.debug("Using data directory: " + this.dataDir.getCanonicalPath());
- }
+ log.debug("Using data directory: " + this.dataDir.getCanonicalPath());
- // initialize id cache
- this.idMap = Collections.synchronizedMap(new HashMap());
+ // initialize id cache
+ this.idMap = Collections.synchronizedMap(new HashMap());
// mark active status
setState(true);
@@ -218,8 +231,7 @@
public void store(String id, AttributeList attrs)
throws Exception
{
- if (log.isDebugEnabled())
- log.debug("store(" + id + ") attrs=" + attrs);
+ log.debug("store(" + id + ") attrs=" + attrs);
// make sure we are active
checkActiveState();
@@ -350,8 +362,7 @@
public AttributeList load(String id)
throws Exception
{
- if (log.isDebugEnabled())
- log.debug("load(" + id + ")");
+ log.debug("load(" + id + ")");
// make sure we are active
checkActiveState();
@@ -502,8 +513,7 @@
} // end for()
}
}
- if (log.isDebugEnabled())
- log.debug("load() returns with: " + attrs);
+ log.debug("load() returns with: " + attrs);
// will be null if a persistent file was not found
return attrs;
@@ -746,16 +756,27 @@
// Prepare the DOM document for writing
Source source = new DOMSource(doc);
- // Prepare the output file
- Result result = new StreamResult(file);
+ // Use an OutputStream rather than a File
+ OutputStream out = new FileOutputStream(file);
+ // Prepare the output
+ Result result = new StreamResult(out);
+
// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance().newTransformer();
// Enable indentation
xformer.setOutputProperty(OutputKeys.INDENT, "yes");
- xformer.transform(source, result);
+ try
+ {
+ xformer.transform(source, result);
+ }
+ finally
+ {
+ // Cleanup
+ out.close();
+ }
}
/**
@@ -771,11 +792,27 @@
// do not request validation against DTD
// no DTD specified in the saved document
factory.setValidating(false);
-
- // Create the builder and parse the file
- Document doc = factory.newDocumentBuilder().parse(file);
-
- return doc;
+
+ // The builder and document to return
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc;
+
+ // Use an InputStreamer rather than a File when parsing,
+ // to avoid pathname encoding problems, like spaces in
+ // the pathname encoded as %20
+ InputStream in = new FileInputStream(file);
+ try
+ {
+ // Parse the file
+ doc = builder.parse(in);
+ }
+ finally
+ {
+ // close anyways
+ in.close();
+ }
+ // Return the parsed document
+ return doc;
}
/**
Modified: branches/JBoss_4_0_2_CP/testsuite/imports/test-jars.xml
===================================================================
--- branches/JBoss_4_0_2_CP/testsuite/imports/test-jars.xml 2006-10-01 22:51:44 UTC (rev 57331)
+++ branches/JBoss_4_0_2_CP/testsuite/imports/test-jars.xml 2006-10-01 23:12:38 UTC (rev 57332)
@@ -3203,6 +3203,14 @@
</fileset>
</copy>
+ <!-- xmbean XMLAttributePersistenceManagerTestService -->
+ <jar jarfile="${build.lib}/xmlapm-xmbean.sar">
+ <metainf dir="${build.resources}/jmx/xmbean/xml-attr-pers/META-INF"/>
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/test/jmx/xmbean/XMLAttributePersistenceManagerTestService.class"/>
+ </fileset>
+ </jar>
+
<!-- xmbean AVC generation from wrapped standard mbean impl -->
<jar jarfile="${build.lib}/listener-xmbean.sar">
<metainf dir="${build.resources}/jmx/xmbean/listener/META-INF"/>
Copied: branches/JBoss_4_0_2_CP/testsuite/src/main/org/jboss/test/jmx/test/XMLAttributePersistenceManagerUnitTestCase.java (from rev 57330, branches/JBoss_4_0_2_JBAS-2964/testsuite/src/main/org/jboss/test/jmx/test/XMLAttributePersistenceManagerUnitTestCase.java)
Copied: branches/JBoss_4_0_2_CP/testsuite/src/main/org/jboss/test/jmx/xmbean/XMLAttributePersistenceManagerTestService.java (from rev 57330, branches/JBoss_4_0_2_JBAS-2964/testsuite/src/main/org/jboss/test/jmx/xmbean/XMLAttributePersistenceManagerTestService.java)
Copied: branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers (from rev 57330, branches/JBoss_4_0_2_JBAS-2964/testsuite/src/resources/jmx/xmbean/xml-attr-pers)
Copied: branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF (from rev 57330, branches/JBoss_4_0_2_JBAS-2964/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF)
Deleted: branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-service.xml
===================================================================
--- branches/JBoss_4_0_2_JBAS-2964/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-service.xml 2006-10-01 22:36:06 UTC (rev 57330)
+++ branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-service.xml 2006-10-01 23:12:38 UTC (rev 57332)
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE server
- PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
- "http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd">
-
-<server>
-
- <mbean code="org.jboss.test.jmx.xmbean.XMLAttributePersistenceManagerTestService"
- name="jboss.test:service=XMLAttributePersistenceManagerTestService"
- xmbean-dd="META-INF/jboss-xmbean.xml" />
-
-</server>
Copied: branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-service.xml (from rev 57330, branches/JBoss_4_0_2_JBAS-2964/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-service.xml)
Deleted: branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-xmbean.xml
===================================================================
--- branches/JBoss_4_0_2_JBAS-2964/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-xmbean.xml 2006-10-01 22:36:06 UTC (rev 57330)
+++ branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-xmbean.xml 2006-10-01 23:12:38 UTC (rev 57332)
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mbean PUBLIC
- "-//JBoss//DTD JBOSS XMBEAN 1.2//EN"
- "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_2.dtd">
-
-<mbean>
- <description>Tests of XMLAttributePersistenceManager</description>
- <class>org.jboss.test.jmx.xmbean.XMLAttributePersistenceManagerTestService</class>
-
- <constructor>
- <description>The default constructor</description>
- <name>XMLAttributePersistenceManagerTestService</name>
- </constructor>
-
- &defaultAttributes;
-
- <!-- Operations -->
-
- <operation>
- <name>store</name>
- <parameter>
- <name>id</name>
- <type>java.lang.String</type>
- </parameter>
- <parameter>
- <name>atlist</name>
- <type>javax.management.AttributeList</type>
- </parameter>
- </operation>
-
- <operation>
- <name>load</name>
- <parameter>
- <name>id</name>
- <type>java.lang.String</type>
- </parameter>
- <return-type>javax.management.AttributeList</return-type>
- </operation>
-
- <operation>
- <name>selftest</name>
- </operation>
-
- &defaultOperations;
-
-</mbean>
\ No newline at end of file
Copied: branches/JBoss_4_0_2_CP/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-xmbean.xml (from rev 57330, branches/JBoss_4_0_2_JBAS-2964/testsuite/src/resources/jmx/xmbean/xml-attr-pers/META-INF/jboss-xmbean.xml)
More information about the jboss-cvs-commits
mailing list