001/*
002 * Copyright 2002-2018 the original author or authors.
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 *      https://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
017package org.springframework.core;
018
019/**
020 * Interface defining a generic contract for attaching and accessing metadata
021 * to/from arbitrary objects.
022 *
023 * @author Rob Harrop
024 * @since 2.0
025 */
026public interface AttributeAccessor {
027
028        /**
029         * Set the attribute defined by {@code name} to the supplied {@code value}.
030         * If {@code value} is {@code null}, the attribute is {@link #removeAttribute removed}.
031         * <p>In general, users should take care to prevent overlaps with other
032         * metadata attributes by using fully-qualified names, perhaps using
033         * class or package names as prefix.
034         * @param name the unique attribute key
035         * @param value the attribute value to be attached
036         */
037        void setAttribute(String name, Object value);
038
039        /**
040         * Get the value of the attribute identified by {@code name}.
041         * Return {@code null} if the attribute doesn't exist.
042         * @param name the unique attribute key
043         * @return the current value of the attribute, if any
044         */
045        Object getAttribute(String name);
046
047        /**
048         * Remove the attribute identified by {@code name} and return its value.
049         * Return {@code null} if no attribute under {@code name} is found.
050         * @param name the unique attribute key
051         * @return the last value of the attribute, if any
052         */
053        Object removeAttribute(String name);
054
055        /**
056         * Return {@code true} if the attribute identified by {@code name} exists.
057         * Otherwise return {@code false}.
058         * @param name the unique attribute key
059         */
060        boolean hasAttribute(String name);
061
062        /**
063         * Return the names of all attributes.
064         */
065        String[] attributeNames();
066
067}