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