Changeset 399


Ignore:
Timestamp:
03/07/12 12:24:08 (12 years ago)
Author:
vmipsl
Message:

commit temporaire _ serialization json Tapas
PAS FINI !!

Location:
tapas
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • tapas/common/implementation/com/ether/JSONHelperImpl.java

    r396 r399  
    1313import org.springframework.beans.factory.InitializingBean; 
    1414 
    15 import java.lang.reflect.TypeVariable; 
     15import java.util.AbstractCollection; 
     16import java.util.ArrayList; 
    1617import java.util.Collection; 
    1718import java.util.Collections; 
     19import java.util.List; 
    1820import java.util.Map; 
    1921 
     
    7981        { 
    8082            final JSONArray jsonArray = JSONArray.fromObject( json, _jsonConfig ); 
    81             if( beanClass.isArray() ) 
     83            final Class<? super T> superclass = beanClass.getSuperclass(); 
     84            if( superclass.isAssignableFrom( AbstractCollection.class ) ) 
    8285            { 
    83                 final Class<?> componentType = beanClass.getComponentType(); 
    84                 //json.sf.net does not support Long[] or long[] 
    85                 if( Long.class.equals( componentType ) || Long.TYPE.equals( componentType ) ) 
     86                final Tapas tapas = new Tapas(); 
     87                final List<Request> requests = new ArrayList<Request>(); 
     88                for( final Object jsonElement : jsonArray ) 
    8689                { 
    87                     final Integer[] integers = (Integer[]) JSONArray.toArray( jsonArray, Integer.class ); 
    88                     if( Long.class.equals( componentType ) ) 
    89                     { 
    90                         final Long[] resultArray = new Long[integers.length]; 
    91                         for( int i = 0; i < integers.length; ++i ) 
    92                             resultArray[i] = integers[i].longValue(); 
    93                         return (T) resultArray; 
    94                     } 
    95                     if( Long.TYPE.equals( componentType ) ) 
    96                     { 
    97                         final long[] resultArray = new long[integers.length]; 
    98                         for( int i = 0; i < integers.length; ++i ) 
    99                             resultArray[i] = integers[i].longValue(); 
    100                         return (T) resultArray; 
    101                     } 
     90                    final Request request = fromJSON( (JSON) jsonElement, Request.class ); 
     91                    requests.add( request ); 
    10292                } 
    103                 return (T) JSONArray.toArray( jsonArray, componentType ); 
     93                tapas.setRequests( requests ); 
     94                return (T) tapas; 
    10495            } 
    105             if( beanClass.isAssignableFrom( Collection.class ) ) 
    106             { 
    107                 final TypeVariable<Class<T>>[] typeParameters = beanClass.getTypeParameters(); 
    108                 if( null == typeParameters || typeParameters.length != 1 || null == typeParameters[0] ) 
    109                     return (T) JSONArray.toCollection( jsonArray ); 
    110                 return (T) JSONArray.toCollection( jsonArray, typeParameters[0].getGenericDeclaration() ); 
    111             } 
     96// 
     97//            if( beanClass.isArray() ) 
     98//            { 
     99//                final Class<?> componentType = beanClass.getComponentType(); 
     100//                //json.sf.net does not support Long[] or long[] 
     101//                if( Long.class.equals( componentType ) || Long.TYPE.equals( componentType ) ) 
     102//                { 
     103//                    final Integer[] integers = (Integer[]) JSONArray.toArray( jsonArray, Integer.class ); 
     104//                    if( Long.class.equals( componentType ) ) 
     105//                    { 
     106//                        final Long[] resultArray = new Long[integers.length]; 
     107//                        for( int i = 0; i < integers.length; ++i ) 
     108//                            resultArray[i] = integers[i].longValue(); 
     109//                        return (T) resultArray; 
     110//                    } 
     111//                    if( Long.TYPE.equals( componentType ) ) 
     112//                    { 
     113//                        final long[] resultArray = new long[integers.length]; 
     114//                        for( int i = 0; i < integers.length; ++i ) 
     115//                            resultArray[i] = integers[i].longValue(); 
     116//                        return (T) resultArray; 
     117//                    } 
     118//                } 
     119//                return (T) JSONArray.toArray( jsonArray, componentType ); 
     120//            } 
     121//            if( beanClass.isAssignableFrom( Collection.class ) ) 
     122//            { 
     123//                final TypeVariable<Class<T>>[] typeParameters = beanClass.getTypeParameters(); 
     124//                if( null == typeParameters || typeParameters.length != 1 || null == typeParameters[0] ) 
     125//                    return (T) JSONArray.toCollection( jsonArray ); 
     126//                return (T) JSONArray.toCollection( jsonArray, typeParameters[0].getGenericDeclaration() ); 
     127//            } 
    112128        } 
    113129        final JSONObject jsonObject = JSONObject.fromObject( json, _jsonConfig ); 
  • tapas/web/init_script.jsp

    r396 r399  
    3131        requestCreateXML: function() 
    3232        { 
     33            var bob = new Object(); 
     34            bob.input1 = "eee"; 
     35            bob.input2 = "rr"; 
     36            var jsonBob = $.toJSON( bob ); 
     37 
    3338            var jsonFormXml = this.serializeFormXMLToJson(); 
    3439            if( jsonFormXml ) 
    3540                $.ajax( { 
    36                     url: "project?methodName=createUserRequest&jsonFormXML=" + jsonFormXml, 
     41                    url: "project?methodName=createUserRequest&jsonFormXml=" + jsonBob + "&jsonTapas=" + jsonFormXml, 
    3742                    success:jQuery.proxy( this.handleCreateXML, this ) 
    3843                } ); 
     
    5661        serializeFormXMLToJson: function() 
    5762        { 
    58             var formXML = new Object(); 
    59             formXML.input1 = $( "#1" ).val(); 
    60             formXML.input2 = $( "#2" ).val(); 
     63            var formXML = new Array(); 
     64            var requestXML = new Object(); 
     65 
     66            var preference = new Object(); 
     67            preference.format = $( "#1" ).val(); 
     68            preference.rayleigh_extinction = $( "#2" ).val(); 
     69            preference.h2o_extinction = "h2o_extinction"; 
     70            preference.o3_extinction = "o3_extinction"; 
     71            preference.o2_extinction = "o2_extinction"; 
     72            preference.co2_extinction = "co2_extinction"; 
     73 
     74            var observation = new Object(); 
     75            observation.date = "2012-02-24"; 
     76 
     77            requestXML.preference = preference; 
     78            requestXML.observation = observation; 
     79            requestXML.atmosphere = "atmosphereZZZZ"; 
     80 
     81            formXML[0] = requestXML; 
     82 
    6183            return $.toJSON( formXML ); 
    6284        } 
  • tapas/web/src/com/ether/Controller.java

    r396 r399  
    55import com.ether.annotation.ParamName; 
    66import com.ether.annotation.UseJSON; 
     7import com.ether.Tapas; 
    78import net.sf.json.JSONObject; 
    89import org.apache.commons.logging.Log; 
     
    3738    /** *********************************************************** **/ 
    3839    @ControllerMethod(jsonResult = true) 
    39     public JSONObject createUserRequest( @ParamName("jsonFormXML") @Mandatory @UseJSON final FormXML jsonFormXML ) 
     40    public JSONObject createUserRequest( @ParamName("jsonFormXml") @Mandatory @UseJSON final FormXML jsonFormXML, 
     41                                         @ParamName("jsonTapas") @Mandatory @UseJSON final Tapas jsonTapas ) 
    4042            throws ServiceException 
    4143    { 
Note: See TracChangeset for help on using the changeset viewer.