svn commit: r489833 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/ConvertHelper.java

[email protected]
Newsgroups gmane.comp.jakarta.ojb.devel
Message-ID <[email protected]>
Author: arminw
Date: Fri Dec 22 18:33:35 2006
New Revision: 489833

URL: http://svn.apache.org/viewvc?view=rev&rev=489833
Log:
initial

Added:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/ConvertHelper.java

Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/ConvertHelper.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/ConvertHelper.java?view=auto&rev=489833
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/ConvertHelper.java (added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/ConvertHelper.java Fri Dec 22 18:33:35 2006
@@ -0,0 +1,92 @@
+package org.apache.ojb.broker.util;
+
+/* Copyright 2002-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.commons.lang.BooleanUtils;
+import org.apache.ojb.broker.util.logging.Logger;
+import org.apache.ojb.broker.util.logging.LoggerFactory;
+
+/**
+ * Helper class to convert objects (e.g. String to Integer).
+ *
+ * @version $Id: $
+ */
+public class ConvertHelper
+{
+    private static Logger log = LoggerFactory.getLogger(ConvertHelper.class);
+
+    public static Integer toInteger(String value) throws NumberFormatException
+    {
+        try
+        {
+            return value != null ? new Integer(value) : null;
+        }
+        catch(NumberFormatException e)
+        {
+            log.error("Can't convert String '" + value + "' to Integer");
+            throw e;
+        }
+    }
+
+    public static int toIntegerPrimitiv(String value) throws NumberFormatException
+    {
+        try
+        {
+            return value != null ? Integer.parseInt(value) : 0;
+        }
+        catch(NumberFormatException e)
+        {
+            log.error("Can't convert String '" + value + "' to Integer");
+            throw e;
+        }
+    }
+
+    public static Long toLong(String value) throws NumberFormatException
+    {
+        try
+        {
+            return value != null ? new Long(value) : null;
+        }
+        catch(NumberFormatException e)
+        {
+            log.error("Can't convert String '" + value + "' to Long");
+            throw e;
+        }
+    }
+
+    public static long toLongPrimitiv(String value) throws NumberFormatException
+    {
+        try
+        {
+            return value != null ? Long.parseLong(value) : 0;
+        }
+        catch(NumberFormatException e)
+        {
+            log.error("Can't convert String '" + value + "' to Long");
+            throw e;
+        }
+    }
+
+    public static Boolean toBoolean(String value)
+    {
+        return BooleanUtils.toBooleanObject(value);
+    }
+
+    public static boolean toBooleanPrimitiv(String value)
+    {
+        return BooleanUtils.toBoolean(value);
+    }
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.