All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xins.server.frontend.ControlResult Maven / Gradle / Ivy

There is a newer version: 3.0
Show newest version
/*
 * $Id: ControlResult.java,v 1.9 2007/09/18 08:45:08 agoubard Exp $
 *
 * Copyright 2003-2007 Orange Nederland Breedband B.V.
 * See the COPYRIGHT file for redistribution and use restrictions.
 */
package org.xins.server.frontend;

import java.util.Iterator;
import java.util.Map;

import org.xins.common.collections.PropertyReader;
import org.xins.common.text.DateConverter;
import org.xins.common.xml.ElementBuilder;
import org.xins.common.spec.FunctionSpec;
import org.xins.common.spec.InvalidSpecificationException;

import org.xins.server.API;
import org.xins.server.FunctionResult;
import org.xins.server.Log;

/**
 * Result for the Control command.
 *
 * @version $Revision: 1.9 $ $Date: 2007/09/18 08:45:08 $
 * @author Anthony Goubard
 */
class ControlResult extends FunctionResult {

   /**
    * Creates the result for the Control command.
    *
    * @param api
    *    the API, cannot be null.
    *
    * @param sessionManager
    *    the sessionManager, cannot be null.
    *
    * @param redirectionMap
    *    the redirection map, cannot be null.
    */
   ControlResult(API api, SessionManager sessionManager, Map redirectionMap) {

      // The versions
      param("xinsCommonVersion", org.xins.common.Library.getVersion());
      param("xinsServerVersion", org.xins.server.Library.getVersion());
      param("apiName", api.getName());
      param("apiStartUpTime", DateConverter.toDateString(api.getStartupTimestamp()));

      // Some bootstrap properties
      PropertyReader bootstrapProps = api.getBootstrapProperties();
      param("apiVersion", bootstrapProps.get("org.xins.api.version"));
      param("apiBuildVersion", bootstrapProps.get("org.xins.api.build.version"));
      param("apiBuildTime", bootstrapProps.get("org.xins.api.build.time"));

      // The commands
      try {
         Map functions = api.getAPISpecification().getFunctions();
         Iterator itFunctions = functions.entrySet().iterator();
         while (itFunctions.hasNext()) {
            Map.Entry nextFunction = (Map.Entry) itFunctions.next();
            FunctionSpec functionSpec = (FunctionSpec) nextFunction.getValue();
            ElementBuilder builder = new ElementBuilder("command");
            builder.setAttribute("name", (String) nextFunction.getKey());
            builder.setAttribute("description", functionSpec.getDescription());
            add(builder.createElement());
         }
      } catch (InvalidSpecificationException isex) {
         Log.log_3705(isex.getMessage());
      }
      Iterator itVirtualFunctions = redirectionMap.keySet().iterator();
      while (itVirtualFunctions.hasNext()) {
         String nextFunction = (String) itVirtualFunctions.next();
         ElementBuilder builder = new ElementBuilder("command");
         builder.setAttribute("name", nextFunction);
         add(builder.createElement());
      }

      // The sessions
      ElementBuilder builder = new ElementBuilder("sessionproperties");
      Map sessionProperties = sessionManager.getProperties();
      Iterator itSessions = sessionProperties.entrySet().iterator();
      while (itSessions.hasNext()) {
         Map.Entry nextSession = (Map.Entry) itSessions.next();
         String nextKey = (String) nextSession.getKey();
         Object nextValue = nextSession.getValue();
         ElementBuilder builder2 = new ElementBuilder("property");
         builder2.setAttribute("name", nextKey);
         builder2.setText(nextValue.toString());
         builder.addChild(builder2.createElement());
      }
      add(builder.createElement());
   }

   /**
    * Return the XSLT to use to display the data of the Control command.
    *
    * @return
    *    the XSLT to display the Control result, never null.
    */
   static String getControlTemplate() {
      String result = "\n" +
          "\n" +
          "\n" +
          "\n" +
          "\n" +
            "\n" +
              "

\n" + "\n" + " Application\n" + "

\n" + "

Versions

\n" + "API: \n" + "\n" + "
\n" + "XINS server: \n" + "\n" + "
\n" + "XINS common: \n" + "\n" + "
\n" + "XINS build version: \n" + "\n" + "
\n" + "XINS build time: \n" + "\n" + "
\n" + "API start-up time: \n" + "\n" + "
\n" + "

Functions

\n" + "\n" + " 1\">\n" + ", \n" + "\n" + "\n" + "\n" + "\n" + "\n" + "

Session properties

\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
KeyValue
\n" + "\n" + "\n" + "\n" + "
\n" + "

Actions

\n" + "

Command template cache management:\n" + "Flush\n" + "Refresh\n" + "

\n" + "

Session properties management:\n" + "Remove all Session Properties\n" + "

\n" + "

XINS meta functions: \n" + "Version,\n" + "Statistics,\n" + "Settings\n" + "

\n" + "\n" + "\n" + "
\n" + "
"; return result; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy