db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r489833 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/ConvertHelper.java
Date Sat, 23 Dec 2006 02:33:36 GMT
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);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message