⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sampleprintserviceagent.java

📁 CmisJavaApi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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). * * 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 *///---------------------------------------------------------------------------////  CVS Info//---------------------------------------------------------------------------//////  $Id: SamplePrintServiceAgent.java,v 1.4 2000/09/05 15:29:15 festor Exp $////---------------------------------------------------------------------------////  Todo//---------------------------------------------------------------------------////package fr.dyade.cmis.examples;import java.util.Enumeration;import java.util.Vector;// coj utilitiesimport fr.dyade.cmis.util.TraceManager;import fr.dyade.cmis.util.getopt.*;//coj API related packagesimport fr.dyade.cmis.api.CMISException;import fr.dyade.cmis.api.CMISAgentStack;import fr.dyade.cmis.api.types.*;import fr.dyade.cmis.api.operation.*;import fr.dyade.cmis.api.operation.event.*;// basic impl utilitiesimport fr.dyade.cmis.impl.InternalErrorListenerBasicImpl;import fr.dyade.cmis.impl.ErrorHandlerBasicImpl;//coj over RMI implementationimport fr.dyade.cmis.rmi.*;import fr.dyade.cmis.rmi.types.RMIAny;// agents mitimport fr.dyade.cmis.agents.mit.*;/** The print service listener associated to the Get Operation * */class SamplePrintServiceGetListener implements GetListener {    public ManagedObjectTree mib;    public SamplePrintServiceGetListener(ManagedObjectTree pMib)    {	super();	mib = pMib;    }    public void perform( GetEvent evt )    {	// getting the stack (association from which the indication has been received	CMISAgentStack st=evt.getStack();	// getting the indication	GetIndication ind=evt.getIndication();	// collecting usefull parameters	 ObjectClass baseObjectClass  = ind.getBaseObjectClass();	 ObjectInstance baseObjectInstance  = ind.getBaseObjectInstance();	 // informing the external user	 System.out.println("A Get indication has been received...");	 System.out.println(ind.toString());	 // telling if more than one object has been selected	 boolean many = false;	 // bulding a new invoke Id if several objects are to be returned	 int id = ind.getInvokeId().getInvokeId()*2;	 // selecting affected objects and building responses	 try	     {		 // getting all selected objects		 Enumeration en = mib.getManagedObjects(baseObjectInstance,ind.getScope(),null);	 // for each managed object, we build a CMIS Get Response	 for (Enumeration enum = en; enum.hasMoreElements() ;)	     {		 ManagedObjectInterface mo = (ManagedObjectInterface) enum.nextElement();		 GetResponse rsp= st.newGetResponse();		 rsp.setManagedObjectClass( mo.getManagedObjectClass());		 rsp.setAttributeList( mo.getAttributes());		 rsp.setManagedObjectInstance( mo.getManagedObjectInstance());		 // Assingning the invoke and linked ID		 if (enum.hasMoreElements() == true && many == false)		     {many = true;}		 if (many == true)		     {			 // there are several responses			 if (enum.hasMoreElements() == true)			     {				 // it is not the last object to be send				 rsp.setInvokeId(new InvokeId(id+1));				 rsp.setLinkedId(ind.getInvokeId());			     }			 else			     {				 // it is the last object				 rsp.setInvokeId(ind.getInvokeId());				 rsp.setLinkedId(ind.getInvokeId());			     }		     }		 else		     {			 // only one object has been selected			  rsp.setInvokeId(ind.getInvokeId());		     };		try		    {			rsp.doIt();		    }		catch (Exception e)		    {System.out.println("An exception occured during response issuance! " + e);		    }	     }	     }	 catch (NoSuchObjectInstanceException e)	     {System.out.println("The Object Instance does not exists!");}	 catch (InvalidScopeException g)	     {System.out.println("Invalid Scope!");}	 catch (InvalidFilterException h)	     {System.out.println("Invalid Filter!");};    }}class SamplePrintServiceCreateListener implements CreateListener {    public ManagedObjectTree mib;    public PrintQueue printQueue;    public SamplePrintServiceCreateListener(ManagedObjectTree pMib, PrintQueue pPrintQueue)    {	super();	mib = pMib;	printQueue = pPrintQueue;    }    public void perform( CreateEvent evt )    {	// getting the stack (association from which the indication has been received	CMISAgentStack st=evt.getStack();	// getting the indication	CreateIndication ind=evt.getIndication();	 // informing the external user	 System.out.println("A Create indication has been received...");	 System.out.println(ind.toString());	 // testing if the instance to be create is of type PrintJob	 if (ind.getManagedObjectClass().toString().equals(PrintJob.classOID) == true)	     {		 // then we add the instance		 // First we built the PrintJob Object		 try		     {			 AttributeList list = ind.getAttributeList();			 int pjId = ((ASN1Integer) list.getValue(new AttributeId("1.512.4.1.1"))).toInteger();			 String mimeTypes = ((OctetString) list.getValue(new AttributeId("1.512.4.1.2"))).toString();			 String paperTypes =((OctetString) list.getValue(new AttributeId("1.512.4.1.3"))).toString();			 int pjStatus = ((ASN1Integer) list.getValue(new AttributeId("1.512.4.1.4"))).toInteger();			 // we also need the superior object instance, thus we are looking for the PrintService			 PrintQueue ps = (PrintQueue) mib.getManagedObject(printQueue.getDN());			 PrintJob pj = new PrintJob(pjId,mimeTypes,paperTypes,pjStatus,ps);			 // now we add the new object to the MIB			 try			     {				 mib.add(((ObjectInstance)pj.getManagedObjectInstance()).getDistinguishedName(),pj);			     }			 catch (Exception e)			     {				 System.out.println("An error occured during MO insertion in the MIT : "+ e);				 // The object could not be created,				 // we must issue an invalid instance CMIS response				 // Les issue a CMIS Error				 CreateResponse resp=st.newCreateResponse();				 resp.setCMISError(CMISError.INVALID_OBJECT_INSTANCE(ind.getManagedObjectInstance()));				 resp.setInvokeId(ind.getInvokeId());				 resp.setManagedObjectClass(ind.getManagedObjectClass());				 resp.setManagedObjectInstance(ind.getManagedObjectInstance());				 resp.setAttributeList(ind.getAttributeList());				 try				     {					 resp.doIt();				     } catch (CMISException excep) {					 System.out.println(excep);				     }			     };			 // lets build the CMIS response			 CreateResponse resp=st.newCreateResponse();			 resp.setInvokeId(ind.getInvokeId());			 resp.setManagedObjectClass(ind.getManagedObjectClass());			 resp.setManagedObjectInstance(ind.getManagedObjectInstance());			 resp.setAttributeList(ind.getAttributeList());			 try			     {				 resp.doIt();			     } catch (CMISException excep) {				 System.out.println(excep);			     }		     }		 catch (Exception e)		     {		     };	     }	 else // generates a CMIS Error with invalid object instance clause	     {		 // Les issue a CMIS Error		 CreateResponse resp=st.newCreateResponse();		 resp.setCMISError(CMISError.INVALID_OBJECT_INSTANCE(ind.getManagedObjectInstance()));		 resp.setInvokeId(ind.getInvokeId());		 resp.setManagedObjectClass(ind.getManagedObjectClass());		 resp.setManagedObjectInstance(ind.getManagedObjectInstance());		 resp.setAttributeList(ind.getAttributeList());		 try		     {			 resp.doIt();		     } catch (CMISException excep) {			 System.out.println(excep);		     }	     }    }}class SamplePrintServiceSetListener implements SetListener {    public ManagedObjectTree mib;    public SamplePrintServiceSetListener(ManagedObjectTree pMib)    {	super();	mib = pMib;    }    public void perform( SetEvent evt )    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -