Das client files
[jalview.git] / src / org / biojava / dasobert / das / SpiceDasSource.java
1 /*
2  *                    BioJava development code
3  *
4  * This code may be freely distributed and modified under the
5  * terms of the GNU Lesser General Public Licence.  This should
6  * be distributed with the code.  If you do not have a copy,
7  * see:
8  *
9  *      http://www.gnu.org/copyleft/lesser.html
10  *
11  * Copyright for this code is held jointly by the individual
12  * authors.  These should be listed in @author doc comments.
13  *
14  * For more information on the BioJava project and its aims,
15  * or to join the biojava-l mailing list, visit the home page
16  * at:
17  *
18  *      http://www.biojava.org/
19  *
20  * Created on 17.10.2004
21  * @author Andreas Prlic
22  *
23  */
24
25 package org.biojava.dasobert.das ;
26
27 //import org.biojava.services.das.registry.*;
28 import org.biojava.dasobert.das.DAS_StylesheetRetrieve;
29 import org.biojava.dasobert.dasregistry.Das1Source;
30 import org.biojava.dasobert.dasregistry.DasCoordinateSystem;
31 import org.biojava.dasobert.dasregistry.DasSource;
32 import java.io.IOException                ;
33 import java.text.DateFormat               ;
34 import java.text.SimpleDateFormat         ;
35 import java.util.*;
36
37
38 import java.net.URL;
39
40 /** Manages all data about a DAS source that SPICE requires */
41 public class SpiceDasSource
42 extends Das1Source
43
44 {
45
46
47     boolean status ;
48     boolean registered ; // a flag to trace if source comes from registry or from user vonfig
49     Map[] typeStyles;
50     Map[] threeDstyles;
51     public static String DEFAULT_NICKNAME = "MyDASsource";
52     public static String DEFAULT_CAPABILITY = "features";
53     public SpiceDasSource() {
54         super();
55
56         status    = true ;  // default source is actived and used .
57         registered = true ; // default true = source comes from registry
58         setNickname(DEFAULT_NICKNAME);
59         typeStyles = null;
60         threeDstyles = null;
61         String[] caps = new String[1];
62         caps[0] = DEFAULT_CAPABILITY;
63         setCapabilities(caps);
64     }
65
66     public void loadStylesheet(){
67         DAS_StylesheetRetrieve dsr = new DAS_StylesheetRetrieve();
68         String cmd = getUrl()+"stylesheet";
69         URL url = null;
70         try {
71             url = new URL(cmd);
72         } catch (Exception e){
73             e.printStackTrace();
74             return ;
75         }
76         Map[] styles = dsr.retrieve(url);
77
78         if ( styles != null){
79             typeStyles = styles;
80         } else {
81             typeStyles = new Map[0];
82         }
83
84
85         Map[] t3dStyles = dsr.get3DStyle();
86         if ( t3dStyles != null){
87             threeDstyles = t3dStyles;
88         } else {
89             threeDstyles = new Map[0];
90         }
91     }
92
93     /** returns the Stylesheet that is provided by a DAS source.
94      * It provides info of how to draw a particular feature.
95      * returns null if not attempt has been made to load the stylesheet.
96      * afterwards it returns a Map[0] or the Map[] containing the style data.
97      *
98      * @return
99      */
100     public Map[] getStylesheet(){
101         return typeStyles;
102     }
103
104     /** get the stylesheet containing the instructions how to paint in 3D.
105      *
106      * @return
107      */
108     public Map[] get3DStylesheet(){
109         return threeDstyles;
110     }
111
112     /** a flag if this das source is active
113      * or
114      * @param flag
115      */
116     public void    setStatus(boolean flag) { status = flag ; }
117     public boolean getStatus()             { return status ; }
118
119     public void    setRegistered(boolean flag) { registered = flag ; }
120     public boolean getRegistered()             { return registered ; }
121
122
123     /** convert DasSource to SpiceDasSource */
124     public static SpiceDasSource  fromDasSource(DasSource ds) {
125         SpiceDasSource s = new SpiceDasSource();
126         s.setUrl(ds.getUrl());
127         s.setAdminemail(ds.getAdminemail());
128         s.setDescription(ds.getDescription());
129         s.setCoordinateSystem(ds.getCoordinateSystem());
130         s.setCapabilities(ds.getCapabilities());
131         s.setRegisterDate(ds.getRegisterDate());
132         s.setLeaseDate(ds.getLeaseDate());
133         s.setNickname(ds.getNickname());
134
135
136         // testcode now part of coordinate system...
137         //s.setTestCode(ds.getTestCode());
138         s.setId(ds.getId());
139         s.setLabels(ds.getLabels());
140         s.setHelperurl(ds.getHelperurl());
141         return s;
142     }
143
144
145     public String toString() {
146         String txt = getId()  + " " + getNickname() + " " + getUrl() ;
147         return txt;
148     }
149
150
151 }