comments
[vamsas.git] / src / org / vamsas / test / simpleclient / ArchiveReports.java
1 package org.vamsas.test.simpleclient;
2
3 import java.io.InputStream;
4
5 import org.vamsas.client.simpleclient.VamsasArchiveReader;
6 import org.vamsas.objects.core.ApplicationData;
7 import org.vamsas.objects.core.VAMSAS;
8 import org.vamsas.objects.core.VamsasDocument;
9
10 public class ArchiveReports {
11     /**
12      * print an informative summary on a VamsasDocument
13      * @param document - the document itself
14      * @param archive - document source archive for resolving any appData refs
15      * @return
16      */
17   public static boolean reportDocument(VamsasDocument document, VamsasArchiveReader archive) {
18     if (document!=null) {
19       System.out.print("Vamsas Document version '"+document.getVersion()+"'");
20       System.out.print("Document contains "+document.getVAMSASCount()+" VAMSAS Elements and "+document.getApplicationDataCount()+" elements.\n");
21       if (document.getApplicationDataCount()>0) {
22         System.out.print("There are "+document.getApplicationDataCount()+" ApplicationData references.\n");
23         ApplicationData appd[] = document.getApplicationData();
24         for (int i=0,j=appd.length; i<j; i++) {
25           System.out.print("Application "+i+": '"+appd[i].getName()+"'\nVersion '"+appd[i].getVersion()+"'\nURN: '"+appd[i].getUrn()+"'\n");
26           System.out.print("AppData is ");
27           if (appd[i].getAppDataChoice().getDataReference()!=null) {
28             String appData=appd[i].getAppDataChoice().getDataReference();
29             if (appData.length()>1) {
30               System.out.print("a reference ("+appData+")");
31               InputStream jstrm;
32               if ((jstrm=archive.getAppdataStream(appData))!=null)
33                 System.out.println(" which resolves to a JarEntry.");
34               else {
35                 System.out.println(" which does not resolve to a JarEntry.");
36                 System.err.println("Unresolved appdata reference '"+appData+"'");
37               }
38             } else {
39               System.out.println("an empty reference.");
40             }
41           } else {
42             System.out.println("an embedded chunk of "+appd[i].getAppDataChoice().getData().length+" bytes.");
43           }
44         }
45           
46       }
47       return true;
48     } else {
49       System.out.print("Document Object is null");
50     }
51     return false;
52   }
53
54   /**
55    * summarises all the datasets in a vamsas document.
56    * @param roots
57    * @return
58    */
59   public static boolean rootReport(VAMSAS[] roots) {
60     if (roots!=null) {
61       for (int i=0; i<roots.length; i++) {
62         VAMSAS r = roots[i];
63         System.out.print("Vamsas Root "+i+" (id="
64             +((r.getId()!=null) ? r.getId():"<none>")
65             +") contains "+r.getDataSetCount()+" DataSets, "
66             + r.getTreeCount()+" Global trees");
67       }
68       return true;
69     }
70     return false;
71   }
72
73 }