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 * @throws LifeCycleException 047 */ 048 void initialize(Document doc) throws LifeCycleException; 049 050 /** 051 * Initializes the life cycle for the given document. 052 * <p> 053 * Tries to set given state on document, if it's a valid initial state. 054 * 055 * @param doc the document instance 056 * @param initialStateName the initial state name 057 * @throws LifeCycleException 058 */ 059 void initialize(Document doc, String initialStateName) throws LifeCycleException; 060 061 /** 062 * Follows a given transition. 063 * 064 * @param doc the Document instance 065 * @param transitionName the transition name 066 * @throws LifeCycleException 067 */ 068 void followTransition(Document doc, String transitionName) throws LifeCycleException; 069 070 /** 071 * Returns a life cycle given its name. 072 * 073 * @param name the life cycle's name 074 * @return a life cycle descriptor instance or null if not found. 075 */ 076 LifeCycle getLifeCycleByName(String name); 077 078 /** 079 * Returns all the registered life cycles. 080 * 081 * @return a collection of lifecycle descriptors 082 */ 083 Collection<LifeCycle> getLifeCycles(); 084 085 /** 086 * Returns the types which follow a given life cycle. 087 * 088 * @param lifeCycleName a string holding the name of the life cycle 089 * @return a collection of type names as strings 090 */ 091 Collection<String> getTypesFor(String lifeCycleName); 092 093 /** 094 * Returns the lifecycle name that the given type follows. 095 * 096 * @param typeName the type's name 097 * @return the life cycle name 098 */ 099 String getLifeCycleNameFor(String typeName); 100 101 /** 102 * Returns a list of transition for which, when a it is followed, it should no recurse in its children. The 103 * {@link BulkLifeCycleChangeListener} will listen to the transition taken event and call a follow transition on the 104 * children of the document if the document is folderish. It check this list of transition to find out if it should 105 * recurse. 106 * 107 * @see BulkLifeCycleChangeListener 108 * @param docTypeName The doc type 109 * @return a list of transition name 110 */ 111 List<String> getNonRecursiveTransitionForDocType(String docTypeName); 112 113 /** 114 * Returns the mapping from types to life cycle names. 115 * 116 * @return a mapping from types to life cycle names 117 */ 118 Map<String, String> getTypesMapping(); 119 120 /** 121 * Returns the life cycle a given document follows. 122 * 123 * @param doc the document instance 124 * @return the life cycle instance 125 */ 126 LifeCycle getLifeCycleFor(Document doc); 127 128 /** 129 * Sets the current state to the initial state as defined by the associated lifecycle. 130 * 131 * @param doc 132 * @throws LifeCycleException 133 */ 134 void reinitLifeCycle(Document doc) throws LifeCycleException; 135 136}