001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Julien Anguenot 018 * Florent Guillaume 019 */ 020 021package org.nuxeo.ecm.core.lifecycle; 022 023import java.util.Collection; 024import java.util.List; 025import java.util.Map; 026 027import org.nuxeo.ecm.core.api.LifeCycleException; 028import org.nuxeo.ecm.core.lifecycle.event.BulkLifeCycleChangeListener; 029import org.nuxeo.ecm.core.model.Document; 030 031/** 032 * Life cycle service. 033 * 034 * @see org.nuxeo.ecm.core.lifecycle.impl.LifeCycleServiceImpl 035 * @author Julien Anguenot 036 * @author Florent Guillaume 037 */ 038public interface LifeCycleService { 039 040 /** 041 * Initializes the life cycle for the given document. 042 * <p> 043 * Document state will be set to the life cycle initial state. 044 * 045 * @param doc the document instance 046 */ 047 void initialize(Document doc) throws LifeCycleException; 048 049 /** 050 * Initializes the life cycle for the given document. 051 * <p> 052 * Tries to set given state on document, if it's a valid initial state. 053 * 054 * @param doc the document instance 055 * @param initialStateName the initial state name 056 */ 057 void initialize(Document doc, String initialStateName) throws LifeCycleException; 058 059 /** 060 * Follows a given transition. 061 * 062 * @param doc the Document instance 063 * @param transitionName the transition name 064 */ 065 void followTransition(Document doc, String transitionName) throws LifeCycleException; 066 067 /** 068 * Returns a life cycle given its name. 069 * 070 * @param name the life cycle's name 071 * @return a life cycle descriptor instance or null if not found. 072 */ 073 LifeCycle getLifeCycleByName(String name); 074 075 /** 076 * Returns all the registered life cycles. 077 * 078 * @return a collection of lifecycle descriptors 079 */ 080 Collection<LifeCycle> getLifeCycles(); 081 082 /** 083 * Returns the types which follow a given life cycle. 084 * 085 * @param lifeCycleName a string holding the name of the life cycle 086 * @return a collection of type names as strings 087 */ 088 Collection<String> getTypesFor(String lifeCycleName); 089 090 /** 091 * Returns the lifecycle name that the given type follows. 092 * 093 * @param typeName the type's name 094 * @return the life cycle name 095 */ 096 String getLifeCycleNameFor(String typeName); 097 098 /** 099 * Returns a list of transition for which, when a it is followed, it should no recurse in its children. The 100 * {@link BulkLifeCycleChangeListener} will listen to the transition taken event and call a follow transition on the 101 * children of the document if the document is folderish. It check this list of transition to find out if it should 102 * recurse. 103 * 104 * @see BulkLifeCycleChangeListener 105 * @param docTypeName The doc type 106 * @return a list of transition name 107 */ 108 List<String> getNonRecursiveTransitionForDocType(String docTypeName); 109 110 /** 111 * Returns the mapping from types to life cycle names. 112 * 113 * @return a mapping from types to life cycle names 114 */ 115 Map<String, String> getTypesMapping(); 116 117 /** 118 * Returns the life cycle a given document follows. 119 * 120 * @param doc the document instance 121 * @return the life cycle instance 122 */ 123 LifeCycle getLifeCycleFor(Document doc); 124 125 /** 126 * Sets the current state to the initial state as defined by the associated lifecycle. 127 */ 128 void reinitLifeCycle(Document doc) throws LifeCycleException; 129 130}