📄 manager.java
字号:
/* * The contents of this file are subject to the Dyade Public License, * as defined by the file DYADE_PUBLIC_LICENSE.TXT * * You may not use this file except in compliance with the License. You may * obtain a copy of the License on the Dyade web site (www.dyade.fr) or * in the root directory of this distribution. * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific terms governing rights and limitations under the License. * * The Original Code is CmisJava API, including the java package * fr.dyade.cmis, released September 5, 2000. * * The Initial Developer of the Original Code is Dyade. The Original Code and * portions created by Dyade are Copyright Bull and Copyright INRIA. * All Rights Reserved. *//* Copyright 1996-2000 by Institut National de Recherche en Informatique * et en Automatique (INRIA) * All rights reserved. See COPYRIGHT in top-level directory. * * Authors: Laurent Andrey, Olivier Festor */package fr.dyade.cmis.examples;import java.io.*;import java.util.*;import fr.dyade.cmis.api.CMISManagerStack;import fr.dyade.cmis.api.CMISException;import fr.dyade.cmis.api.BadStackRoleException;import fr.dyade.cmis.api.types.*;import fr.dyade.cmis.api.operation.*;import fr.dyade.cmis.api.operation.event.*;import java.util.Enumeration;// coj util & basic implementationimport fr.dyade.cmis.util.TraceManager;// RMI stack related packagesimport fr.dyade.cmis.rmi.*;import fr.dyade.cmis.rmi.operation.*;import fr.dyade.cmis.rmi.types.*;public class Manager { /** Default constructor * instanciates the stack as well as basic OIDs and values used throughout the tests */ public Manager() { try { theStack = new RMIStack("CmisJavaApiSamplePrintServiceAgent"); ((RMIStack) theStack).bind(); } catch (Exception ef) { System.out.println("Error during Agent Bind"); System.out.println(ef); }; oid = new ObjectIdentifier("1.512.1"); oid1 = new ObjectIdentifier("1.512.1.1"); ASN1Integer pValue = new ASN1Integer(1); // construction de l'AVA Ava ava = new Ava(oid1,pValue); Ava avaTable[] = new Ava[1]; avaTable[0] = ava; // Construction du DN RelativeDistinguishedName RDN = new RelativeDistinguishedName(); RDN.setAvaTable(avaTable); DistinguishedName DN = new DistinguishedName(RDN); oi = new ObjectInstance(); oi.setDistinguishedName(DN); }; /** * defines se test sequence */ public void runManager() { System.out.println("The manager first associates an Event-Report Listener to the stack"); theStack.addEventReportListener(new EventReportListener() { public void perform(EventReportEvent e) { EventReportIndication ind=e.getIndication(); count++; System.out.print("Event Report ("+count+") "+ind.getMode()+" Type="+ ind.getEventType()+" info="); Any info=ind.getEventInformation(); if (info != null) System.out.println(".. : " + ((RMIAny) info).toString()); else System.out.println("empty information field"); } private int count; } ); System.out.println("The manager now performs a get request with a WHOLE_SUBTREE scope and prints the reponses on the screen"); System.out.println("<Press return key to proceed!>"); waitForKeyPressed(); getWholeSubtree(); System.out.println("We now add a new instance of a PrintJob to the agent through a create operation!"); System.out.println("<Press return to proceed!>"); waitForKeyPressed(); createPrintJob(); System.out.println("The manager performs again a get request with a WHOLE_SUBTREE scope and prints the reponses on the screen"); System.out.println("<Press return to proceed!>"); waitForKeyPressed(); getWholeSubtree(); System.out.println("8 responses should have been received after the creation of the new print job...."); System.out.println("..............."); System.out.println("Next step"); System.out.println("The manager now performs a set request to change the paper type of the last created job...."); System.out.println("<Press return to proceed!>"); waitForKeyPressed(); setPrintJobPaperType("DIN A3"); System.out.println("Now we delete all print JOB through a scoped Delete operation!"); waitForKeyPressed(); deletePrintJobs(); System.out.println("Lets check through a whole subtree Get that the print jobs are deleted on the agent"); System.out.println("<Press return to proceed!>"); waitForKeyPressed(); getWholeSubtree(); System.out.println("Lest perform a 3 second intervall polling on the printQueue"); System.out.println("<Press return to proceed!>"); waitForKeyPressed(); polledGet(); System.out.println("Trying to access a print JOB.... An event report is expected"); setPrintJobPaperType("DIN A4"); System.out.println("Thank You for using CmisJavaApi!"); try { ((RMIStack) theStack).unbind(); } catch (RMIRemoteException ex2) { System.out.println("Unbind Exception"); } catch (BadStackRoleException ex3) { System.out.println("Unbind Exception (bad stack role)"); } System.exit(0); }; public void getWholeSubtree() { GetRequest get = theStack.newGetRequest(); get.setBaseObjectClass(new ObjectClass(oid)); System.out.println(oid.toString()); get.setBaseObject(oi); get.setScope(Scope.WHOLESUBTREE); MySamplePrinterGetRequestListener theListener = new MySamplePrinterGetRequestListener(); get.addGetRequestListener(theListener); try{ get.doIt(); get.waitForIdle(); } catch (RuntimeException ex){ System.out.println(ex.getMessage()); } catch (CMISException ce){ System.out.println(ce.getMessage()); } }; public void createPrintJob() { PrintService printService = new PrintService(1); Printer printer1 = new Printer(1,printService); PrintQueue pq1 = new PrintQueue(1,3,true,true,"enabled",printService); PrintJob pj = new PrintJob(1095, new String("PDF"), new String("Letter"), 1, pq1); CreateRequest create= theStack.newCreateRequest(); create.setManagedObjectClass(pj.getManagedObjectClass()); create.setManagedObjectInstance(pj.getManagedObjectInstance()); create.setAttributeList(pj.getAttributes()); create.addCreateRequestListener(new MyCreateRequestListener()); try { create.doIt(); create.waitForIdle(); } catch (Exception e) { System.out.println("An exception occured during the create operation"); } }; public void polledGet() { PrintService printService = new PrintService(1); Printer printer1 = new Printer(1,printService); PrintQueue pq1 = new PrintQueue(1,3,true,true,"enabled",printService); GetRequest get= theStack.newGetRequest(); get.setBaseObjectClass(pq1.getManagedObjectClass()); get.setBaseObject(pq1.getManagedObjectInstance()); get.setScope(Scope.BASE_OBJECT); get.addGetRequestListener(new MySamplePrinterGetRequestListener()); int count = 1; while (count !=4) { try { get.doIt(); get.waitForIdle(); System.out.println("Wait for response and next Poll"); try { Thread.sleep(4* 1000);//polling every 4 sec. } catch (InterruptedException f) {}; } catch (Exception e) { System.out.println("An exception occured during the et operation"); } count++; } }; public void setPrintJobPaperType(String pType) { PrintService printService = new PrintService(1); Printer printer1 = new Printer(1,printService); PrintQueue pq1 = new PrintQueue(1,3,true,true,"enabled",printService); PrintJob pj = new PrintJob(1095, new String("PDF"), pType, 1, pq1); SetRequest set= theStack.newSetRequest(); set.setBaseObjectClass(pj.getManagedObjectClass()); set.setBaseObject(pj.getManagedObjectInstance()); set.setMode(Mode.CONFIRMED); set.setScope(Scope.BASE_OBJECT); ModificationAttributeList aml=new ModificationAttributeList(ModificationAttribute.REPLACE(new AttributeId("1.512.4.1.3"), new OctetString(pType))); set.setModificationList(aml); set.addSetRequestListener(new MySetRequestListener()); try { set.doIt(); set.waitForIdle(); } catch (Exception e) { System.out.println("An exception occured during the set operation"); } }; public void deletePrintJobs() { PrintService printService = new PrintService(1); Printer printer1 = new Printer(1,printService); PrintQueue pq1 = new PrintQueue(1,3,true,true,"enabled",printService); DeleteRequest del= theStack.newDeleteRequest(); del.setBaseObjectClass(pq1.getManagedObjectClass()); del.setBaseObject(pq1.getManagedObjectInstance()); del.setScope(Scope.FIRSTLEVELONLY); del.addDeleteRequestListener(new MyDeleteRequestListener()); try { del.doIt(); del.waitForIdle(); } catch (Exception e) { System.out.println("An exception occured during the delete operation"); } }; public void waitForKeyPressed() { try { BufferedReader Stdin = new BufferedReader(new InputStreamReader(System.in)); int key = Stdin.read(); } catch (IOException e) {} } private CMISManagerStack theStack; // Base class OID private ObjectIdentifier oid; // Base class Naming Attribute OID private ObjectIdentifier oid1; private ObjectInstance oi;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -