Package com.dbxml.labrador.types

Examples of com.dbxml.labrador.types.Variant


      lastSyncDate = new Date(0);
      try {
         localSyncClient.getMachineID();
         Document doc = localContentClient.getContent("/system/SysConfig/sync" + src_host + ".xml").getDocument();
         Element e = doc.getDocumentElement();
         lastSyncDate = new Variant(e.getAttribute("date")).getDate();
      }
      catch ( Exception e ) {
         // Document doesn't exist I guess
         //out.println(e.getMessage());
      }

      try {
         // Do Stuff
         Manifest mf;
         if ( groups != null )
            mf = sourceSyncClient.listGroupChanges(lastSyncDate, (String[])groups.toArray(EmptyStrings));
         else
            mf = sourceSyncClient.listAllChanges(lastSyncDate);
         Date startTime = mf.getDate();
         String[] grps = mf.getGroupNames();
         int totalDocs = 0;
         for ( int i = 0; i < grps.length; i++ )
            totalDocs += mf.getGroupContent(grps[i]).length;

         if ( grps.length > 0 ) {
            log.add("Updating " + grps.length + " files");
            int docNum = 0;
            for ( int i = 0; !cancel && i < grps.length; i++ ) {
               currentGroup = grps[i];
               String[] files = mf.getGroupContent(currentGroup);
               log.add("Group '" + currentGroup + "' contains " + files.length + " updated files");
               for ( int j = 0; !cancel && j < files.length; j++ ) {
                  currentFile = files[j];
                  int idx = currentFile.lastIndexOf('/');
                  String colName = currentFile.substring(0, idx);
                  String docName = currentFile.substring(idx + 1);
                  Content c = mf.getContent(currentFile);

                  CollectionClient lclCol = (CollectionClient)lclColCache.get(colName);
                  if ( lclCol == null ) {
                     lclCol = localContentClient.getCollection(colName);
                     lclColCache.put(colName, lclCol);
                     if ( lclCol.getCollectionType() == CollectionClient.TYPE_DOCUMENTS )
                        lclColXML.add(colName);
                  }

                  if ( c.getStatus() != Constants.STATUS_DELETED ) {
                     CollectionClient srcCol = (CollectionClient)srcColCache.get(colName);
                     if ( srcCol == null ) {
                        srcCol = sourceContentClient.getCollection(colName);
                        srcColCache.put(colName, srcCol);
                        if ( srcCol.getCollectionType() == CollectionClient.TYPE_DOCUMENTS )
                           srcColXML.add(colName);
                     }
                     File f = File.createTempFile("dbxml_", ".sync");
                     tempFiles.put(currentFile, f);
                     if ( srcColXML.contains(colName) ) {
                        String doc = srcCol.getDocumentAsText(docName);
                        FileOutputStream fos = new FileOutputStream(f);
                        BufferedOutputStream bos = new BufferedOutputStream(fos, 4096);
                        OutputStreamWriter osw = new OutputStreamWriter(bos, "UTF8");
                        osw.write(doc);
                        osw.flush();
                        osw.close();
                     }
                     else {
                        byte[] doc = srcCol.getValue(docName);
                        FileOutputStream fos = new FileOutputStream(f);
                        fos.write(doc);
                        fos.close();
                     }
                  }
                  else
                     delList.put(currentFile, lclCol);
                  percentComplete = 100 * docNum++ / totalDocs;
               }
            }

            if ( !cancel ) {
               Iterator iter = delList.entrySet().iterator();
               while ( iter.hasNext() ) {
                  Map.Entry entry = (Map.Entry)iter.next();
                  String path = (String)entry.getKey();
                  CollectionClient col = (CollectionClient)entry.getValue();
                  int idx = path.lastIndexOf('/');
                  String docName = path.substring(idx + 1);
                  col.remove(docName);
               }

               iter = tempFiles.entrySet().iterator();
               while ( iter.hasNext() ) {
                  Map.Entry entry = (Map.Entry)iter.next();
                  String path = (String)entry.getKey();
                  File f = (File)entry.getValue();
                  int idx = path.lastIndexOf('/');
                  String colName = path.substring(0, idx);
                  String docName = path.substring(idx + 1);

                  CollectionClient lclCol = (CollectionClient)lclColCache.get(colName);
                  if ( lclCol == null ) {
                     lclCol = localContentClient.getCollection(colName);
                     lclColCache.put(colName, lclCol);
                     if ( lclCol.getCollectionType() == CollectionClient.TYPE_DOCUMENTS )
                        lclColXML.add(colName);
                  }

                  if ( lclColXML.contains(colName) ) {
                     FileInputStream fis = new FileInputStream(f);
                     BufferedInputStream bis = new BufferedInputStream(fis, 4096);
                     InputStreamReader isr = new InputStreamReader(bis, "UTF8");
                     char[] buf = new char[(int)f.length()];
                     int size = isr.read(buf);
                     isr.close();
                     lclCol.setDocumentAsText(docName, new String(buf, 0, size));
                  }
                  else {
                     FileInputStream fis = new FileInputStream(f);
                     byte[] buf = new byte[(int)f.length()];
                     fis.read(buf);
                     fis.close();
                     lclCol.setValue(docName, buf);
                  }
               }
            }
            log.add("Synchronization complete");
         }
         else
            log.add("No files are out of date");

         if ( !cancel ) {
            // Write the last sync to the Database
            Document doc = DOMHelper.newDocument();
            Element srvElem = doc.createElement("server");
            doc.appendChild(srvElem);
            srvElem.setAttribute("host", src_host);
            srvElem.setAttribute("date", new Variant(startTime).getString());
            for ( int i = 0; i < log.size(); i++ ) {
               Element logElem = doc.createElement("log");
               DOMUtils.setText(logElem, (String)log.get(i));
               srvElem.appendChild(logElem);
            }
View Full Code Here


   private void writeValue(OutputStream os, Object o) throws IOException {
      if ( o != null && o.getClass().isArray() )
         writeArray(os, o);
      else
         writeVariant(os, new Variant(o));
   }
View Full Code Here

   private void writeValue(PrintWriter pw, Object o) throws IOException {
      if ( o != null && o.getClass().isArray() )
         writeArray(pw, o);
      else
         writeVariant(pw, new Variant(o));
   }
View Full Code Here

         byte[] b = (byte[])o;
         os.write(b);
      }
      else {
         List l = ArrayConversions.toList(o);
         writeVariant(os, new Variant(l));
      }
   }
View Full Code Here

         byte[] b = (byte[])o;
         pw.write(new String(b));
      }
      else {
         List l = ArrayConversions.toList(o);
         writeVariant(pw, new Variant(l));
      }
   }
View Full Code Here

            break;

         case Types.LIST:
            Iterator l = v.getList().iterator();
            while ( l.hasNext() )
               writeVariant(pw, new Variant(l.next()));
            break;

         case Types.MAP:
            Map m = v.getMap();
            Iterator k = m.keySet().iterator();
            while ( k.hasNext() ) {
               Object key = k.next();
               pw.print(key + "=");
               writeVariant(pw, new Variant(m.get(key)));
            }
            break;

         case Types.OBJECT:
            writeValue(pw, v.getObject());
View Full Code Here

    * @throws Throwable if an invocation error occurs
    */
   public Object invoke(Object obj, String name, Object[] params) throws Throwable {
      Variant[] v = new Variant[params.length];
      for ( int i = 0; i < v.length; i++ )
         v[i] = new Variant(params[i]);
      return invoke(obj, name, v);
   }
View Full Code Here

         pw.println("<"+METHOD_RESPONSE+"><"+FAULT+">");

         Map m = new HashMap();
         m.put(FAULT_CODE, code);
         m.put(FAULT_STRING, message);
         writeVariant(pw, new Variant(m));

         pw.println("</"+FAULT+"></"+METHOD_RESPONSE+">");
         pw.flush(); // Is this needed?
         pw.close(); // Is this needed?
         response.close();
View Full Code Here

   private void writeValue(PrintWriter pw, Object o) throws IOException {
      if ( o != null && o.getClass().isArray() )
         writeArray(pw, o);
      else
         writeVariant(pw, new Variant(o));
   }
View Full Code Here

            e.printStackTrace(System.err);
         }
      }
      else {
         List l = ArrayConversions.toList(o);
         writeVariant(pw, new Variant(l));
      }
   }
View Full Code Here

TOP

Related Classes of com.dbxml.labrador.types.Variant

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.