View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // GenomeBrowser Project
18  //
19  // SubOperation.java
20  // Since: 2007/06/18
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.track.operation;
26  
27  import org.utgenome.gwt.utgb.client.RPCServiceManager;
28  import org.utgenome.gwt.utgb.client.track.Track;
29  import org.utgenome.gwt.utgb.client.track.lib.old.Utilities;
30  import org.utgenome.gwt.utgb.client.util.GETMethodURL;
31  
32  import com.google.gwt.user.client.rpc.AsyncCallback;
33  import com.google.gwt.user.client.ui.Widget;
34  import com.google.gwt.xml.client.Document;
35  import com.google.gwt.xml.client.Node;
36  import com.google.gwt.xml.client.NodeList;
37  import com.google.gwt.xml.client.XMLParser;
38  
39  /**
40   * @author ssksn
41   * 
42   */
43  public class SubOperation extends OperationImpl {
44  	protected final GETMethodURL url;
45  
46  	public SubOperation(final Node subOperationNode, final Track track) {
47  		super(track);
48  
49  		this.url = GETMethodURL.newInstance(Utilities.getAttributeValue(subOperationNode, "url"));
50  	}
51  
52  	public void execute(Widget sender, int x, int y) {
53  		final String fullURL = url.getURL();
54  
55  		RPCServiceManager.getRPCService().getHTTPContent(fullURL, new Command(sender, x, y));
56  	}
57  
58  	private class Command implements AsyncCallback<String> {
59  		private final Widget sender;
60  		private final int x;
61  		private final int y;
62  
63  		Command(final Widget sender, final int x, final int y) {
64  			this.sender = sender;
65  			this.x = x;
66  			this.y = y;
67  		}
68  
69  		public void onFailure(Throwable caught) {
70  		}
71  
72  		public void onSuccess(String result) {
73  			if (result.length() <= 0) {
74  				return;
75  			}
76  			{
77  				final Document dom = XMLParser.parse(result);
78  
79  				final NodeList suboperation_layerNodeList = dom.getElementsByTagName("suboperation_layer");
80  				if (suboperation_layerNodeList.getLength() != 1) {
81  					throw new AssertionError();
82  				}
83  
84  				final Node suboperation_layerNode = suboperation_layerNodeList.item(0);
85  
86  				final NodeList operationNodeList = Utilities.getTagChildNodes(suboperation_layerNode);
87  				for (int k = 0; k < operationNodeList.getLength(); k++) {
88  					final Node operationNode = operationNodeList.item(k);
89  
90  					final OperationParser parser = OperationParser.getParser();
91  					final Operation operation = parser.parseOperationNode(operationNode, track);
92  
93  					operation.execute(sender, x, y);
94  				}
95  			}
96  		}
97  
98  	}
99  
100 }