001: package simpleorm.core;
002:
003: /**
004: * This class contains a few required utilities to enable SimpleORM to run
005: * under j# (.net)!
006: * The only other classes that need overriding are
007: * SArraylist, SThreadLocal, and SSerializable.
008: * If you are not interested in J#/.Net this will not affect you.
009: */
010:
011: public class SJSharp {
012: /**
013: Java Class is .net System.Type
014: */
015: static public Class castToClass(Object clas) {
016: return (Class) clas;
017: }
018:
019: static public String jvmVersion() {
020: return Package.getPackage("java.lang")
021: .getImplementationVersion();
022: }
023:
024: static public int object2Int(Object obj) {
025: if (obj == null)
026: return 0;
027: if (obj instanceof Number)
028: return ((Number) obj).intValue();
029: else
030: return Integer.parseInt(obj.toString());
031: }
032:
033: static public long object2Long(Object obj) {
034: if (obj == null)
035: return 0;
036: if (obj instanceof Number)
037: return ((Number) obj).longValue();
038: else
039: return Long.parseLong(obj.toString());
040: }
041:
042: static public double object2Double(Object obj) {
043: if (obj == null)
044: return 0;
045: if (obj instanceof Number)
046: return ((Number) obj).doubleValue();
047: else
048: return Double.parseDouble(obj.toString());
049: }
050:
051: static public boolean object2Boolean(Object obj) {
052: if (obj == null)
053: return false;
054: if (obj instanceof Boolean)
055: return ((Boolean) obj).booleanValue();
056: else
057: return Boolean.valueOf(obj.toString()).booleanValue();
058: }
059:
060: /**
061: * These classes allow the java.lang.int etc. classes to be replaced
062: * by native .Net classes.
063: */
064:
065: static public Object newInteger(int i) {
066: return new Integer(i);
067: }
068:
069: static public Object newInteger(String s) {
070: return new Integer(Integer.parseInt(s));
071: }
072:
073: static public Object newInteger(Number n) {
074: return newInteger(n.intValue());
075: }
076:
077: static public Object newLong(long i) {
078: return new Long(i);
079: }
080:
081: static public Object newLong(Number n) {
082: return newLong(n.intValue());
083: }
084:
085: static public Object newLong(String s) {
086: return newLong(Long.parseLong(s));
087: }
088:
089: static public Object newDouble(double i) {
090: return new Double(i);
091: }
092:
093: static public Object newDouble(Number n) {
094: return newDouble(n.intValue());
095: }
096:
097: static public Object newDouble(String s) {
098: return newDouble(Double.parseDouble(s));
099: }
100:
101: static public boolean isInteger(Object obj) {
102: return obj instanceof Integer;
103: }
104:
105: static public boolean isLong(Object obj) {
106: return obj instanceof Long;
107: }
108:
109: static public boolean isDouble(Object obj) {
110: return obj instanceof Double;
111: }
112:
113: }
114:
115: /*
116: public class SJSharp {
117: static public Class castToClass(object clas) {
118: if (clas instanceof Class)
119: return (Class)clas;
120: else
121: return Class.FromType((System.Type)clas);
122: }
123: static public String jvmVersion() {
124: return System.Environment.get_Version().ToString();
125: }
126:
127: static public int object2Int(object obj) {
128: if (obj == null) return 0;
129: return Integer.parseInt(obj.toString());
130: }
131: static public long object2Long(object obj) {
132: if (obj == null) return 0;
133: return Long.parseLong(obj.toString());
134: }
135: static public double object2Double(object obj) {
136: if (obj == null) return 0;
137: return Double.parseDouble(obj.toString());
138: }
139: }
140: */
|