cmisrequestimpl.java

来自「CmisJavaApi」· Java 代码 · 共 269 行

JAVA
269
字号
/* * 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, Eric Dillon, Olivier Festor *///  $Id: CMISRequestImpl.java,v 1.2 2000/09/05 14:30:39 festor Exp $//  $Source: /local/resedas/CVS-Repository/CmisJavaApi/src/fr/dyade/cmis/impl/operation/CMISRequestImpl.java,v $//---------------------------------------------------------------------------////  Todo//---------------------------------------------------------------------------//package fr.dyade.cmis.impl.operation;import java.util.*;import fr.dyade.cmis.api.CMISStack;import fr.dyade.cmis.api.CMISException;import fr.dyade.cmis.api.operation.*;import fr.dyade.cmis.api.operation.event.CMISServiceRequestListener;import fr.dyade.cmis.api.types.InvokeId;import fr.dyade.cmis.util.TraceManager;import fr.dyade.cmis.impl.*;/** Basic implementation of an a CMIS request.  * This class provides a basic implementation for a CMIS request.   * This class mainly implements the {@link fr.dyade.cmis.api.operation.CMISRequest} interface.  * It is an abstract class because it does not implement any real cmis service.      * We provides a "class tag" (short) facility to make easier the dispatching process.  * Remark: ok, this is UGLY, as java is oo and implements polymorphism.  * But just in case!  * @version cvs $Id: CMISRequestImpl.java,v 1.2 2000/09/05 14:30:39 festor Exp $  */public abstract class CMISRequestImpl implements CMISRequest {      // tag value      public static final short ACTION_REQUEST=41;      public static final short CANCEL_GET_REQUEST=42;      public static final short CREATE_REQUEST=43;      public static final short DELETE_REQUEST=44;      public static final short EVENT_REPORT_REQUEST=45;      public static final short GET_REQUEST=46;      public static final short SET_REQUEST=47;      // request state      private static final short IDLE=0;      private static final short PROCESSING=1;      /** Basic constructor.		*/      protected CMISRequestImpl( CMISStackImpl pStack, short pTag )  {	 super();	 fStack = pStack;	 fTag=pTag;	 fIsCompleted = false;      }      public final CMISStack getStack() {	 return fStack;      }      public final short getTag() {	 return fTag;      }      /**	* Set the invoke identifier for this CMISRequest	* @param pIId The InvokeId object for the invoke identifier	*/      public final void setInvokeId(InvokeId pIId) { 	 fInvokeId = pIId;      }        /**	* Get the invoke identifier of this CMISRequest	* @result the InvokeId object of the CMISRequest	*/      public final InvokeId getInvokeId()  { 	 return fInvokeId;      }            /** Number of received replies.	  Implementation of the CMISRequest interface	  <tt>getRepliesCount</tt> method.	  @return the number of replies (resp/conf) already associated to the operation.	  @see fr.dyade.cmis.api.operation.CMISRequest#getRepliesCount       */      public final int getRepliesCount() {	 return fHasReplies.size();      }        public final Enumeration getReplies() {	 return fHasReplies.elements();      }      public final boolean hasError() {	 for (Enumeration e=fHasReplies.elements(); e.hasMoreElements(); ) {	    CMISConfirmation c=(CMISConfirmation)e.nextElement();	    if ((c.getCMISError()!=null) || (c.getInternalError()!=null)) {	       return true;	    }	 }	 return false;      }      /** Errors raised for an operation.	* Implementation of the CMISRequest interface's	*<code>{@link fr.dyade.cmis.api.operation.CMISRequest#getError}</code> method.	*/      public final synchronized fr.dyade.cmis.api.types.CMISError getError()  {	 Enumeration i =  fHasReplies.elements();	 while (i.hasMoreElements()){	    CMISConfirmation r = (CMISConfirmation)i.nextElement();	    fr.dyade.cmis.api.types.CMISError  e= r.getCMISError();	    if (e!=null){	       return e;	    }	 }	 return null;      }        /** Set request's internal state to PROCESSING & (re) init internal variables	*/      synchronized protected final void startProcessing() throws CMISException {	 if (fState!=IDLE) {	    throw new CMISException("request is not IDLE");	 }	 fState=PROCESSING;	 fIsCompleted=false;	 fHasReplies.removeAllElements();	 return;      }            synchronized protected final void ensureIdle() throws CMISException {	 if (fState!=IDLE) {	    throw new CMISException("request is not IDLE");	 }	 return;      }      /** Set request's internal state to IDLE	*/      synchronized protected final void endProcessing() {	 if (fState!=PROCESSING) {	    TraceManager.debugln(getClass().getName() + ".stopProcessing not PROCESSING");	 }	 fState=IDLE;	 fIsCompleted=true;	 notifyAll();	 return;      }      synchronized public final boolean isIdle() {	 return fState==IDLE;      }            synchronized public final void waitForIdle() {	 try {	    while (fState!=IDLE) {wait();}	 } catch (InterruptedException e) {}	 return;      }      /** Completion state of the operation.	  Implementation of the CMISRequest interface  <tt>isCompleted</tt> method.      */      public final boolean isCompleted() {	 return fIsCompleted;      }            /** Sets the operation as completed.	  Implementation of the CMISRequest interface <tt>complete</tt> method. 	  TODO: declare this method as protected or package.	  @see fr.dyade.cmis.api.operation.CMISRequest#complete      */      public final void complete()  {	 fIsCompleted = true;      }        /** Adds a confirmation to the request.	* Implementation of the CMISRequest interface	* <code>addReplie</code> method. 	*  @see fr.dyade.cmis.api.operation.CMISRequest#addConfirmation	*/      public final void addConfirmation( CMISConfirmation pConfirmation )  {	 synchronized(fHasReplies) {	    fHasReplies.addElement(pConfirmation);	 }      }         /**  Verification of operation request parameters.	   This implementation of the 	   <a href="cmis.operation.CMISRequest#isReqValid">isReqValid</a> method	   of the <tt>CMISRequest</tt> interface is provided to allow user to	   implemented a bottom-up implementation of it into sub-class (use of	   <tt>super</tt> reference).	   	   @return true if the invoke identifier is setted (setInvokeId method)      */	      public boolean isReqValid()  {	 return fInvokeId != null;      }      /**	* Actual call thru actual stack.	* Not for public use. This method is be implemented by actual	* "stack", i.e jni C mapping to vendor's CMIS interface .	* @return the invoke id allocated by the stack, meaningfull only for confirmed call.	*/      protected abstract int nativeDoIt() throws CMISException;       /**	* Add a CMISEventListener to the list of this CMIS request	*/      protected final void addCMISListener(CMISServiceRequestListener pCel) {	 synchronized(fCMISEventListener) {	    if (!fCMISEventListener.contains(pCel)) {	       fCMISEventListener.addElement(pCel);	    }	 }      }      /**	* Delete a CMISEventListener to the list of this CMIS call	*/      protected final void removeCMISListener(CMISServiceRequestListener pCel) {	 synchronized(fCMISEventListener) {	    fCMISEventListener.removeElement(pCel);	 }      }      protected Vector fCMISEventListener= new Vector();        /** Completion state.	  True means that the operation completed.      */      protected boolean	fIsCompleted;            /** Request internal state	*/      private short fState=IDLE;            /** Received replies for a performing/performed confirmed request.	* Implementation of <i>OperationConfirmationRelation</i>, <i>hasReplies</i> role.	* Implemented by a Vector sequence. This may be tuned according to	* average usage of this container.	* @see fr.dyade.cmis.api.operation.CMISRequest#addConfirmation	*/      protected InvokeId fInvokeId = null;      //Remark: vector IS SYNCHRONIZED      protected Vector fHasReplies = new Vector() ;            // for use from the JNI or implementation.      protected CMISStackImpl fStack;      private short fTag;}

⌨️ 快捷键说明

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