<%@page import="net.jini.lookup.entry.*" %>
<%@page import="javax.print.attribute.standard.*" %>
<%@page import="javax.print.attribute.*" %>
<%@page import="javax.net.*" %>

<table>
<tbody>
<%
String orgParam = request.getParameter("organization");
serviceBean.setOrganization(orgParam);
Set watchedServices = getWatches(serviceBean);
if("watch".equals(request.getParameter("action"))) {
	String uri = request.getParameter("uri");
	if(watchedServices.contains(new URI(uri))) unwatch(uri, serviceBean);
	else watch(uri, serviceBean);
	watchedServices = getWatches(serviceBean);
}
pageContext.setAttribute("required", watchedServices);
pageContext.setAttribute("serviceItems", serviceBean.getCache().getServiceItems());

Map watched, unwatched;
watched = new TreeMap();
unwatched = new TreeMap();
Vector v = new Vector();
v.add(new Object[] {watched, "watched", "eye_open.jpeg"});
v.add(new Object[] {unwatched, "unwatched", "eye_closed.jpeg"});
pageContext.setAttribute("watches", v);
SortedSet organizations = new TreeSet();
pageContext.setAttribute("organizations", organizations);
%>
<c:forEach var="serviceItem" items="${serviceItems}">
<%
	ServiceItem item = (ServiceItem )pageContext.getAttribute("serviceItem");
        URI uri = getURI(item.attributeSets);
		String org = getOrganization(item.attributeSets);
                if(org!=null) organizations.add(org);
		
		if(orgParam==null || orgParam.length()==0 || orgParam.equals(org)) {
			ServiceID sid = item.serviceID;
			String ssid = sid.getMostSignificantBits()+"|"+sid.getLeastSignificantBits();
			if(watchedServices.remove(uri)) watched.put(uri, new Object[] {ssid,item.attributeSets});
			else if(watched.containsKey(uri)) { //select one
				try {
					serviceBean.setServiceContext(sid);
					serviceBean.setMethodName("ping");
					serviceBean.setMethodParamClasses(null);
					serviceBean.setMethodParams(null);
					serviceBean.getMethodResult();
					watched.put(uri, new Object[] {ssid,item.attributeSets});
				}
				catch(Exception e) {
					log("lookup: "+e);
				}
			}
			else unwatched.put(uri, new Object[] {ssid,item.attributeSets});
		}
%>
</c:forEach>
<%for(Iterator i=watchedServices.iterator(); i.hasNext();) watched.put(i.next(), new Object[] {null,null});%>
<tr><td colspan=3>
<form action="selector.jsp" target="_self" method="GET">
<input type=hidden name="view" value="lookup">
<font size="-1">
<a href="../" target="_top">Up</a>
|
<a href="index.html" target="_top">home</a>
|
<a href="selector.jsp?view=history" target="main">history</a>
|
<a href="selector.jsp?view=listing" target="main">export</a>
<br>
<select name="organization"><option value="">default</option>
<c:forEach items="${organizations}" var="organization">
<option value="<c:out value='${organization}'/>"
<c:if test="${organization == param.organization}">SELECTED</c:if>
><c:out value='${organization}'/></option>
</c:forEach>
</select><input type="submit" value="group">
</font>
<form>
<br>
<%=watched.size()%> watched
|
<%=watchedServices.size()%> missing
</td><td></td></tr>
<c:forEach var="watch" items="${watches}">
	<tr><td colspan=3><hr></td><td></td></tr>
	<c:forEach var="service" items="${watch[0]}">
		<c:set var="entries" value="${service.value[1]}"/>
		<%@include file="include/status_message.jsp"%>
		<c:set var="uri">selector.jsp?view=main&uri=<c:out value="${service.key}"/>&sid=<c:out value="${service.value[0]}"/></c:set>
		<tr>
				<td nowrap>
						<font size="+0"><font size="+2" color="<c:out value='${color}'/>">&bull;</font>&nbsp;
						<a href="selector.jsp?view=main&next=http&uri=http://<c:out value='${service.key.host}'/>" target="main" title="<c:out value='${errors}'/>">
								<c:forTokens items="${service.key.host}" delims="." end="0" var="host"><c:out value="${host}"/></c:forTokens>
						</a></font>
				</td>
				<td>
						<a href="<c:out value='${uri}'/>&next=monitor" target="main" title="monitor"><img src="images/monitor.gif" border=0></a>
				</td>
				<td>
						<a href="<c:out value='${uri}'/>&next=configure" target="main" title="configure"><img src="images/configure.gif" border=0></a>
				</td>
				<td>
						<a href="selector.jsp?view=lookup&action=watch&organization=<%=orgParam%>&uri=<c:out value="${service.key}"/>" target="_self" title="watch/unwatch">
                                                <img src="images/<c:out value='${watch[2]}'/>" border=0></a>
				</td>
		</tr>
	</c:forEach>
</c:forEach>
</tbody>
</table>
