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