X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Forg%2Fbiojava%2Fdasobert%2Fdas%2FDAS_Feature_Handler.java;h=105388eb323354e74df6dbc8df7cef81cfdca60c;hb=714ad67911cdd8e2078cd3e961b5d709f5f0e5ce;hp=88eb57d8e861767c71497c86479d3361d0699457;hpb=4891120c866fcd3516b270915d0db2d31a4815e0;p=jalview.git diff --git a/src/org/biojava/dasobert/das/DAS_Feature_Handler.java b/src/org/biojava/dasobert/das/DAS_Feature_Handler.java index 88eb57d..105388e 100755 --- a/src/org/biojava/dasobert/das/DAS_Feature_Handler.java +++ b/src/org/biojava/dasobert/das/DAS_Feature_Handler.java @@ -48,7 +48,9 @@ public class DAS_Feature_Handler extends DefaultHandler{ String dasCommand ; int comeBackLater ; - + + int maxFeatures ; + public DAS_Feature_Handler() { super(); @@ -58,6 +60,21 @@ public class DAS_Feature_Handler extends DefaultHandler{ characterdata = ""; dasCommand = "" ; comeBackLater = -1; + maxFeatures = -1; + } + + /** specifies a maximum number of features to be downloaded. if a + server returns more, they will be ignored. default is to load + all features + @param max the maximium number of features to be downloaded + */ + + public void setMaxFeatures(int max) { + maxFeatures = max; + } + + public int getMaxFeatures() { + return maxFeatures; } public void setDASCommand(String cmd) { dasCommand = cmd ;} @@ -72,6 +89,11 @@ public class DAS_Feature_Handler extends DefaultHandler{ } void start_feature(String uri, String name, String qName, Attributes atts) { + + if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) { + characterdata = ""; + return; + } feature = new HashMap() ; String id = atts.getValue("id"); feature.put("id",id); @@ -83,6 +105,11 @@ public class DAS_Feature_Handler extends DefaultHandler{ //System.out.println("featurefield "+featurefield+ " data "+characterdata); // NOTE can have multiple lines .. + if (( maxFeatures > 0 ) && ( features.size() > maxFeatures ) ) { + return; + } + + String data = (String)feature.get(featurefield); if (data != null){ characterdata = data + " " + characterdata; @@ -122,16 +149,12 @@ public class DAS_Feature_Handler extends DefaultHandler{ } public void startDocument() { - //System.out.println("start document"); } - public void endDocument () { - //System.out.println("adding feature " + feature); - //features.add(feature); - + public void endDocument () { } public void endElement(String uri, String name, String qName) { - //System.out.println("end "+name); + if ( qName.equals("METHOD") || qName.equals("TYPE") || qName.equals("START") || @@ -143,13 +166,20 @@ public class DAS_Feature_Handler extends DefaultHandler{ add_featuredata(uri,name,qName); } else if ( qName.equals("FEATURE")) { - //System.out.println("adding ffeature " + feature); - features.add(feature); + + if ( maxFeatures > 0 ) { + if ( features.size() < maxFeatures ) { + features.add(feature); + } + } else { + // no restriction + features.add(feature); + } } } public void characters (char ch[], int start, int length){ - //System.out.println("characters"); + for (int i = start; i < start + length; i++) { characterdata += ch[i];