Index: trunk/thirds/otb2zcfg/otb2zcfg.cxx
===================================================================
--- trunk/thirds/otb2zcfg/otb2zcfg.cxx	(revision 817)
+++ trunk/thirds/otb2zcfg/otb2zcfg.cxx	(revision 917)
@@ -97,23 +97,58 @@
   std::cout << "    </Supported>" << std::endl;
   std::cout << "    <Supported>" << std::endl;
+  std::cout << "     mimeType = application/json" << std::endl;
+  std::cout << "     encoding = utf-8" << std::endl;
+  std::cout << "    </Supported>" << std::endl;
+  std::cout << "    <Supported>" << std::endl;
   std::cout << "     mimeType = application/zip" << std::endl;
   std::cout << "    </Supported>" << std::endl;
 }
 
-void printOutputImage(){
+void printOutputImage(ImagePixelType pt){
   std::cout << "   <LiteralData>" << std::endl;
   std::cout << "    dataType = string" << std::endl;
   std::cout << "    <Default>" << std::endl;
-  std::cout << "     value = float" << std::endl;
-  std::cout << "     AllowedValues = uint8,uint16,int16n,int32,int32,float,double" << std::endl;
+  // Check for the default pixel type
+  switch(pt){
+  case ImagePixelType_uint8:
+    std::cout << "     value = uint8" << std::endl;
+    break;
+  case ImagePixelType_int16:
+    std::cout << "     value = int16" << std::endl;
+    break;
+  case ImagePixelType_uint16:
+    std::cout << "     value = uint16" << std::endl;
+    break;
+  case ImagePixelType_int32:
+    std::cout << "     value = int32" << std::endl;
+    break;
+  case ImagePixelType_uint32:
+    std::cout << "     value = uint8" << std::endl;
+    break;
+  case ImagePixelType_double:
+    std::cout << "     value = uint8" << std::endl;
+    break;
+  default:
+    std::cout << "     value = float" << std::endl;
+    break;
+  }
+  std::cout << "     AllowedValues = uint8,uint16,int16,int32,int32,float,double" << std::endl;
   std::cout << "    </Default>" << std::endl;
   std::cout << "   </LiteralData>" << std::endl;
 }
 
-void printOutputComplexImage(){
+void printOutputComplexImage(ComplexImagePixelType pt){
   std::cout << "   <LiteralData>" << std::endl;
   std::cout << "    dataType = string" << std::endl;
   std::cout << "    <Default>" << std::endl;
-  std::cout << "     value = cfloat" << std::endl;
+  // Check for the default pixel type
+  switch(pt){
+  case ComplexImagePixelType_double:
+    std::cout << "     value = cdouble" << std::endl;
+    break;
+  default:
+    std::cout << "     value = cfloat" << std::endl;
+    break;
+  }
   std::cout << "     AllowedValues = cfloat,cdouble" << std::endl;
   std::cout << "    </Default>" << std::endl;
@@ -242,9 +277,10 @@
 	  }
 	  else{
-	    if(type == ParameterType_OutputImage)
-	      printOutputImage();
+	    if(type == ParameterType_OutputImage){
+	      printOutputImage(m_Application->GetParameterOutputImagePixelType(paramKey));
+	    }
 	    else{
 	      if(type == ParameterType_ComplexOutputImage){
-		printOutputComplexImage();
+		printOutputComplexImage(m_Application->GetParameterComplexOutputImagePixelType(paramKey));
 	      }else{
 		std::cout << "   <ComplexData>" << std::endl;
@@ -312,4 +348,5 @@
 	  std::string s=m_Application->GetParameterDescription(paramKey);
 	  if(s.length()>0){
+	    s=ReplaceAll(ReplaceAll(s,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
 	    std::cout << "   Title = " << s << std::endl;
 	    std::cout << "   Abstract = " << s << std::endl;
Index: trunk/thirds/saga2zcfg/saga2zcfg.c
===================================================================
--- trunk/thirds/saga2zcfg/saga2zcfg.c	(revision 817)
+++ trunk/thirds/saga2zcfg/saga2zcfg.c	(revision 917)
@@ -5,5 +5,5 @@
 
 #include <api_core.h>
-#include <module_library.h>
+#include <saga_api.h>
 
 int Callback(TSG_UI_Callback_ID ID, CSG_UI_Parameter &Param_1, CSG_UI_Parameter &Param_2){
@@ -144,22 +144,41 @@
   static bool g_bShow_Messages = false;
   SG_Set_UI_Callback(Get_Callback());
+#if SAGA_MAJOR_VERSION == 2
   int n = SG_Get_Module_Library_Manager().Add_Directory(wxT(MODULE_LIBRARY_PATH),false);
-  if( SG_Get_Module_Library_Manager().Get_Count() <= 0 ){
+  if( SG_Get_Module_Library_Manager().Get_Count() <= 0 )
+#else
+  int n = SG_Get_Tool_Library_Manager().Add_Directory(wxT(MODULE_LIBRARY_PATH),false);
+  if( SG_Get_Tool_Library_Manager().Get_Count() <= 0 )
+#endif
+  {
     fprintf(stderr,"could not load any tool library");
     return -2;
   }
 
-  for(int i=0;i<SG_Get_Module_Library_Manager().Get_Count();i++){
+#if SAGA_MAJOR_VERSION == 2
+  for(int i=0;i<SG_Get_Module_Library_Manager().Get_Count();i++)
+#else
+  for(int i=0;i<SG_Get_Tool_Library_Manager().Get_Count();i++)
+#endif
+    {
     
+#if SAGA_MAJOR_VERSION == 2
     CSG_Module_Library * library=SG_Get_Module_Library_Manager().Get_Library(i);
+#else
+    CSG_Tool_Library * library=SG_Get_Tool_Library_Manager().Get_Library(i);
+#endif
     int lc=library->Get_Count();
     if(!library->Get_Library_Name().Contains("io_")) {
 
       for(int j=0;j<lc;j++){
+#if SAGA_MAJOR_VERSION == 2
 	CSG_Module * module=library->Get_Module(j);
+#else
+	CSG_Tool * module=library->Get_Tool(j);
+#endif
 	if(module!=NULL && !module->needs_GUI() /*&& !module->is_Interactive()*/ ){
 
 	  mkdir(library->Get_Library_Name().b_str(),0755);
-
+	  
 	  FILE *stdout1=fopen((library->Get_Library_Name()+"/"+module->Get_ID()+".zcfg").b_str(),"w+");
 	  fprintf(stdout1,"[%d]\n",j);
@@ -203,4 +222,12 @@
 	      
 	    }
+	    else if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("date"),true)){
+	      printBasicMetadata(stdout1,param,false,true,true);
+	      fprintf(stdout1,"  <LiteralData>\n");
+	      fprintf(stdout1,"   dataType = date\n");
+	      fprintf(stdout1,"   <Default/>\n");
+	      fprintf(stdout1,"  </LiteralData>\n");
+	      
+	    }
 	    else if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("range"),true)){
 
@@ -212,5 +239,9 @@
 	      CSG_Parameter_Range *range=param->asRange();
 	      fprintf(stdout1,"   <Default>\n");
+#if SAGA_MAJOR_VERSION == 2
 	      fprintf(stdout1,"    value = %f\n",((CSG_Parameter_Range*)param->Get_Data())->Get_LoVal());
+#else
+	      //fprintf(stdout1,"    value = %f\n",((CSG_Parameter_Range*)param->asDataObject())->Get_Min());	      
+#endif
 	      fprintf(stdout1,"   </Default>\n");
 	      fprintf(stdout1,"  </LiteralData>\n");
@@ -220,5 +251,9 @@
 	      fprintf(stdout1,"   dataType = float\n");
 	      fprintf(stdout1,"   <Default>\n");
+#if SAGA_MAJOR_VERSION == 2
 	      fprintf(stdout1,"    value = %f\n",((CSG_Parameter_Range*)param->Get_Data())->Get_HiVal());
+#else
+	      //fprintf(stdout1,"    value = %f\n",((CSG_Parameter_Range*)param->asDataObject())->Get_Max());	      
+#endif
 	      fprintf(stdout1,"   </Default>\n");
 	      fprintf(stdout1,"  </LiteralData>\n");
@@ -280,7 +315,13 @@
 		fprintf(stdout1,"   dataType = string\n");
 		fprintf(stdout1,"   <Default>\n");
+#if SAGA_MAJOR_VERSION == 2
 		if( !param->Get_Data()->Get_Default().is_Empty() ){
 		  fprintf(stdout1,"    value = %s\n",param->Get_Data()->Get_Default().b_str());
 		}
+#else
+		if( !param->Get_Default().is_Empty() ){
+		  fprintf(stdout1,"    value = %s\n",param->Get_Default().b_str());
+		}
+#endif
 		fprintf(stdout1,"   </Default>\n");
 		fprintf(stdout1,"  </LiteralData>\n");
@@ -299,7 +340,13 @@
 
 		fprintf(stdout1,"   <Default>\n");
+#if SAGA_MAJOR_VERSION == 2
 		if( !param->Get_Data()->Get_Default().is_Empty() ){
 		  fprintf(stdout1,"    value = %s\n",param->Get_Data()->Get_Default().b_str());
 		}
+#else
+		if( !param->Get_Default().is_Empty() ){
+		  fprintf(stdout1,"    value = %s\n",param->Get_Default().b_str());
+		}
+#endif
 		if(param->asValue()->has_Minimum() && param->asValue()->has_Maximum()){
 		  fprintf(stdout1,"    rangeMin = %f\n",param->asValue()->Get_Minimum());
@@ -314,7 +361,13 @@
 		fprintf(stdout1,"   dataType = bool\n");
 		fprintf(stdout1,"   <Default>\n");
+#if SAGA_MAJOR_VERSION == 2
 		if( !param->Get_Data()->Get_Default().is_Empty() ){
 		  fprintf(stdout1,"    value = %s\n",(param->Get_Data()->Get_Default().Contains("0")?"false":"true"));
 		}
+#else
+		if( !param->Get_Default().is_Empty() ){
+		  fprintf(stdout1,"    value = %s\n",(param->Get_Default().Contains("0")?"false":"true"));
+		}
+#endif
 		fprintf(stdout1,"   </Default>\n");
 		fprintf(stdout1,"  </LiteralData>\n");	
@@ -337,7 +390,13 @@
 		  }
 		  fprintf(stdout1,"   <Default>\n");
+#if SAGA_MAJOR_VERSION == 2
 		  if( !param->Get_Data()->Get_Default().is_Empty() ){
 		    fprintf(stdout1,"    value = %s\n",CSG_String(choice->Get_Item(atoi(param->Get_Data()->Get_Default()))).b_str());
 		  }
+#else
+		  if( !param->Get_Default().is_Empty() ){
+		    fprintf(stdout1,"    value = %s\n",CSG_String(choice->Get_Item(atoi(param->Get_Default()))).b_str());
+		  }		  
+#endif
 		  fprintf(stdout1,"   </Default>\n");
 		  fprintf(stdout1,"  </LiteralData>\n");
Index: trunk/thirds/zcfg2sql/Makefile
===================================================================
--- trunk/thirds/zcfg2sql/Makefile	(revision 917)
+++ trunk/thirds/zcfg2sql/Makefile	(revision 917)
@@ -0,0 +1,16 @@
+ZRPATH=../../zoo-project
+include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts
+LCFLAGS=${CFLAGS} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG
+CC=gcc
+
+ifeq (${CALLBACK_FILE},service_callback.o)
+CALLBACK_FILES=${ZRPATH}/zoo-kernel/${CALLBACK_FILE} ${ZRPATH}/zoo-kernel/ulinet.o ${ZRPATH}/zoo-kernel/caching.o
+else
+CALLBACK_FILES=
+endif
+zcfg2sql: zcfg2sql.c
+	g++ -g -O2 ${JSCFLAGS} ${RUBYCFLAGS} ${XML2CFLAGS} ${LCFLAGS} -c zcfg2sql.c  -fno-common -DPIC -o zcfg2sql.o
+	g++  ${XML2CFLAGS} ${LCFLAGS} zcfg2sql.o ${CALLBACK_FILES} ${ZRPATH}/zoo-kernel/server_internal.o ${ZRPATH}/zoo-kernel/service_internal.o ${ZRPATH}/zoo-kernel/${MS_FILE} ${ZRPATH}/zoo-kernel/response_print.o ${ZRPATH}/zoo-kernel/lex.cr.o ${ZRPATH}/zoo-kernel/lex.sr.o ${ZRPATH}/zoo-kernel/service_conf.tab.o ${ZRPATH}/zoo-kernel/main_conf_read.tab.o  ${ZRPATH}/zoo-kernel/${YAML_FILE} -o zcfg2sql -L${ZRPATH}/zoo-kernel/ ${LDFLAGS}
+
+clean:
+	rm -f zcfg2sql
Index: trunk/thirds/zcfg2sql/zcfg2sql.c
===================================================================
--- trunk/thirds/zcfg2sql/zcfg2sql.c	(revision 917)
+++ trunk/thirds/zcfg2sql/zcfg2sql.c	(revision 917)
@@ -0,0 +1,494 @@
+/*
+ * Author : Gérald FENOY
+ *
+ *  Copyright (c) 2017-2019 GeoLabs SARL. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "service.h"
+
+extern int getServiceFromFile (maps *, const char *, service **);
+
+/**
+ * Dump an elements on stderr using the SQL syntaxe
+ *
+ * @param e the elements to dump
+ */
+void dumpElementsAsSQL(const char* type,elements* e,int index,int level,FILE* f){
+  elements* tmp=e;
+  int i;
+  while(tmp!=NULL){
+    fprintf(f,"--\n-- %s %s \n--\n",type,tmp->name);
+    map* mcurs=tmp->content;
+    iotype* tmpio=tmp->defaults;
+    int ioc=0;
+    if(tmp->format!=NULL){
+      //fprintf(stderr,"%s:\n",tmp->format);
+      if(strncmp(tmp->format,"Complex",7)==0){
+	while(tmpio!=NULL){
+	  map* values[3]={
+	    getMap(tmpio->content,"mimeType"),
+	    getMap(tmpio->content,"encoding"),
+	    getMap(tmpio->content,"schema")
+	  };
+	  char cond[3][256]={
+	    "mime_type is NULL",
+	    "encoding is NULL",
+	    "schema is NULL"
+	  };
+	  char *condNames[3]={
+	    "mime_type",
+	    "encoding",
+	    "schema"
+	  };
+	  for(i=0;i<3;i++)
+	    if(values[i]!=NULL){
+	      sprintf(cond[i],"%s='%s'",condNames[i],values[i]->value);
+	    }
+	  fprintf(f,"INSERT INTO CollectionDB.ows_Format"
+		  " (def,primitive_format_id) VALUES \n(true,");
+	  fprintf(f,"(SELECT id from CollectionDB.PrimitiveFormats"
+		  " WHERE %s AND %s AND %s));\n",cond[0],cond[1],cond[2]);
+	  fprintf(f,"INSERT INTO CollectionDB.ows_DataDescription (format_id)"
+		  " VALUES ((SELECT last_value FROM CollectionDB.ows_Format_id_seq));\n");
+	  tmpio=tmpio->next;
+	  ioc++;
+	}
+      }else{
+	if(strncmp(tmp->format,"Literal",7)==0){
+	  while(tmpio!=NULL){
+	    map* values[4]={
+	      getMap(tmpio->content,"dataType"),
+	      getMap(tmpio->content,"value"),
+	      getMap(tmpio->content,"uom"),
+	      getMap(tmpio->content,"AllowedValues")
+	    };
+	    char *fields[20]={
+	      "default_value",
+	      "def"
+	    };
+	    fprintf(f,"INSERT INTO CollectionDB.LiteralDataDomain"
+		    " (def,data_type_id) VALUES \n(true,");
+	    fprintf(f,"(SELECT id from CollectionDB.PrimitiveDatatypes"
+		    " where name = '%s'));\n",values[0]->value);
+	    if(values[1]!=NULL)
+	      fprintf(f,"UPDATE CollectionDB.LiteralDataDomain \n"
+		      "set %s = $q$%s$q$ \n WHERE id = \n"
+		      "  ((SELECT last_value FROM CollectionDB.ows_DataDescription_id_seq));\n ",
+		      fields[0],values[1]->value);
+	    if(values[2]!=NULL)
+	      fprintf(f,"UPDATE CollectionDB.LiteralDataDomain \n"
+		      "set uom = (SELECT id from CollectionDB.PrimitiveUOM WHERE uom=$q$%s$q$) \n WHERE id = \n"
+		      "  (SELECT last_value FROM CollectionDB.ows_DataDescription_id_seq);\n ",
+		      values[2]->value);
+	    if(values[3]!=NULL){
+	      char *tmp=strtok(values[3]->value,",");
+	      while(tmp!=NULL){
+		fprintf(f,"INSERT INTO CollectionDB.AllowedValues (allowed_value) VALUES ('%s');\n",tmp);
+		fprintf(f,"INSERT INTO CollectionDB.AllowedValuesAssignment"
+			" (allowed_value_id,literal_data_domain_id) VALUES "
+			"((SELECT last_value FROM CollectionDB.AllowedValues_id_seq),"
+			"(SELECT last_value FROM CollectionDB.ows_DataDescription_id_seq));\n",tmp);
+		tmp=strtok(NULL,",");
+	      }
+	    }
+	    tmpio=tmpio->next;
+	    ioc++;
+	  }	  
+	}
+      }
+
+    }
+    
+    map* values[4]={
+      getMap(tmp->content,"Title"),
+      getMap(tmp->content,"Abstract"),
+      getMap(tmp->content,"minOccurs"),
+      getMap(tmp->content,"maxOccurs")
+    };
+    char *toto=",min_occurs,max_occurs";
+    if(strcmp(type,"Input")==0){
+      fprintf(f,"INSERT INTO CollectionDB.ows_Input "
+	      "(identifier,title,abstract,min_occurs,max_occurs)"
+	      " VALUES "
+	      "($q$%s$q$,\n$q$%s$q$,\n$q$%s$q$,\n%s,\n%s);\n",
+	      tmp->name,
+	      values[0]->value,
+	      values[1]->value,
+	      values[2]->value,
+	      values[3]->value
+	      );
+      if(tmp->format!=NULL)
+	fprintf(f,"INSERT INTO CollectionDB.InputDataDescriptionAssignment"
+		" (input_id,data_description_id) VALUES "
+		"((select last_value as id "
+	        "from CollectionDB.Descriptions_id_seq),"
+		"(select last_value "
+		"from CollectionDB.ows_DataDescription_id_seq));\n");
+      if(level==0)
+	fprintf(f,"INSERT INTO CollectionDB.ProcessInputAssignment"
+		"(process_id,input_id)"
+		" VALUES"
+		"((select id from pid),"
+		"(select last_value as id from CollectionDB.Descriptions_id_seq));\n");
+      else
+	fprintf(f,"INSERT INTO CollectionDB.InputInputAssignment"
+		"(parent_input,child_input)"
+		" VALUES"
+		"((select id from cid_%d),"
+		"(select last_value as id from CollectionDB.Descriptions_id_seq));\n",level-1);
+    }
+    else{
+      fprintf(f,"INSERT INTO CollectionDB.ows_Output\n"
+	      "\t(identifier,title,abstract)\n"
+	      "\t VALUES \n"
+	      "($q$%s$q$,$q$%s$q$,$q$%s$q$);\n",
+	      tmp->name,
+	      values[0]->value,
+	      values[1]->value
+	      );
+      if(tmp->format!=NULL)
+	fprintf(f,"INSERT INTO CollectionDB.OutputDataDescriptionAssignment"
+		" (output_id,data_description_id) VALUES "
+		"((select last_value as id "
+	        "from CollectionDB.Descriptions_id_seq),"
+		"(select last_value "
+		"from CollectionDB.ows_DataDescription_id_seq));\n");
+      if(level==0)
+	fprintf(f,"INSERT INTO CollectionDB.ProcessOutputAssignment"
+		"(process_id,output_id)"
+		" VALUES"
+		"((select id from pid),"
+		"(select last_value as id from CollectionDB.Descriptions_id_seq));\n");
+      else
+	fprintf(f,"INSERT INTO CollectionDB.OutputOutputAssignment"
+		"(parent_output,child_output)"
+		" VALUES"
+		"((select id from cid_%d),"
+		"(select last_value as id from CollectionDB.Descriptions_id_seq));\n",level-1);
+    }
+
+    map* mcurs1=tmp->metadata;
+    if(mcurs1!=NULL){
+      while(mcurs1!=NULL){
+	if(strncasecmp(mcurs1->name,"title",5)==0){
+	  fprintf(stdout,"INSERT INTO CollectionDB.ows_Metadata (title) "
+		  "VALUES ($q$%s$q$);\n",mcurs->value);
+	tryagain0:
+	  if(mcurs1->next!=NULL){
+	    if(strncasecmp(mcurs->next->name,"role",4)==0){
+	      fprintf(stdout,"UPDATE CollectionDB.ows_Metadata set role = \n"
+		      "$q$%s$q$ where id=(SELECT last_value FROM CollectionDB.ows_Metadata_id_seq);\n",mcurs1->next->value);
+	      mcurs1=mcurs1->next;
+	      goto tryagain0;
+	    }
+	    else{
+	      if(strncasecmp(mcurs1->next->name,"href",4)==0){
+		fprintf(stdout,"UPDATE CollectionDB.ows_Metadata set href = \n"
+			"$q$%s$q$ where id=(SELECT last_value FROM CollectionDB.ows_Metadata_id_seq);\n",mcurs1->next->value);
+		mcurs1=mcurs1->next;
+		goto tryagain0;
+	      }
+	    }
+	  }
+	  fprintf(stdout,"INSERT INTO CollectionDB.DescriptionsMetadataAssignment (descriptions_id,metadata_id) "
+		  "VALUES ((select last_value as id from CollectionDB.Descriptions_id_seq),"
+		  "(SELECT last_value FROM CollectionDB.ows_Metadata_id_seq));\n");	  
+	}
+	mcurs1=mcurs1->next;
+      }
+    }
+    mcurs=tmp->additional_parameters;
+    if(mcurs!=NULL){
+      while(mcurs!=NULL){
+	if(strncasecmp(mcurs->name,"title",5)==0){
+	  fprintf(stdout,"INSERT INTO CollectionDB.ows_AdditionalParameters (title) "
+		  "VALUES ($q$%s$q$);\n",mcurs->value);
+	tryagain:
+	  if(mcurs->next!=NULL){
+	    if(strncasecmp(mcurs->next->name,"role",4)==0){
+	      fprintf(stdout,"UPDATE CollectionDB.ows_AdditionalParameters set role = \n"
+		      "$q$%s$q$ where id=(SELECT last_value FROM CollectionDB.ows_AdditionalParameters_id_seq);\n",mcurs->next->value);
+	      mcurs=mcurs->next;
+	      goto tryagain;
+	    }
+	    else{
+	      if(strncasecmp(mcurs->next->name,"href",4)==0){
+		fprintf(stdout,"UPDATE CollectionDB.ows_AdditionalParameters set href = \n"
+			"$q$%s$q$ where id=(SELECT last_value FROM CollectionDB.ows_AdditionalParameters_id_seq);\n",mcurs->next->value);
+		mcurs=mcurs->next;
+		goto tryagain;
+	      }
+	    }
+	  }
+	  fprintf(stdout,"INSERT INTO CollectionDB.DescriptionsAdditionalParametersAssignment (descriptions_id,additional_parameters_id) "
+		  "VALUES ((select last_value as id from CollectionDB.Descriptions_id_seq),"
+		  "(SELECT last_value FROM CollectionDB.ows_AdditionalParameters_id_seq));\n");	  
+	}else{
+	  fprintf(stdout,"INSERT INTO CollectionDB.ows_AdditionalParameter (key,value,additional_parameters_id) "
+		  "VALUES ($q$%s$q$,$q$%s$q$,"
+		  "(SELECT last_value FROM CollectionDB.ows_AdditionalParameters_id_seq));\n",mcurs->name,mcurs->value);	  
+	}
+	mcurs=mcurs->next;
+      }
+    }
+
+    if(tmp->format!=NULL){
+      tmpio=tmp->supported;
+      if(strncmp(tmp->format,"Complex",7)==0){
+	while(tmpio!=NULL){
+	  map* values[3]={
+	    getMap(tmpio->content,"mimeType"),
+	    getMap(tmpio->content,"encoding"),
+	    getMap(tmpio->content,"schema")
+	  };
+	  char cond[3][256]={
+	    "mime_type is NULL",	    
+	    "encoding is NULL",
+	    "schema is NULL",
+	  };
+	  char *condNames[3]={
+	    "mime_type",
+	    "encoding",
+	    "schema"
+	  };
+	  for(i=0;i<3;i++)
+	    if(values[i]!=NULL){
+	      sprintf(cond[i],"%s='%s'",condNames[i],values[i]->value);
+	    }
+	  fprintf(f,"INSERT INTO CollectionDB.ows_Format"
+		  " (def,primitive_format_id) VALUES \n(false,");
+	  fprintf(f,"(SELECT id from CollectionDB.PrimitiveFormats"
+		  " WHERE %s AND %s AND %s));\n",cond[0],cond[1],cond[2]);
+	  fprintf(f,"INSERT INTO CollectionDB.ows_DataDescription (format_id)"
+		  " VALUES ((SELECT last_value FROM CollectionDB.ows_Format_id_seq));\n");
+	  fprintf(f,"INSERT INTO CollectionDB.%sDataDescriptionAssignment"
+		  " (%s_id,data_description_id) VALUES "
+		  "((select last_value as id "
+		  "from CollectionDB.Descriptions_id_seq),"
+		  "(select last_value "
+		  "from CollectionDB.ows_DataDescription_id_seq));\n",
+		  type,type);	  
+	  tmpio=tmpio->next;
+	  ioc++;
+	}
+      }else{
+	if(strncmp(tmp->format,"Literal",7)==0){
+	  while(tmpio!=NULL){
+	    map* values[4]={
+	      getMap(tmpio->content,"dataType"),
+	      getMap(tmpio->content,"value"),
+	      getMap(tmpio->content,"uom"),
+	      getMap(tmpio->content,"AllowedValues")
+	    };
+	    map* values0[4]={
+	      getMap(tmp->defaults->content,"dataType"),
+	      getMap(tmp->defaults->content,"value"),
+	      getMap(tmp->defaults->content,"uom"),
+	      getMap(tmp->defaults->content,"AllowedValues")
+	    };
+	    char *fields[20]={
+	      "default_value",
+	      "def"
+	    };
+	    fprintf(f,"INSERT INTO CollectionDB.LiteralDataDomain"
+		    " (def,data_type_id) VALUES \n(false,");
+	    if(values[0]!=NULL)
+	      fprintf(f,"(SELECT id from CollectionDB.PrimitiveDatatypes"
+		      " where name = '%s'));\n",values[0]->value);
+	    else
+	      fprintf(f,"(SELECT id from CollectionDB.PrimitiveDatatypes"
+		      " where name = '%s'));\n",values0[0]->value);
+	    if(values[1]!=NULL)
+	      fprintf(f,"UPDATE CollectionDB.LiteralDataDomain \n"
+		      "set %s = $q$%s$q$ \n WHERE id = \n"
+		      "  ((SELECT last_value FROM CollectionDB.ows_DataDescription_id_seq));\n ",
+		      fields[0],values[1]->value);
+	    if(values[2]!=NULL)
+	      fprintf(f,"UPDATE CollectionDB.LiteralDataDomain \n"
+		      "set uom = (SELECT id from CollectionDB.PrimitiveUOM WHERE uom=$q$%s$q$) \n WHERE id = \n"
+		      "  (SELECT last_value FROM CollectionDB.ows_DataDescription_id_seq);\n ",
+		      values[2]->value);
+	    if(type!=NULL)
+	    fprintf(f,"INSERT INTO CollectionDB.%sDataDescriptionAssignment"
+		    " (%s_id,data_description_id) VALUES "
+		    "((select last_value "
+		    "from CollectionDB.Descriptions_id_seq),"
+		    "(select last_value "
+		    "from CollectionDB.ows_DataDescription_id_seq));\n",
+		    type,type);	  
+	    tmpio=tmpio->next;
+	    ioc++;
+	  }	  
+	}
+      }
+    }
+
+    if(tmp->format==NULL){
+      fprintf(f,"--\n-- Child %d \n--\n",level);
+      fprintf(f,"CREATE TEMPORARY TABLE cid_%d AS (select last_value as id from CollectionDB.Descriptions_id_seq) ;\n",level);
+      if(tmp->child!=NULL)
+	dumpElementsAsSQL(type,tmp->child,0,level+1,f);
+      fprintf(f,"DROP TABLE cid_%d;\n",level);
+      fprintf(f,"--\n-- End Child %d \n--\n",level);
+    }
+    tmp=tmp->next;
+  }
+}
+
+
+int main(int argc, char *argv[]) {
+  service* s=NULL;
+  maps *m=NULL;
+  char conf_file[1024];
+  snprintf(conf_file,1024,"%s",argv[1]);
+  s=(service*)malloc(SERVICE_SIZE);
+  if(s == NULL){
+    fprintf(stderr,"Unable to allocate memory");
+    return -1;
+  }
+  int t=getServiceFromFile(m,conf_file,&s);
+
+  fprintf(stdout,"--\n-- Load from %s %d \n--",__FILE__,__LINE__);
+  int i;
+  fprintf(stdout,"--\n-- Service %s\n--\n",s->name);
+  if(s->content!=NULL){
+    map* values[4]={
+      getMap(s->content,"Title"),
+      getMap(s->content,"Abstract"),
+      getMap(s->content,"serviceProvider"),
+      getMap(s->content,"serviceType")
+    };
+    fprintf(stdout,"INSERT INTO CollectionDB.zoo_DeploymentMetadata\n"
+	    "(executable_name,service_type_id)\n"
+	    "\nVALUES\n"
+	    "($q$%s$q$,\n(SELECT id from CollectionDB.zoo_ServiceTypes WHERE service_type=$q$%s$q$));\n\n",
+	    values[2]->value,
+	    values[3]->value);
+    fprintf(stdout,"INSERT INTO CollectionDB.zoo_PrivateMetadata"
+	    "(id) VALUES (default);\n"); 
+    fprintf(stdout,"INSERT INTO CollectionDB.PrivateMetadataDeploymentMetadataAssignment"
+	    "(private_metadata_id,deployment_metadata_id) VALUES \n"
+	    "((SELECT last_value FROM CollectionDB.zoo_PrivateMetadata_id_seq),\n"
+	    "(SELECT last_value FROM CollectionDB.zoo_DeploymentMetadata_id_seq));\n");
+    fprintf(stdout,"INSERT INTO CollectionDB.ows_Process\n"
+	    "(identifier,title,abstract,private_metadata_id,"
+	    "availability)\n"
+	    "\nVALUES\n"
+	    "($q$%s$q$,\n$q$%s$q$,\n$q$%s$q$,(SELECT last_value FROM CollectionDB.PrivateMetadataDeploymentMetadataAssignment_id_seq),\ntrue);\n\n",
+	    s->name,
+	    values[0]->value,
+	    values[1]->value);
+    fprintf(stdout,"CREATE TEMPORARY TABLE pid AS "
+	    "(select last_value as id from CollectionDB.Descriptions_id_seq);\n");
+    map* mcurs=s->content;
+    //dumpMap(mcurs);
+    mcurs=s->metadata;
+    if(mcurs!=NULL){
+      while(mcurs!=NULL){
+	if(strncasecmp(mcurs->name,"title",5)==0){
+	  fprintf(stdout,"INSERT INTO CollectionDB.ows_Metadata (title) "
+		  "VALUES ($q$%s$q$);\n",mcurs->value);
+	tryagain0:
+	  if(mcurs->next!=NULL){
+	    if(strncasecmp(mcurs->next->name,"role",4)==0){
+	      fprintf(stdout,"UPDATE CollectionDB.ows_Metadata set role = \n"
+		      "$q$%s$q$ where id=(SELECT last_value FROM CollectionDB.ows_Metadata_id_seq);\n",mcurs->next->value);
+	      mcurs=mcurs->next;
+	      goto tryagain0;
+	    }
+	    else{
+	      if(strncasecmp(mcurs->next->name,"href",4)==0){
+		fprintf(stdout,"UPDATE CollectionDB.ows_Metadata set href = \n"
+			"$q$%s$q$ where id=(SELECT last_value FROM CollectionDB.ows_Metadata_id_seq);\n",mcurs->next->value);
+		mcurs=mcurs->next;
+		goto tryagain0;
+	      }
+	    }
+	  }
+	  fprintf(stdout,"INSERT INTO CollectionDB.DescriptionsMetadataAssignment (descriptions_id,metadata_id) "
+		  "VALUES ((select last_value as id from CollectionDB.Descriptions_id_seq),"
+		  "(SELECT last_value FROM CollectionDB.ows_Metadata_id_seq));\n");	  
+	}
+	mcurs=mcurs->next;
+      }
+    }
+    mcurs=s->additional_parameters;
+    if(mcurs!=NULL){
+      while(mcurs!=NULL){
+	if(strncasecmp(mcurs->name,"title",5)==0){
+	  fprintf(stdout,"INSERT INTO CollectionDB.ows_AdditionalParameters (title) "
+		  "VALUES ($q$%s$q$);\n",mcurs->value);
+	tryagain:
+	  if(mcurs->next!=NULL){
+	    if(strncasecmp(mcurs->next->name,"role",4)==0){
+	      fprintf(stdout,"UPDATE CollectionDB.ows_AdditionalParameters set role = \n"
+		      "$q$%s$q$ where id=(SELECT last_value FROM CollectionDB.ows_AdditionalParameters_id_seq);\n",mcurs->next->value);
+	      mcurs=mcurs->next;
+	      goto tryagain;
+	    }
+	    else{
+	      if(strncasecmp(mcurs->next->name,"href",4)==0){
+		fprintf(stdout,"UPDATE CollectionDB.ows_AdditionalParameters set href = \n"
+			"$q$%s$q$ where id=(SELECT last_value FROM CollectionDB.ows_AdditionalParameters_id_seq);\n",mcurs->next->value);
+		mcurs=mcurs->next;
+		goto tryagain;
+	      }
+	    }
+	  }
+	  fprintf(stdout,"INSERT INTO CollectionDB.DescriptionsAdditionalParametersAssignment (descriptions_id,additional_parameters_id) "
+		  "VALUES ((select last_value as id from CollectionDB.Descriptions_id_seq),"
+		  "(SELECT last_value FROM CollectionDB.ows_AdditionalParameters_id_seq));\n");	  
+	}else{
+	  fprintf(stdout,"INSERT INTO CollectionDB.ows_AdditionalParameter (key,value,additional_parameters_id) "
+		  "VALUES ($q$%s$q$,$q$%s$q$,"
+		  "(SELECT last_value FROM CollectionDB.ows_AdditionalParameters_id_seq));\n",mcurs->name,mcurs->value);	  
+	}
+	mcurs=mcurs->next;
+      }
+    }
+    
+  }
+  if(s->inputs!=NULL){
+    //fprintf(stderr,"\ninputs:\n");
+    dumpElementsAsSQL("Input",s->inputs,0,0,stdout);
+  }
+  if(s->outputs!=NULL){
+    //fprintf(stderr,"\noutputs:\n");
+    dumpElementsAsSQL("Output",s->outputs,0,0,stdout);
+  }
+  fprintf(stdout,"--\n-- Load from %s %d \n--",__FILE__,__LINE__);
+
+  
+  
+  /*fprintf(stderr,"--\n-- Load from %s %d \n--",__FILE__,__LINE__);
+  fflush(stderr);
+  printf("--\n-- Load from %s %d \n--",__FILE__,__LINE__);
+  if(t>=0){
+    fprintf(stderr,"--\n-- Service %s\n--",s->name);
+    fflush(stderr);
+    dumpServiceAsSQL(s); 
+    fprintf(stderr,"--\n-- Service %s\n--",s->name);
+    fflush(stderr);
+  }
+  */
+  fflush(stderr);
+  return 0;
+}
