本文整理了Java中java.lang.Package.getAnnotation()
方法的一些代码示例,展示了Package.getAnnotation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Package.getAnnotation()
方法的具体详情如下:
包路径:java.lang.Package
类名称:Package
方法名:getAnnotation
[英]Returns the annotation associated with the specified annotation type and this package, if present.
[中]返回与指定批注类型和此包(如果存在)关联的批注。
代码示例来源:origin: robovm/robovm
/**
* Indicates whether the specified annotation is present.
*
* @param annotationType
* the annotation type to look for.
* @return {@code true} if the annotation is present; {@code false}
* otherwise.
* @see java.lang.reflect.AnnotatedElement#isAnnotationPresent(java.lang.Class)
*/
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
return getAnnotation(annotationType) != null;
}
代码示例来源:origin: oblac/jodd
private boolean parseMethodAuthFlag(final Method actionMethod) {
if (actionMethod.getAnnotation(Auth.class) != null) {
return true;
}
final Class declaringClass = actionMethod.getDeclaringClass();
if (declaringClass.getAnnotation(Auth.class) != null) {
return true;
}
if (declaringClass.getPackage().getAnnotation(Auth.class) != null) {
return true;
}
return false;
}
代码示例来源:origin: oblac/jodd
public Annotations<A> onPackageHierarchyOf(final Class type) {
Package pck = type.getPackage();
String packageName = pck.getName();
while (true) {
if (pck != null) {
A a = pck.getAnnotation(annotationClass);
if (a != null) {
annotations.add(a);
}
}
int ndx = packageName.lastIndexOf('.');
if (ndx == -1) {
break;
}
packageName = packageName.substring(0, ndx);
pck = Packages.of(type.getClassLoader(), packageName);
}
return this;
}
代码示例来源:origin: com.sun.xml.bind/jaxb-impl
public <A extends Annotation> A getPackageAnnotation(Class<A> a, Class clazz, Locatable srcPos) {
Package p = clazz.getPackage();
if(p==null) return null;
Map<Package,Annotation> cache = packageCache.get(a);
if(cache==null) {
cache = new HashMap<Package,Annotation>();
packageCache.put(a,cache);
}
if(cache.containsKey(p))
return (A)cache.get(p);
else {
A ann = LocatableAnnotation.create(p.getAnnotation(a),srcPos);
cache.put(p,ann);
return ann;
}
}
代码示例来源:origin: org.testng/testng
private static Ignore findAnnotation(Package testPackage) {
if (testPackage == null) {
return null;
}
Ignore result = testPackage.getAnnotation(Ignore.class);
if (result != null) {
return result;
}
String[] parts = testPackage.getName().split("\\.");
String[] parentParts = Arrays.copyOf(parts, parts.length - 1);
String parentPackageName = Strings.join(".", parentParts);
if (parentPackageName.isEmpty()) {
return null;
}
return findAnnotation(Package.getPackage(parentPackageName));
}
}
代码示例来源:origin: spring-projects/spring-framework
Package outputClassPackage = outputClass.getPackage();
if (outputClassPackage != null && outputClassPackage.isAnnotationPresent(XmlSchema.class)) {
XmlSchema annotation = outputClassPackage.getAnnotation(XmlSchema.class);
namespaceUri = annotation.namespace();
代码示例来源:origin: cbeust/testng
private static Ignore findAnnotation(Package testPackage) {
if (testPackage == null) {
return null;
}
Ignore result = testPackage.getAnnotation(Ignore.class);
if (result != null) {
return result;
}
String[] parts = testPackage.getName().split("\\.");
String[] parentParts = Arrays.copyOf(parts, parts.length - 1);
String parentPackageName = Strings.join(".", parentParts);
if (parentPackageName.isEmpty()) {
return null;
}
return findAnnotation(Package.getPackage(parentPackageName));
}
}
代码示例来源:origin: org.springframework/spring-web
Package outputClassPackage = outputClass.getPackage();
if (outputClassPackage != null && outputClassPackage.isAnnotationPresent(XmlSchema.class)) {
XmlSchema annotation = outputClassPackage.getAnnotation(XmlSchema.class);
namespaceUri = annotation.namespace();
代码示例来源:origin: oblac/jodd
MadvocAction madvocActionAnnotation = actionPackage.getAnnotation(MadvocAction.class);
代码示例来源:origin: resteasy/Resteasy
private static LinkELProvider findLinkELProvider(Method m){
if(m.isAnnotationPresent(LinkELProvider.class))
return m.getAnnotation(LinkELProvider.class);
Class<?> c = m.getDeclaringClass();
if(c.isAnnotationPresent(LinkELProvider.class))
return c.getAnnotation(LinkELProvider.class);
Package p = c.getPackage();
if(p != null && p.isAnnotationPresent(LinkELProvider.class))
return p.getAnnotation(LinkELProvider.class);
return null;
}
代码示例来源:origin: org.glassfish.jaxb/jaxb-runtime
public <A extends Annotation> A getPackageAnnotation(Class<A> a, Class clazz, Locatable srcPos) {
Package p = clazz.getPackage();
if(p==null) return null;
Map<Package,Annotation> cache = packageCache.get(a);
if(cache==null) {
cache = new HashMap<Package,Annotation>();
packageCache.put(a,cache);
}
if(cache.containsKey(p))
return (A)cache.get(p);
else {
A ann = LocatableAnnotation.create(p.getAnnotation(a),srcPos);
cache.put(p,ann);
return ann;
}
}
代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common
public List<ResourceInterceptor> getResourceInterceptorsForMethod(Method m) {
// First check the method
InterceptorChain chain = m.getAnnotation(InterceptorChain.class);
if (chain == null) {
// Next check the class
chain = m.getDeclaringClass().getAnnotation(InterceptorChain.class);
if (chain == null) {
// Finally, check the package
chain = m.getDeclaringClass().getPackage().getAnnotation(InterceptorChain.class);
}
}
if (chain != null) {
return buildFromClass(chain.value());
} else {
// Return default interceptor list
return new ArrayList<ResourceInterceptor>(defaultResourceInterceptors.values());
}
}
代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common
private boolean requiresWebSudo() {
final Method m = abstractMethod.getMethod();
if (null != m && m.getAnnotation(WebSudoRequired.class) != null) {
return true;
}
if (null != m && m.getAnnotation(WebSudoNotRequired.class) != null) {
return false;
}
final AbstractResource resource = abstractMethod.getResource();
if (resource.isAnnotationPresent(WebSudoRequired.class)) {
return true;
}
if (resource.isAnnotationPresent(WebSudoNotRequired.class)) {
return false;
}
final Package p = abstractMethod.getResource().getResourceClass().getPackage();
if (p.getAnnotation(WebSudoRequired.class) != null) {
return true;
}
if (p.getAnnotation(WebSudoNotRequired.class) != null) {
return false;
}
return false;
}
}
代码示例来源:origin: com.fasterxml.jackson.module/jackson-module-jaxb-annotations
Package pkg = memberClass.getPackage();
if (pkg != null) {
return memberClass.getPackage().getAnnotation(annotationClass);
代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws
protected final void initConfiguration(JaxWsImplementorInfo ii) {
if (ii.isWebServiceProvider()) {
jaxWsConfiguration = new WebServiceProviderConfiguration();
jaxWsConfiguration.setServiceFactory(this);
getServiceConfigurations().add(0, jaxWsConfiguration);
setWrapped(false);
setDataBinding(new SourceDataBinding());
setMethodDispatcher(new JAXWSProviderMethodDispatcher(implInfo));
} else {
jaxWsConfiguration = new JaxWsServiceConfiguration();
jaxWsConfiguration.setServiceFactory(this);
getServiceConfigurations().add(0, jaxWsConfiguration);
Class<?> seiClass = ii.getEndpointClass();
if (seiClass != null && seiClass.getPackage() != null) {
XmlSchema schema = seiClass.getPackage().getAnnotation(XmlSchema.class);
if (schema != null && XmlNsForm.QUALIFIED.equals(schema.elementFormDefault())) {
setQualifyWrapperSchema(true);
}
}
setMethodDispatcher(new JAXWSMethodDispatcher(implInfo));
}
loadWSFeatureAnnotation(ii.getSEIClass(), ii.getImplementorClass());
}
代码示例来源:origin: apache/cxf
static XmlAccessType getXmlAccessType(Class<?> cls) {
XmlAccessorType accessorType = cls.getAnnotation(XmlAccessorType.class);
if (accessorType == null && cls.getPackage() != null) {
accessorType = cls.getPackage().getAnnotation(XmlAccessorType.class);
}
return accessorType != null
? accessorType.value() : XmlAccessType.PUBLIC_MEMBER;
}
代码示例来源:origin: OpenNMS/opennms
public static <T> String getNamespaceForClass(final Class<T> clazz) {
final XmlSchema schema = clazz.getPackage().getAnnotation(XmlSchema.class);
if (schema != null) {
final String namespace = schema.namespace();
if (namespace != null && !"".equals(namespace)) {
return namespace;
}
}
return null;
}
代码示例来源:origin: org.apache.cxf/cxf-api
public static String getPackageNamespace(Class<?> cls) {
Package p = cls.getPackage();
if (p != null) {
javax.xml.bind.annotation.XmlSchema schemaAnn =
p.getAnnotation(javax.xml.bind.annotation.XmlSchema.class);
if (schemaAnn != null) {
return schemaAnn.namespace();
}
}
return null;
}
代码示例来源:origin: org.apache.cxf/cxf-core
public static String getPackageNamespace(Class<?> cls) {
Package p = cls.getPackage();
if (p != null) {
javax.xml.bind.annotation.XmlSchema schemaAnn =
p.getAnnotation(javax.xml.bind.annotation.XmlSchema.class);
if (schemaAnn != null) {
return schemaAnn.namespace();
}
}
return null;
}
代码示例来源:origin: apache/cxf
public static String getPackageNamespace(Class<?> cls) {
Package p = cls.getPackage();
if (p != null) {
javax.xml.bind.annotation.XmlSchema schemaAnn =
p.getAnnotation(javax.xml.bind.annotation.XmlSchema.class);
if (schemaAnn != null) {
return schemaAnn.namespace();
}
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!