[jboss-svn-commits] JBL Code SVN: r12438 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jun 9 17:42:00 EDT 2007


Author: mark.little at jboss.com
Date: 2007-06-09 17:42:00 -0400 (Sat, 09 Jun 2007)
New Revision: 12438

Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java
Log:
http://jira.jboss.com/jira/browse/JBESB-611

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java	2007-06-09 21:40:59 UTC (rev 12437)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java	2007-06-09 21:42:00 UTC (rev 12438)
@@ -62,256 +62,284 @@
 
 public class Util
 {
-	private Util()
+    private Util()
+    {
+    }
+
+    public static void dumpSysProps (PrintStream p_OS)
+    {
+	String[] sa = new String[ModulePropertyManager.getPropertyManager(
+		ModulePropertyManager.TRANSPORTS_MODULE).getProperties().size()];
+	ModulePropertyManager.getPropertyManager(
+		ModulePropertyManager.TRANSPORTS_MODULE).getProperties()
+		.keySet().toArray(sa);
+	Arrays.sort(sa);
+	for (String sCurr : sa)
+	    p_OS.println(sCurr
+		    + "="
+		    + ModulePropertyManager.getPropertyManager(
+			    ModulePropertyManager.TRANSPORTS_MODULE)
+			    .getProperty(sCurr));
+    } // __________________________________
+
+    public static boolean isNullString (String p_s)
+    {
+	return (null == p_s) ? true : p_s.trim().length() < 1;
+    } // __________________________________
+
+    public static boolean isLong (String p_s)
+    {
+	if (isNullString(p_s))
+	    return false;
+
+	try
 	{
+	    Long.parseLong(p_s);
+	    return true;
 	}
-
-	public static void dumpSysProps(PrintStream p_OS)
+	catch (Exception e)
 	{
-		String[] sa = new String[ModulePropertyManager.getPropertyManager(
-				ModulePropertyManager.TRANSPORTS_MODULE).getProperties().size()];
-		ModulePropertyManager.getPropertyManager(
-				ModulePropertyManager.TRANSPORTS_MODULE).getProperties()
-				.keySet().toArray(sa);
-		Arrays.sort(sa);
-		for (String sCurr : sa)
-			p_OS.println(sCurr
-					+ "="
-					+ ModulePropertyManager.getPropertyManager(
-							ModulePropertyManager.TRANSPORTS_MODULE)
-							.getProperty(sCurr));
-	} // __________________________________
+	    return false;
+	}
+    } // __________________________________
 
-	public static boolean isNullString(String p_s)
-	{
-		return (null == p_s) ? true : p_s.trim().length() < 1;
-	} // __________________________________
+    public static boolean isPositiveLong (String p_s)
+    {
+	if (isNullString(p_s))
+	    return false;
 
-	public static boolean isLong(String p_s)
+	try
 	{
-		if (isNullString(p_s))
-			return false;
-		
-		try
-		{
-			Long.parseLong(p_s);
-			return true;
-		}
-		catch (Exception e)
-		{
-			return false;
-		}
-	} // __________________________________
+	    long lBk = Long.parseLong(p_s);
+	    return lBk > 0;
+	}
+	catch (Exception e)
+	{
+	    return false;
+	}
+    } // __________________________________
 
-	public static boolean isPositiveLong(String p_s)
+    public static int parseInt (String s)
+    {
+	if (s == null)
+	    return 0;
+
+	String sVal = s.trim();
+
+	if (sVal.length() < 1)
+	    return 0;
+	else
 	{
-		if (isNullString(p_s))
-			return false;
-		
-		try
-		{
-			long lBk = Long.parseLong(p_s);
-			return lBk > 0;
-		}
-		catch (Exception e)
-		{
-			return false;
-		}
-	} // __________________________________
+	    try
+	    {
+		return Integer.parseInt(s);
+	    }
+	    catch (NumberFormatException ex)
+	    {
+		return 0;
+	    }
+	}
+    } // __________________________________
 
-	public static int parseInt(String s)
+    public static long parseLong (String s)
+    {
+	if (s == null)
+	    return 0;
+
+	String sVal = s.trim();
+
+	if (sVal.length() < 1)
+	    return 0;
+	else
 	{
-		if (s == null)
-			return 0;
-		
-		String sVal = s.trim();
-		
-		if (sVal.length() < 1)
-			return 0;
-		else
-		{
-			try
-			{
-				return Integer.parseInt(s);
-			}
-			catch (NumberFormatException ex)
-			{
-				return 0;
-			}
-		}
-	} // __________________________________
+	    try
+	    {
+		return Long.parseLong(s);
+	    }
+	    catch (NumberFormatException ex)
+	    {
+		return 0;
+	    }
+	}
+    } // __________________________________
 
-	public static long parseLong(String s)
+    public static Logger getDefaultLogger (Class p_oCls)
+    {
+	Logger oRet = Logger.getLogger(p_oCls.getName());
+	Appender oApp = new ConsoleAppender(new TTCCLayout("ISO8601"));
+	oRet.addAppender(oApp);
+	return oRet;
+    } // __________________________________
+
+    public static Serializable serialize (Message message)
+	    throws ParserConfigurationException, IOException
+    {
+	if (message.getType().equals(
+		org.jboss.soa.esb.message.format.MessageType.JAVA_SERIALIZED))
+	    return (Serializable) message;
+
+	try
 	{
-		if (s == null)
-			return 0;
-		
-		String sVal = s.trim();
-		
-		if (sVal.length() < 1)
-			return 0;
-		else
-		{
-			try
-			{
-				return Long.parseLong(s);
-			}
-			catch (NumberFormatException ex)
-			{
-				return 0;
-			}
-		}
-	} // __________________________________
+	    DocumentBuilderFactory factory = DocumentBuilderFactory
+		    .newInstance();
 
-	public static Logger getDefaultLogger(Class p_oCls)
+	    factory.setNamespaceAware(true);
+
+	    Document doc = factory.newDocumentBuilder().newDocument();
+	    ((org.jboss.internal.soa.esb.message.format.xml.MessageImpl) message)
+		    .toXML(doc);
+	    StringWriter sWriter = new StringWriter();
+	    OutputFormat format = new OutputFormat();
+	    format.setIndenting(true);
+	    XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+	    xmlS.asDOMSerializer();
+	    xmlS.serialize(doc);
+	    return sWriter.toString();
+	}
+	catch (MarshalException ex)
 	{
-		Logger oRet = Logger.getLogger(p_oCls.getName());
-		Appender oApp = new ConsoleAppender(new TTCCLayout("ISO8601"));
-		oRet.addAppender(oApp);
-		return oRet;
-	} // __________________________________
+	    throw new IOException(ex.toString());
+	}
+    }// ________________________________
 
