001/*
002 *  Copyright 2010 Anyware Services
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 */
016package org.ametys.plugins.repository;
017
018import org.ametys.plugins.repository.data.holder.DataHolder;
019
020/**
021 * Common interface for all Ametys objects.
022 */
023public interface AmetysObject extends DataHolder
024{
025    /**
026     * Retrieves the name of the current object.
027     * @return the name.
028     * @throws AmetysRepositoryException if an error occurs.
029     */
030    String getName() throws AmetysRepositoryException;
031    
032    /**
033     * Retrieves the path of the current object.
034     * @return the path.
035     * @throws AmetysRepositoryException if an error occurs.
036     */
037    String getPath() throws AmetysRepositoryException;
038    
039    /**
040     * Retrieves the unique identifier of this AmetysObject.<br>
041     * It must be unique in the whole repository and must never be null.<br>
042     * It must conform to the URI syntax:<br>
043     * <code>&lt;protocol&gt;://&lt;protocol-specific-part&gt;</code>
044     * @return the unique identifier of this AmetysObject
045     * @throws AmetysRepositoryException if an error occurs.
046     */
047    String getId() throws AmetysRepositoryException;
048    
049    /**
050     * Returns the parent object in the Ametys hierarchy.
051     * @param <A> the type of the parent {@link AmetysObject}.
052     * @return the parent object or <code>null</code> if current object
053     *         is the root.
054     * @throws AmetysRepositoryException if an error occurs.
055     */
056    <A extends AmetysObject> A getParent() throws AmetysRepositoryException;
057    
058    /**
059     * Returns the path of the parent object in the Ametys hierarchy.
060     * @return the path of the parent object.
061     * @throws AmetysRepositoryException if an error occurs.
062     */
063    String getParentPath() throws AmetysRepositoryException;
064    
065    /**
066     * Two AmetysObjects are equals if and only if their ids are equals.
067     */
068    @Override
069    public boolean equals(Object obj);
070    
071    /**
072     * The hashCode of an AmetysObject must be the hashCode of its id.
073     */
074    @Override
075    public int hashCode();
076}