org.openide.util.lookup.NamedServiceDefinition Maven / Gradle / Ivy
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.openide.util.lookup;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** Annotation to simplify creation and add robustness to usage of
* various named service registration annotations. For example
* the {@code @}
* URLStreamHandlerRegistration annotation uses the {@link NamedServiceDefinition}
* as:
* {@code @NamedServiceDefinition(path="URLStreamHandler/@protocol()", serviceType=URLStreamHandler.class)}
*
* The above instructs the annotation processor that handles {@link NamedServiceDefinition}s
* to verify the annotated type is subclass of URLStreamHandler
and
* if so, register it into URLStreamHandler/@protocol
where the
* value of @protocol()
is replaced by the value of annotation's
*
* protocol attribute. The registration can later be found by using
* {@link Lookups#forPath(java.lang.String) Lookups.forPath("URLStreamHandler/ftp")}
* (in case the protocol was ftp).
*
* @author Jaroslav Tulach <[email protected]>
* @since 8.14
* @see ServiceProvider#path()
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface NamedServiceDefinition {
/** Type, or array of types that the registered type
* has to implement. The annotated type needs to register at least
* one of the enumerated classes.
* @return set of type
*/
public Class>[] serviceType();
/** Path to register the annotation to, so it can later be found by
* using {@link Lookups#forPath(java.lang.String) Lookups.forPath(theSamePath)}.
* The path may reference attributes of the annotated annotation by prefixing
* them with {@code @}. To reuse attribute named location
one
* can for example use "how/to/get/to/@location()s/please"
* These attributes must be of type String
* or array of String
s (then one registration is performed
* per each string in the array).
* @return path to register annotation
*/
public String path();
/** Name of attribute that specifies position. By default the system tries
* to find int position()
attribute in the defined annotation
* and use it to specify the order of registrations. In case a different
* attribute should be used to specify the position, one can be provide its
* name by specifying non-default here. Should the position be ignored,
* specify empty string.
*
* name of attribute in the annotated annotation to use for defining
* position of the registration. The attribute should return int value.
* @return position
*/
public String position() default "-";
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy