001/*
002 * (C) Copyright 2006-2007 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 *     Dragos Mihalache
018 */
019package org.nuxeo.ecm.core.uidgen;
020
021import org.nuxeo.ecm.core.api.DocumentModel;
022import org.nuxeo.ecm.core.api.model.PropertyNotFoundException;
023
024/**
025 * Common interface for UID generators. All UID generators must implement this interface.
026 *
027 * @author <a href="mailto:dm@nuxeo.com">Dragos Mihalache</a>
028 */
029public interface UIDGenerator {
030
031    /**
032     * Sets the property name used to set the identifier value.
033     * <p>
034     * The property must be a string like 'schemaPrefix:fieldName' ; the syntax 'schemaName:fieldName' is also accepted.
035     * Could be used as a convenient method when there is only one property to set.
036     *
037     * @see #setPropertyNames(String[])
038     */
039    void setPropertyName(String propertyName);
040
041    /**
042     * Get the property name used to set the identifier value.
043     *
044     * @see #getPropertyNames()
045     */
046    String getPropertyName();
047
048    /**
049     * Set the properties used to set the identifier value.
050     */
051    void setPropertyNames(String[] propertyNames);
052
053    /**
054     * Gets the property name used to set the identifier value
055     */
056    String[] getPropertyNames();
057
058    /**
059     * The sequencer used to generate unique numbers sequencially.
060     */
061    void setSequencer(UIDSequencer sequencer);
062
063    String getSequenceKey(DocumentModel document);
064
065    /**
066     * Returns a new UID for the given doc.
067     */
068    String createUID(DocumentModel document);
069
070    /**
071     * Creates a new UID for the given doc and sets the field configured in the generator component with this value.
072     */
073    void setUID(DocumentModel document) throws PropertyNotFoundException;
074
075}