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

📄 managedobjecttree.java

📁 CmisJavaApi
💻 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 */package fr.dyade.cmis.agents.mit;import java.util.*;import fr.dyade.cmis.api.types.Ava;import fr.dyade.cmis.api.types.DistinguishedName;import fr.dyade.cmis.api.types.RelativeDistinguishedName;import fr.dyade.cmis.api.types.ObjectInstance;import fr.dyade.cmis.api.types.Scope;import fr.dyade.cmis.api.types.Filter;/** Basic implementation for a MIT.  * This structure gives support for DN interpretation, scoping, filtering.   * No assumption about MO is done.  * TODO: factories method for inner containers (oid & value level)  * @version $Id: ManagedObjectTree.java,v 1.6 2000/09/05 09:58:41 festor Exp $  */public class ManagedObjectTree {            public ManagedObjectTree() {	 super();      }      /** Add new node from existing node	* Add a node associated to one ava from a parent node.	* A former node associated to the same ava is removed from the containre	* and returned by the function.	* @param fromNode the parent node	* @param ava the key to use to insert the the new node	* @param mo the managed object the new node must keep	* @return null or previous node with same ava.	*/      public Node add(Node fromNode, Ava ava, Object mo) {	 return fromNode.addChild(ava, mo);      }      public synchronized Node get(DistinguishedName dn) throws NoSuchObjectInstanceException {	 Node current=top;	 for (Enumeration rdns=dn.getElts(); rdns.hasMoreElements(); ) {	    Ava[] lAvaTable=((RelativeDistinguishedName)rdns.nextElement()).getAvaTable();	    for (int i=0; i<lAvaTable.length; i++) {	       current=current.getChild(lAvaTable[i]);	       if (current==null) {		  throw new NoSuchObjectInstanceException();	       }	    }	 }	 return current;      }      public synchronized Node add(DistinguishedName dn, Object mo) throws DuplicatedInstanceException, NoSuchObjectInstanceException {	 Node current=top;	 for (Enumeration rdns=dn.getElts(); rdns.hasMoreElements(); ) {	    Ava[] lAvaTable=((RelativeDistinguishedName)rdns.nextElement()).getAvaTable();	    for (int i=0; i<lAvaTable.length; i++) {	       // last ava case...	       if (!rdns.hasMoreElements()&&(i==(lAvaTable.length-1))) {		  Node newNode=add(current, lAvaTable[i], mo);		  if (newNode!=null) {		     throw new DuplicatedInstanceException();		  }		  return newNode;	       } else {		  current=current.getChild(lAvaTable[i]);		  if (current==null) {		     throw new NoSuchObjectInstanceException();		  }	       }	    }	 }	 return current; // usefuless, but compiler is asking for a return...      }      public final void addp(DistinguishedName dn, Object mo) throws DuplicatedInstanceException, NoSuchObjectInstanceException {	 Node dummy=add(dn, mo);      }      public synchronized Object getManagedObject(DistinguishedName dn) throws NoSuchObjectInstanceException {	 return get(dn).getManagedObject();      }      public synchronized void remove(DistinguishedName dn) throws NoSuchObjectInstanceException {	  get(dn).remove();      }      public synchronized Enumeration getManagedObjects( ObjectInstance baseObject,							 Scope scope,							 Filter filter ) 	 throws NoSuchObjectInstanceException, InvalidScopeException, InvalidFilterException {	    DistinguishedName baseDN=baseObject.getDistinguishedName();	    // we only use global id. (DN)	    if (baseDN==null) {	       throw new NoSuchObjectInstanceException();	    }	    if (scope==null) { // default scope == baseObject	       return new BaseObjectEnumeration(get(baseDN), filter);	    }	    switch (scope.getScopeType()){	       case Scope.SCOPE_INTEGER_CODE:		  switch (scope.getScope()){		     case Scope.SCOPE_INTEGER_BASEOBJECT: return new BaseObjectEnumeration(get(baseDN), filter);		     case Scope.SCOPE_INTEGER_FIRSTLEVELONLY: return new LevelEnumeration(get(baseDN), 1, filter);			// OR ?? return new LevelEnumeration(get(baseDN), 1, filter);		     case Scope.SCOPE_INTEGER_WHOLESUBTREE: return new SubTreeEnumeration(get(baseDN), -1, filter);		     default: throw new RuntimeException(getClass().getName()+"getManagedObjects: bad Scope");		  }	       case Scope.SCOPE_INDIVIDUAL_LEVELS_CODE: return new LevelEnumeration(get(baseDN), scope.getScope(), filter);	       case Scope.SCOPE_BASE_TO_NTH_LEVEL_CODE: return new SubTreeEnumeration(get(baseDN), scope.getScope(), filter); 	       default: throw new RuntimeException(getClass().getName()+"getManagedObjects: bad Scope Type");	    }      }      class BaseObjectEnumeration implements Enumeration {	    BaseObjectEnumeration( Node start, Filter filter ) {	       // apply filter on mo	       baseObject=start;	    }	    public Object nextElement() {	       if (baseObject==null) { // getManagedObjects/hasMoreElements/nextElement badly used		  throw new java.util.NoSuchElementException("BaseObjectEnumeration missused");	       }	       Object result=baseObject.getManagedObject();	       baseObject=null;	       return result;	    }	    public boolean hasMoreElements() {	       return baseObject!=null;	    }	    private Node baseObject;      }      class SubTreeEnumeration implements Enumeration {	    SubTreeEnumeration( Node start, int maxDepth, Filter filter ) {	       this.maxDepth=maxDepth;	       current=start;                //if !filterOkFor(current) {	       // seek();	       //}	    }	    public boolean hasMoreElements() {	       return current!=null;	    }	    public Object nextElement() {	       if (current==null) { // getManagedObjects/hasMoreElements/nextElement badly used		  throw new java.util.NoSuchElementException("SubTreeEnumeration missused");	       }	       Object result=current.getManagedObject();	       seek(); // update hasMoreElements();	       return result;	    }	    private void seek() { // post fixed, deep first, left-rigth	       if (stack==null) { // stil on base		  stack=new Stack();		  Object dummy=stack.push(current.enumerateChilds()); // this push sucks !	       }	       while (!stack.empty()){		  Enumeration head=(Enumeration)stack.peek();		  if (head.hasMoreElements()){ // filter => loop		     //filter....		     current=(Node)head.nextElement();		     if ((maxDepth==-1)||(stack.size()<maxDepth)) {			Object dummy=stack.push(current.enumerateChilds());		     }		     return;		  } else {		     stack.pop();		  }	       }	       current=null;	    }	    private int maxDepth;	    private Stack stack;	    private Node current;      }      class LevelEnumeration implements Enumeration {	    LevelEnumeration( Node start, int targetLevel, Filter filter ) throws InvalidScopeException {	       this.targetLevel=targetLevel;	       stack=new Stack();// stack is needed IN ANY case. seek() is called at least once.This fixes a bug when targetLevel==0	       if (targetLevel>0) {		  Object dummy=stack.push(start.enumerateChilds()); // this push sucks !		  seek();	       } else {		   if (targetLevel<0) {		       throw new InvalidScopeException();		   } else {		       // if (filter....)		       current=start;		       // else current=null;		   }	       }	    }	    public boolean hasMoreElements() {	       return current!=null;	    }	    public Object nextElement() {	       if (current==null) { // getManagedObjects/hasMoreElements/nextElement badly used		  throw new java.util.NoSuchElementException("LevelEnumeration missused");	       }	       Object result=current.getManagedObject();	       seek(); // update hasMoreElements();	       return result;	    }	    private void seek() { // post fixed, deep first, left-rigth	       while (!stack.empty()){		  Enumeration head=(Enumeration)stack.peek();		  if (head.hasMoreElements()) {		     if (stack.size()==targetLevel) {			// filter...			current=(Node)head.nextElement();			return;		     } else { // stack.size()<targetlevel, as we are going  deep first.			   Object dummy=stack.push(((Node)head.nextElement()).enumerateChilds());		     }		  } else {		     stack.pop();		  }	       }	       current=null;	    }	    private int targetLevel;	    private Stack stack;	    private Node current;      }      private Node top=new Node(); //top is NOT linked to a management object. }

⌨️ 快捷键说明

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