Jini Print Service Tutorial -- Lesson 1. The Very Basics

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    import java.rmi.RemoteException;
    import javax.print.exception.PrintException;
    import net.jini.core.lookup.ServiceRegistrar;
    import net.jini.core.lookup.ServiceTemplate;
    import net.jini.print.job.PrintRequest;
    import net.jini.print.service.PrintService;
    import org.jpwg.jini.print.data.StringDoc;
    . . .
    try
        {
        StringDoc theDoc = new StringDoc ("Hello, world!", null);
        ServiceRegistrar theJLUS = // Obtain a Jini Lookup Service (JLUS) proxy
        ServiceTemplate theServiceTemplate =
            new ServiceTemplate
                (null,
                 new Class[] {PrintService.class},
                 null);
        PrintService thePrintService =
            (PrintService) theJLUS.lookup (theServiceTemplate);
        if (thePrintService != null)
            {
            PrintRequest thePrintRequest =
                thePrintService.createDocPrintRequest (theDoc, null);
            thePrintRequest.print();
            }
        else
            {
            // This code executed if the JLUS couldn't find any print services
            }
        }
    catch (PrintException exc)
        {
        // This code executed if a printing error occurred
        // Thrown by any of the above
        }
    catch (RemoteException exc)
        {
        // This code executed if a remote error occurred
        // Thrown by any of the above
        }