-	public static Serializable serialize(Message message)
-			throws ParserConfigurationException, IOException
+    public static Message deserialize (Serializable serial)
+	    throws ParserConfigurationException, SAXException, IOException
+    {
+	if (serial instanceof MessageImpl) // MessageType.JAVA_SERIALIZED
+	    return (Message) serial;
+
+	try
 	{
-		if (message.getType().equals(
-				org.jboss.soa.esb.message.format.MessageType.JAVA_SERIALIZED))
-			return (Serializable) message;
+	    // MessageType.JBOSS_XML
+	    InputStream inStream = new ByteArrayInputStream(((String) serial)
+		    .getBytes());
+	    DocumentBuilderFactory factory = DocumentBuilderFactory
+		    .newInstance();
+	    factory.setNamespaceAware(true);
 
-		try
-		{
-			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-			
-			factory.setNamespaceAware(true);
-			
-			Document doc = factory.newDocumentBuilder().newDocument();
-			((org.jboss.internal.soa.esb.message.format.xml.MessageImpl) message)
-					.toXML(doc);
-			StringWriter sWriter = new StringWriter();
-			OutputFormat format = new OutputFormat();
-			format.setIndenting(true);
-			XMLSerializer xmlS = new XMLSerializer(sWriter, format);
-			xmlS.asDOMSerializer();
-			xmlS.serialize(doc);
-			return sWriter.toString();
-		}
-		catch (MarshalException ex)
-		{
-			throw new IOException(ex.toString());
-		}
-	}// ________________________________
+	    DocumentBuilder builder = factory.newDocumentBuilder();
+	    Document doc = builder.parse(inStream);
 
-	public static Message deserialize(Serializable serial)
-			throws ParserConfigurationException, SAXException, IOException
+	    org.jboss.internal.soa.esb.message.format.xml.MessageImpl message = new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
+	    message.fromXML(doc);
+	    return message;
+	}
+	catch (UnmarshalException ex)
 	{
-		if (serial instanceof MessageImpl) // MessageType.JAVA_SERIALIZED
-			return (Message) serial;
+	    throw new IOException(ex.toString());
+	}
+    } // ________________________________
 
-		try
-		{
-			// MessageType.JBOSS_XML
-			InputStream inStream = new ByteArrayInputStream(((String) serial)
-					.getBytes());
-			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-			factory.setNamespaceAware(true);
-			
-			DocumentBuilder builder = factory.newDocumentBuilder();
-			Document doc = builder.parse(inStream);
-	
-			org.jboss.internal.soa.esb.message.format.xml.MessageImpl message = new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
-			message.fromXML(doc);
-			return message;
-		}
-		catch (UnmarshalException ex)
-		{
-			throw new IOException(ex.toString());
-		}
-	} // ________________________________
+    public static List<KeyValuePair> propertiesFromSelector (String selector)
+    {
+	// No problem if selector is null - everything in queue will be returned
+	List<KeyValuePair> oRet = new ArrayList<KeyValuePair>();
 
-	public static List<KeyValuePair> propertiesFromSelector(String selector)
+	if (!Util.isNullString(selector))
 	{
-		// No problem if selector is null - everything in queue will be returned
-		List<KeyValuePair> oRet = new ArrayList<KeyValuePair>();
-		
-		if (!Util.isNullString(selector))
+	    for (String sCurr : selector.trim().split(","))
+	    {
+		String[] sa = sCurr.split("=");
+		if (sa.length != 2 || sa[1].charAt(0) != '\''
+			|| sa[1].charAt(-1 + sa[1].length()) != '\'')
 		{
-			for (String sCurr : selector.trim().split(","))
-			{
-				String[] sa = sCurr.split("=");
-				if (sa.length != 2 || sa[1].charAt(0) != '\''
-						|| sa[1].charAt(-1 + sa[1].length()) != '\'') {
-					throw new IllegalArgumentException("Illegal message selector syntax <" + selector + ">.  Must be 2 tokens seperated by an '=' character, and the token after the '=' character must be enclosed in single quotes.");
-                }
-                KeyValuePair oNew = new KeyValuePair(sa[0], sa[1].substring(0,
-						-1 + sa[1].length()).substring(1));
-				oRet.add(oNew);
-			}
+		    throw new IllegalArgumentException(
+			    "Illegal message selector syntax <"
+				    + selector
+				    + ">.  Must be 2 tokens seperated by an '=' character, and the token after the '=' character must be enclosed in single quotes.");
 		}
-		
-		return oRet;
-	} // ________________________________
+		KeyValuePair oNew = new KeyValuePair(sa[0], sa[1].substring(0,
+			-1 + sa[1].length()).substring(1));
+		oRet.add(oNew);
+	    }
+	}
 
-	public static String getStamp()
-	{
-		return s_oTS.format(new java.util.Date(System.currentTimeMillis()));
-	}
-	
-	/**
-	 * Attempt to format the output.
-	 * 
-	 * @param output
-	 *            Output to be formatted.
-	 * @return Output.
+	return oRet;
+    } // ________________________________
+
+    public static String getStamp ()
+    {
+	return s_oTS.format(new java.util.Date(System.currentTimeMillis()));
+    }
+
+    /**
+         * Attempt to format the output.
+         * 
+         * @param output
+         *                Output to be formatted.
+         * @return Output.
+         */
+
+    public static String format (String output)
+    {
+	/*
+	 * If it's not XML, then don't try to deal with it as if it were.
 	 */
 	
-	public static String format(String output)
+	if (!output.startsWith("<?xml"))
+	    return output;
+	
+	StreamSource source = new StreamSource(new ByteArrayInputStream(output
+		.getBytes()));
+	ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+
+	try
 	{
-		StreamSource source = new StreamSource(new ByteArrayInputStream(output
-				.getBytes()));
-		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+	    Transformer transformer;
 
-		try
-		{
-			Transformer transformer;
+	    try
+	    {
+		factory.setAttribute("indent-number", new Integer(4));
+	    }
+	    catch (Exception e)
+	    {
+		// Ignore... Xalan may throw on this!!
+		// We handle Xalan indentation below (yeuckkk) ...
+	    }
+	    transformer = factory.newTransformer();
+	    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+	    // There's a bug in Java 5 re this code (formatting).
+	    // See
+                // http://forum.java.sun.com/thread.jspa?threadID=562510&start=0
+	    // and it explains the
+	    // whys of the following code.
+	    transformer.setOutputProperty(
+		    "{http://xml.apache.org/xalan}indent-amount", "4");
+	    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
+		    "yes");
+	    transformer.setErrorListener(new NullErrorListener());
+	    transformer.transform(source, new StreamResult(outStream));
 
-            try {
-                factory.setAttribute("indent-number", new Integer(4));
-            } catch(Exception e) {
-                // Ignore... Xalan may throw on this!!
-                // We handle Xalan indentation below (yeuckkk) ...
-            }
-			transformer = factory.newTransformer();
-			transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-            // There's a bug in Java 5 re this code (formatting).
-            // See http://forum.java.sun.com/thread.jspa?threadID=562510&start=0
-            // and it explains the
-            // whys of the following code.
-			transformer.setOutputProperty(
-					"{http://xml.apache.org/xalan}indent-amount", "4");
-			transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
-					"yes");
-            transformer.setErrorListener(new NullErrorListener());
-            transformer.transform(source, new StreamResult(outStream));
+	    return outStream.toString();
+	}
+	catch (Exception e)
+	{
+	    return output;
+	}
+    }
 
-			return outStream.toString();
-		}
-		catch (Exception e)
-		{
-			return output;
-		}
+    private static TransformerFactory factory = TransformerFactory
+	    .newInstance();
+
+    private static class NullErrorListener implements ErrorListener
+    {
+	public void warning (TransformerException exception)
+		throws TransformerException
+	{
 	}
 
-    private static TransformerFactory factory = TransformerFactory.newInstance();
-    private static class NullErrorListener implements ErrorListener {
-        public void warning(TransformerException exception) throws TransformerException {
-        }
-        public void error(TransformerException exception) throws TransformerException {
-        }
-        public void fatalError(TransformerException exception) throws TransformerException {
-        }
+	public void error (TransformerException exception)
+		throws TransformerException
+	{
+	}
+
+	public void fatalError (TransformerException exception)
+		throws TransformerException
+	{
+	}
     }
-	
+
     private static final SimpleDateFormat s_oTS = new SimpleDateFormat(
-			"yyyy/MM/dd hh:mm:ss.SSS");
+	    "yyyy/MM/dd hh:mm:ss.SSS");
 
 } // ____________________________________________________________________________




More information about the jboss-svn-commits mailing list