Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Utilities

    jspocp 2007-01-24

    Download button

    No screenshots available
    Downloads: 364  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Leif Johansson | More programs
    GPL / FREE
    April 5th, 2007, 14:00 GMT
    ROOT / Utilities

     Read user reviews (0)  Refer to a friend  Subscribe

    jspocp description

    jspocp is a java-based SPOCP client.

    jspocp is a java-based SPOCP client.

    This project (jspocp) is a client for SPOCP using java. It is available using maven2 from the maven2 repository. The generated documentation contains javadoc and usage examples.

    jSPOCP Usage Example

    The following source code example is preliminary and subject to testing.

    package org.spocp.client;

    import java.util.List;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    /**
    *
    * @author alund
    */
    public class Example
    {

    private static final Log log = LogFactory.getLog(SPOCPClient.class);

    /**
    *
    * @return an instance of a connection factory used to create connections to a spocp server
    */
    public static SPOCPConnectionFactory connectionFactory(String host, int port)
    {
    SPOCPConnectionFactoryImpl cf = new SPOCPConnectionFactoryImpl();
    cf.setServer(host);
    cf.setPort(port);

    return cf;
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[])
    throws Exception
    {
    SPOCPResult result;
    String host = args[0];
    int port = Integer.parseInt(args[1]);
    SPOCPConnectionFactory cf = SPOCPClient.connectionFactory(host,port);
    SPOCPConnection c = cf.getConnection();
    log.debug(c);

    // ---- Add some rules ----
    result = c.issueCommand(new AddCommand(null,"(a (b c))"));
    if(result.getResultCode() != SPOCPResult.SPOCP_SUCCESS)
    System.err.println(result.getMessage());

    AddCommand addCmd = new AddCommand();
    addCmd.setPath("/example");
    addCmd.setSExpr("(abc def)");
    result = c.issueCommand(addCmd);
    if(result.getResultCode() != SPOCPResult.SPOCP_SUCCESS)
    System.err.println(result.getMessage());

    addCmd.setPath("/anlu0008");
    addCmd.setSExpr("(UB book (sab P u))");
    addCmd.setBoundaryCondition("NULL");
    addCmd.setReturnInfo("anlu0008@somedomain.se".getBytes());
    result = c.issueCommand(addCmd);
    if(result.getResultCode() != SPOCPResult.SPOCP_SUCCESS)
    System.err.println(result.getMessage());

    addCmd.setPath("/jolo0001");
    addCmd.setSExpr("(UB book (sab P u))");
    addCmd.setBoundaryCondition("NULL");
    addCmd.setReturnInfo("johanna.lofstrom@somedomain.se".getBytes());
    result = c.issueCommand(addCmd);
    if(result.getResultCode() != SPOCPResult.SPOCP_SUCCESS)
    System.err.println(result.getMessage());


    // Make some queries
    result = c.issueCommand(new QueryCommand(null, "(abc def ghi)"));
    if(result.getResultCode() == SPOCPResult.SPOCP_DENIED)
    System.err.println("The query did not match any rules");

    // A query that gives rise to a multi-line respons
    // because of a return information blob associated with
    // the matching rule
    result = c.issueCommand(new QueryCommand(null, "(UB book (sab P u))"));
    if(result.getResultCode() == SPOCPResult.SPOCP_SUCCESS)
    {
    List resultList = result.getResultInfoList();
    if(resultList.size() == 1)
    {
    SPOCPResultInfo ri = (SPOCPResultInfo)resultList.get(0);
    System.out.println("Return information for matching rule: " +
    new String(ri.getBlob()));
    }


    }

    // List the rules, show them and delete them
    result = c.issueCommand(new ListCommand());
    List resultList = result.getResultInfoList();
    if(resultList != null)
    {
    for(int i=0;i < resultList.size(); i++)
    {
    SPOCPResultInfo ri = (SPOCPResultInfo)resultList.get(i);
    String path = ri.getPath();
    String ruleId = ri.getRuleId();

    // In this context, we have access to everything that there
    // is to know about the listed rules through the accessor methods
    // of SPOCPResultInfo. However, for the sake of demonstration
    // we will use the show command to get information about what
    // s-expression a partiuclar rule identity is asscociated with

    ShowCommand showCmd = new ShowCommand(path, ruleId);
    SPOCPResult r = c.issueCommand(showCmd);
    SPOCPResultInfo showInfo = (SPOCPResultInfo)r.getResultInfoList().get(0);
    System.out.println("Rule id: " + ruleId + ", s-expression: " +
    showInfo.getSExpr().toString());
    c.issueCommand(new DeleteCommand(path, ruleId));
    }
    }

    c.close();
    }

    }

    Product's homepage

      


    TAGS:

    SPOCP client | Java library | SPOCP Java client | jspocp | Java | SPOCP

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM