📄 datasources.java
字号:
/* * Copyright 2006 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * See use restrictions at /arcgis/java/samples/userestrictions. */package com.esri.arcgis.demo;import com.esri.adf.web.ags.data.AGSLocalConnection;import com.esri.adf.web.ags.data.AGSUser;import com.esri.aims.mtier.io.ConnectionProxy;import com.esri.aims.mtier.model.service.Services;import com.esri.arcgis.server.IEnumServerObjectConfigurationInfo;import com.esri.arcgis.server.IEnumServerObjectConfigurationInfoProxy;import com.esri.arcgis.server.IServerObjectConfigurationInfo;import com.esri.arcgis.server.IServerObjectManager;import com.esri.arcgisws.ServiceCatalogBindingStub;import com.esri.arcgisws.ServiceDescription;import java.net.URL;import java.util.ArrayList;import java.util.List;public class Datasources { private static String message=""; public Datasources() { } public String[] getAimsServices(String host, int port, String username, String password) { String[] aimsServices; int svcCount=0; try { setMessage(""); ConnectionProxy connection = new ConnectionProxy(); Services svc = new Services(); if (username != null) connection.setUsername(username); if (password != null) connection.setPassword(password); if (host != null && !host.toLowerCase().startsWith("http")) { svc.getServices(host, port,username,password); } else if (host != null && host.toLowerCase().startsWith("http")) { URL url = new URL(host); svc.getServices(url, username,password); }else{ setMessage("Invalid connection parameters."); } for (int i=0; i<svc.getServicesCount(); i++) { if (svc.getService(i).getType().equalsIgnoreCase("imageServer") || svc.getService(i).getType().equalsIgnoreCase("ArcMapServer")){ svcCount++; } } if (svcCount == 0) setMessage("No service available."); aimsServices = new String[svcCount]; int m=0; for (int j=0; j<svc.getServicesCount(); j++) { if (svc.getService(j).getType().equalsIgnoreCase("imageServer") || svc.getService(j).getType().equalsIgnoreCase("ArcMapServer")) { aimsServices[m] = svc.getService(j).getName(); m++; } } return aimsServices; } catch(Exception e) { setMessage("Invalid connection parameters"); e.printStackTrace(); return null; } } public String[] getAgsServices(String server, String domain, String username, String password) { AGSLocalConnection ags = null; List host = new ArrayList(); host.add(server); setMessage(""); String[] agsServices; try { AGSUser agsUser = new AGSUser(domain, username,password, false ); ags = new AGSLocalConnection("", host, "", "none",agsUser); ags.initResource(); IServerObjectManager mgr = ags.getServerObjectManager(); IEnumServerObjectConfigurationInfo SOCollection = new IEnumServerObjectConfigurationInfoProxy(mgr.getConfigurationInfos()); agsServices = new String[SOCollection.getCount()]; //agsServices[0] = "-- Select a Service --"; if (agsServices.length == 0) setMessage("No services available"); for (int j=0; j<SOCollection.getCount(); j++) { IServerObjectConfigurationInfo srvObj = SOCollection.next(); System.out.println(srvObj.getName()); agsServices[j] = srvObj.getName(); } return agsServices; } catch (Exception e) { setMessage("Invalid connection parameters."); e.printStackTrace(); return null; } finally{ if(ags != null) ags.passivateResource(); } //return null; } public String[] getAgsWebURLs(String catalogURL){ int svcCount=0; try { URL url = new URL(catalogURL); ServiceCatalogBindingStub servicecatalog = new ServiceCatalogBindingStub(url, null); ServiceDescription sd[] = servicecatalog.getServiceDescriptions(); for (int i=0; i<sd.length; i++) { if (sd[i].getType().equalsIgnoreCase("MapServer")) { svcCount++; } } if (svcCount == 0) setMessage("No service available."); String[] agswsServices = new String[svcCount]; int m=0; for (int i = 0; i < sd.length; i++) { if ( sd[i].getType().equalsIgnoreCase("MapServer") ) { agswsServices[m] = sd[i].getUrl(); m++; } } return agswsServices; } catch(Exception e) { setMessage("Invalid connection parameters."); e.printStackTrace(); return null; } } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -