📄 requestctxobject.java
字号:
/*
* RequestCtxObject.java
*
* Created on 04 September 2006, 13:43
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package uk.ac.kent.dpa.coord.clients;
import org.w3c.dom.*;
import java.util.ArrayList;
/**
*
* @author ls97
*/
public class RequestCtxObject {
Element requestCtx;
/** Creates a new instance of RequestCtxObject */
public RequestCtxObject(Element request) {
this.requestCtx=request;
}
public String getMethod()throws ClientException {
NodeList list = this.requestCtx.getChildNodes();
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (Text.class.isAssignableFrom(node.getClass())) continue;
if (node.getNodeName().equals("Method")) {
return ((Element)node).getAttribute("name");
}
}
return null;
}
public String getType()throws ClientException {
NodeList list = this.requestCtx.getChildNodes();
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (Text.class.isAssignableFrom(node.getClass())) continue;
if (node.getNodeName().equals("Method")) {
return ((Element)node).getAttribute("type");
}
}
return null;
}
public String getService()throws ClientException {
return this.requestCtx.getAttribute("service");
}
public String[] getParameterNames() throws ClientException {
ArrayList arr = new ArrayList();
NodeList list = this.requestCtx.getChildNodes();
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (Text.class.isAssignableFrom(node.getClass())) continue;
if (node.getNodeName().equals("Method")) {
NodeList list1 = node.getChildNodes();
for (int j=0; j<list1.getLength(); j++) {
Node node1 = list1.item(j);
if (Text.class.isAssignableFrom(node1.getClass())) continue;
if (node1.getNodeName().equals("Parameter")) {
Element ele = (Element)node1;
String name = ele.getAttribute("name");
arr.add(name);
}
}
}
}
String [] res = new String[arr.size()];
res = (String[])arr.toArray(res);
return res;
}
public String getParameterType(String name) throws ClientException {
NodeList list = this.requestCtx.getChildNodes();
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (Text.class.isAssignableFrom(node.getClass())) continue;
if (node.getNodeName().equals("Method")) {
NodeList list1 = node.getChildNodes();
for (int j=0; j<list1.getLength(); j++) {
Node node1 = list1.item(j);
if (Text.class.isAssignableFrom(node1.getClass())) continue;
if (node1.getNodeName().equals("Parameter")) {
Element ele = (Element)node1;
if (ele.getAttribute("name").equals(name)) {
return ele.getAttribute("type");
}
}
}
}
}
return null;
}
public Object getParameter(String name) throws ClientException {
NodeList list = this.requestCtx.getChildNodes();
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (Text.class.isAssignableFrom(node.getClass())) continue;
if (node.getNodeName().equals("Method")) {
NodeList list1 = node.getChildNodes();
for (int j=0; j<list1.getLength(); j++) {
Node node1 = list1.item(j);
if (Text.class.isAssignableFrom(node1.getClass())) continue;
if (node1.getNodeName().equals("Parameter")) {
Element ele = (Element)node1;
if (ele.getAttribute("name").equals(name)) {
String type = ele.getAttribute("type");
if (type.equals("integer")) {
NodeList list2 = node1.getChildNodes();
for (int k=0; k<list2.getLength(); k++) {
Node node2 = list2.item(k);
if (Text.class.isAssignableFrom(node2.getClass())) continue;
if (node2.getNodeName().equals("Value")) {
NodeList list3 = node2.getChildNodes();
for (int l=0; l<list3.getLength(); l++) {
Node node3 = list3.item(l);
if (Text.class.isAssignableFrom(node3.getClass())) {
return new Integer(node3.getNodeValue());
} else throw new ClientException("invalid request context");
}
}
}
} else if (type.equals("float")) {
NodeList list2 = node1.getChildNodes();
for (int k=0; k<list2.getLength(); k++) {
Node node2 = list2.item(k);
if (Text.class.isAssignableFrom(node2.getClass())) continue;
if (node2.getNodeName().equals("Values")) {
NodeList list3 = node2.getChildNodes();
for (int l=0; l<list3.getLength(); l++) {
Node node3 = list3.item(l);
if (Text.class.isAssignableFrom(node3.getClass())) {
return new Float(node3.getNodeValue());
} else throw new ClientException("invalid request context");
}
}
}
} else if (type.equals("string")) {
NodeList list2 = node1.getChildNodes();
for (int k=0; k<list2.getLength(); k++) {
Node node2 = list2.item(k);
if (Text.class.isAssignableFrom(node2.getClass())) continue;
if (node2.getNodeName().equals("Values")) {
NodeList list3 = node2.getChildNodes();
for (int l=0; l<list3.getLength(); l++) {
Node node3 = list3.item(l);
if (Text.class.isAssignableFrom(node3.getClass())) {
return new String(node3.getNodeValue());
} else throw new ClientException("invalid request context");
}
}
}
} else throw new ClientException("invalid parameter type");
}
}
}
}
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -