OW2 Consortium telosys

Rev

Rev 52 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 52 Rev 138
Line 2... Line 2...
2

2

3
import java.util.Collection;
3
import java.util.Collection;
4
import java.util.Iterator;
-
 
5

4

6
import org.objectweb.telosys.common.TelosysException;
5
import org.objectweb.telosys.common.TelosysException;
7

6

8
/**
7
/**
9
 * Memory DataSet <br>
8
 * Memory DataSet <br>
Line 59... Line 58...
59
        return init(obj);
58
        return init(obj);
60
    }
59
    }
61
    
60
    
62
    //-----------------------------------------------------------------------------
61
    //-----------------------------------------------------------------------------
63
    /**
62
    /**
64
     * Init the DataSet with the given object, supposed to be a usable collection
-
 
65
     * @param obj
-
 
-
 
63
     * Initializes the DataSet with the given collection <br>
-
 
64
     *  
-
 
65
     * @param obj a collection of Object[], or Object[][]
66
     * @return
66
     * @return
67
     * @throws TelosysException
67
     * @throws TelosysException
68
     */
68
     */
69
    private int init(Object obj) throws TelosysException
69
    private int init(Object obj) throws TelosysException
70
    {
70
    {
Line 76... Line 76...
76
        //--- Initialize the DataSet ( prepare to load )
76
        //--- Initialize the DataSet ( prepare to load )
77
        initBeforeLoad();
77
        initBeforeLoad();
78

78

79
        if ( obj instanceof Collection ) // Collection of "Object[]"
79
        if ( obj instanceof Collection ) // Collection of "Object[]"
80
        {
80
        {
81
            Collection c = (Collection) obj;
-
 
82
            Iterator iter = c.iterator();
-
 
83
            Object oRow = null ;
-
 
84
            while ( iter.hasNext() )
-
 
-
 
81
            Collection<?> collection = (Collection<?>) obj;
-
 
82
            for ( Object oRow : collection )
85
            {
83
            {
86
                oRow = iter.next();
-
 
87
                if ( oRow instanceof Object[] )
84
                if ( oRow instanceof Object[] )
88
                {
85
                {
89
                    Object[] values = (Object[]) oRow ;
86
                    Object[] values = (Object[]) oRow ;
90
                    DataRow dr = new DataRow( values.length, values);
87
                    DataRow dr = new DataRow( values.length, values);
91
                    super.addRow(dr);
88
                    super.addRow(dr);
-
 
89
                }
-
 
90
                else {
-
 
91
                    throw new TelosysException("Invalid row type (not Object[]) "  );
92
                }
92
                }
93
            }
93
            }
94
        }
94
        }
95
        else if ( obj instanceof Object[][] ) // Collection of "Object[]"
-
 
-
 
95
        else if ( obj instanceof Object[][] ) // Array of "Object[]"
96
        {
96
        {
97
            //Object[][] grid = (Object[][]) obj;
-
 
98
            // TODO
-
 
99
            throw new TelosysException("unusable parameter " + obj.getClass().getName() );
-
 
-
 
97
            Object[][] array = (Object[][]) obj;
-
 
98
            for ( Object[] oRow : array )
-
 
99
            {
-
 
100
                DataRow dr = new DataRow( oRow.length, oRow);
-
 
101
                super.addRow(dr);
-
 
102
            }
100
        }
103
        }
101
        else
104
        else
102
        {
105
        {
103
            throw new TelosysException("unusable parameter " + obj.getClass().getName() );
-
 
-
 
106
            throw new TelosysException("Invalid parameter " + obj.getClass().getName() + " ( not a collection or array of Object[] )" );
104
        }
107
        }
105
        
108
        
106
        //--- Return the number of rows in the DataSet
109
        //--- Return the number of rows in the DataSet
107
        return getRowCount();
110
        return getRowCount();
108
    }
111
    }