예제 #1
0
axis2_status_t test_date_time(axutil_env_t *env)
{
    axutil_date_time_t *date_time = NULL;
    axutil_date_time_t *ref = NULL;
    axutil_date_time_t *date_time_offset = NULL;
    axis2_char_t *time_str = "22:45:12";
    axis2_char_t *date_str = "2000-12-12";
    axis2_char_t *date_time_str = "2000-11-11T12:30:24";
    axis2_status_t status = AXIS2_FAILURE;
    axutil_date_time_comp_result_t compare_res = AXIS2_DATE_TIME_COMP_RES_FAILURE;
    axis2_char_t *t_str = NULL, *d_str = NULL, *dt_str = NULL;
    int year , month , date , hour , min , sec , msec;

    date_time_offset = axutil_date_time_create_with_offset(env, 100);
    if(!date_time_offset)
    {
        printf("axutil_date_time_t creation failed.\n");
        return AXIS2_FAILURE;
    }
    date_time = axutil_date_time_create(env);
    if(!date_time)
    {
        printf("axutil_date_time_t creation failed.\n");
        return AXIS2_FAILURE;
    }
    status = axutil_date_time_deserialize_time(date_time, env, time_str);
    if(status)
        printf("axutil_date_time_t time string deserialization success.\n");
    status = axutil_date_time_deserialize_date(date_time, env, date_str);
    if(status)
        printf("axutil_date_time_t date string deserialization success.\n");
    status = axutil_date_time_deserialize_date_time(date_time, env, date_time_str);
    if(status)
        printf("axutil_date_time_t date time string deserialization success.\n");

    ref = axutil_date_time_create(env);
    if(!ref)
    {
        printf("axutil_date_time_t creation failed.\n");
        return AXIS2_FAILURE;
    }
    compare_res = axutil_date_time_compare(date_time, env, ref);
    if(compare_res == AXIS2_DATE_TIME_COMP_RES_FAILURE)
    {
        printf("axutil_date_time comparison failed.\n");
    }

    status = axutil_date_time_deserialize_date_time(ref, env, date_time_str);
    if(status)
        printf("axutil_date_time_t date time string deserialization success.\n");
    compare_res = axutil_date_time_compare(date_time, env, ref);
    if(compare_res == AXIS2_DATE_TIME_COMP_RES_EQUAL)
    {
        printf("axutil_date_time_t comparison success.");
    }
    status = axutil_date_time_set_date_time(date_time, env, 2008, 1, 8, 12, 18, 57, 799);
    if(status)
    {
        printf("axutil_date_time_t set date time success.\n");
    }

    t_str = axutil_date_time_serialize_time(date_time, env);
    if(!t_str)
    {
        printf("axutil_date_time_t time serialization failed.\n");
    }
    else
    {
        printf("axutil_date_time_t Time: %s\n", t_str);
    }
    d_str = axutil_date_time_serialize_date(date_time, env);
    if(!d_str)
    {
        printf("axutil_date_time_t date serialization failed.\n");
    }
    else
    {
        printf("axutil_date_time_t Date: %s\n", d_str);
    }
    dt_str = axutil_date_time_serialize_date_time(date_time, env);
    if(!dt_str)
    {
        printf("axutil_date_time_t date time serialization failed.\n");
    }
    else
    {
        printf("axutil_date_time_t Date Time: %s\n", dt_str);
    }
    year = axutil_date_time_get_year(date_time,env);
    month=axutil_date_time_get_month(date_time,env);
    date = axutil_date_time_get_day(date_time,env);
    hour = axutil_date_time_get_hour(date_time,env);
    min  = axutil_date_time_get_minute(date_time,env);
    sec  = axutil_date_time_get_second(date_time,env);
    msec = axutil_date_time_get_msec(date_time,env);
    printf("axutil_date_time_t year: %d \n",year);
    printf("axutil_date_time_t month: %d \n",month);
    printf("axutil_date_time_t date: %d \n",date);
    printf("axutil_date_time_t hour: %d \n",hour);
    printf("axutil_date_time_t min: %d \n",min);
    printf("axutil_date_time_t sec: %d \n",sec);
    printf("axutil_date_time_t msec: %d \n",msec);

    axutil_date_time_free(date_time,env);
    axutil_date_time_free(ref, env);
    axutil_date_time_free(date_time_offset, env);
    return AXIS2_SUCCESS;
}
        axis2_status_t AXIS2_CALL
        adb_contentItem_type0_deserialize_obj(
                adb_contentItem_type0_t* _contentItem_type0,
                const axutil_env_t *env,
                axiom_node_t **dp_parent,
                axis2_bool_t *dp_is_early_node_valid,
                axis2_bool_t dont_care_minoccurs)
        {
          axiom_node_t *parent = *dp_parent;
          
          axis2_status_t status = AXIS2_SUCCESS;
          
              axiom_attribute_t *parent_attri = NULL;
              axiom_element_t *parent_element = NULL;
              axis2_char_t *attrib_text = NULL;

              axutil_hash_t *attribute_hash = NULL;

          
              void *element = NULL;
           
             const axis2_char_t* text_value = NULL;
             axutil_qname_t *qname = NULL;
          
            axutil_qname_t *element_qname = NULL; 
            
               axiom_node_t *first_node = NULL;
               axis2_bool_t is_early_node_valid = AXIS2_TRUE;
               axiom_node_t *current_node = NULL;
               axiom_element_t *current_element = NULL;
            
            AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
            AXIS2_PARAM_CHECK(env->error, _contentItem_type0, AXIS2_FAILURE);

            
              
              while(parent && axiom_node_get_node_type(parent, env) != AXIOM_ELEMENT)
              {
                  parent = axiom_node_get_next_sibling(parent, env);
              }
              if (NULL == parent)
              {
                /* This should be checked before everything */
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                            "Failed in building adb object for contentItem_type0 : "
                            "NULL element can not be passed to deserialize");
                return AXIS2_FAILURE;
              }
              
                      
                      first_node = axiom_node_get_first_child(parent, env);
                      
                    
                 parent_element = (axiom_element_t *)axiom_node_get_data_element(parent, env);
                 attribute_hash = axiom_element_get_all_attributes(parent_element, env);
              

                     
                     /*
                      * building label element
                      */
                     
                     
                     
                                   current_node = first_node;
                                   is_early_node_valid = AXIS2_FALSE;
                                   
                                   
                                    while(current_node && axiom_node_get_node_type(current_node, env) != AXIOM_ELEMENT)
                                    {
                                        current_node = axiom_node_get_next_sibling(current_node, env);
                                    }
                                    if(current_node != NULL)
                                    {
                                        current_element = (axiom_element_t *)axiom_node_get_data_element(current_node, env);
                                        qname = axiom_element_get_qname(current_element, env, current_node);
                                    }
                                   
                                 element_qname = axutil_qname_create(env, "label", "http://www.daisy.org/ns/daisy-online/", NULL);
                                 

                           if (adb_label_type0_is_particle() ||  
                                (current_node   && current_element && (axutil_qname_equals(element_qname, env, qname))))
                           {
                              if( current_node   && current_element && (axutil_qname_equals(element_qname, env, qname)))
                              {
                                is_early_node_valid = AXIS2_TRUE;
                              }
                              
                                 
                                      element = (void*)axis2_extension_mapper_create_from_node(env, &current_node, "adb_label_type0");

                                      status =  adb_label_type0_deserialize((adb_label_type0_t*)element,
                                                                            env, &current_node, &is_early_node_valid, AXIS2_FALSE);
                                      if(AXIS2_FAILURE == status)
                                      {
                                          AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "failed in building adb object for element label");
                                      }
                                      else
                                      {
                                          status = adb_contentItem_type0_set_label(_contentItem_type0, env,
                                                                   (adb_label_type0_t*)element);
                                      }
                                    
                                 if(AXIS2_FAILURE ==  status)
                                 {
                                     AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "failed in setting the value for label ");
                                     if(element_qname)
                                     {
                                         axutil_qname_free(element_qname, env);
                                     }
                                     return AXIS2_FAILURE;
                                 }
                              }
                           
                              else if(!dont_care_minoccurs)
                              {
                                  if(element_qname)
                                  {
                                      axutil_qname_free(element_qname, env);
                                  }
                                  /* this is not a nillable element*/
                                  AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "non nillable or minOuccrs != 0 element label missing");
                                  return AXIS2_FAILURE;
                              }
                           
                  if(element_qname)
                  {
                     axutil_qname_free(element_qname, env);
                     element_qname = NULL;
                  }
                 
                
                
                  parent_attri = NULL;
                  attrib_text = NULL;
                  if(attribute_hash)
                  {
                       axutil_hash_index_t *hi;
                       void *val;
                       const void *key;

                       for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, &key, NULL, &val);
                           
                           
                               if(!strcmp((axis2_char_t*)key, "id"))
                             
                               {
                                   parent_attri = (axiom_attribute_t*)val;
                                   AXIS2_FREE(env->allocator, hi);
                                   break;
                               }
                       }
                  }

                  if(parent_attri)
                  {
                    attrib_text = axiom_attribute_get_value(parent_attri, env);
                  }
                  else
                  {
                    /* this is hoping that attribute is stored in "id", this happnes when name is in default namespace */
                    attrib_text = axiom_element_get_attribute_value_by_name(parent_element, env, "id");
                  }

                  if(attrib_text != NULL)
                  {
                      
                      adb_contentItem_type0_set_id(_contentItem_type0,
                                                          env, attrib_text);
                        
                    }
                  
                    else if(!dont_care_minoccurs)
                    {
                        if(element_qname)
                        {
                            axutil_qname_free(element_qname, env);
                        }
                        /* this is not a nillable element*/
                        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "required attribute id missing");
                        return AXIS2_FAILURE;
                    }
                  
                  if(element_qname)
                  {
                     axutil_qname_free(element_qname, env);
                     element_qname = NULL;
                  }
                 
                
                
                  parent_attri = NULL;
                  attrib_text = NULL;
                  if(attribute_hash)
                  {
                       axutil_hash_index_t *hi;
                       void *val;
                       const void *key;

                       for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, &key, NULL, &val);
                           
                           
                               if(!strcmp((axis2_char_t*)key, "lastModifiedDate"))
                             
                               {
                                   parent_attri = (axiom_attribute_t*)val;
                                   AXIS2_FREE(env->allocator, hi);
                                   break;
                               }
                       }
                  }

                  if(parent_attri)
                  {
                    attrib_text = axiom_attribute_get_value(parent_attri, env);
                  }
                  else
                  {
                    /* this is hoping that attribute is stored in "lastModifiedDate", this happnes when name is in default namespace */
                    attrib_text = axiom_element_get_attribute_value_by_name(parent_element, env, "lastModifiedDate");
                  }

                  if(attrib_text != NULL)
                  {
                      
                      
                           element = (void*)axutil_date_time_create(env);
                           axutil_date_time_deserialize_date_time((axutil_date_time_t*)element, env,
                                                                      attrib_text);
                           adb_contentItem_type0_set_lastModifiedDate(_contentItem_type0,
                                                          env, (axutil_date_time_t*)element);
                        
                    }
                  
                  if(element_qname)
                  {
                     axutil_qname_free(element_qname, env);
                     element_qname = NULL;
                  }
                 
          return status;
       }