001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.jena; 014 015import java.util.*; 016 017import org.apache.juneau.*; 018import org.apache.juneau.jena.annotation.*; 019import org.apache.juneau.xml.*; 020 021/** 022 * Metadata on classes specific to the RDF serializers and parsers pulled from the {@link Rdf @Rdf} annotation on the 023 * class. 024 */ 025public class RdfClassMeta extends ExtendedClassMeta { 026 027 private final Rdf rdf; 028 private final RdfCollectionFormat collectionFormat; 029 private final Namespace namespace; 030 031 /** 032 * Constructor. 033 * 034 * @param cm The class that this annotation is defined on. 035 * @param mp RDF metadata provider (for finding information about other artifacts). 036 */ 037 public RdfClassMeta(ClassMeta<?> cm, RdfMetaProvider mp) { 038 super(cm); 039 this.rdf = cm.getAnnotation(Rdf.class); 040 if (rdf != null) { 041 collectionFormat = rdf.collectionFormat(); 042 } else { 043 collectionFormat = RdfCollectionFormat.DEFAULT; 044 } 045 List<Rdf> rdfs = cm.getAnnotations(Rdf.class); 046 List<RdfSchema> schemas = cm.getAnnotations(RdfSchema.class); 047 this.namespace = RdfUtils.findNamespace(rdfs, schemas); 048 } 049 050 /** 051 * Returns the {@link Rdf @Rdf} annotation defined on the class. 052 * 053 * @return The value of the annotation, or <jk>null</jk> if annotation is not specified. 054 */ 055 protected Rdf getAnnotation() { 056 return rdf; 057 } 058 059 /** 060 * Returns the {@link Rdf#collectionFormat() @Rdf(collectionFormat)} annotation defined on the class. 061 * 062 * @return The value of the annotation, or <jk>null</jk> if annotation is not 063 * specified. 064 */ 065 protected RdfCollectionFormat getCollectionFormat() { 066 return collectionFormat; 067 } 068 069 /** 070 * Returns the RDF namespace associated with this class. 071 * 072 * <p> 073 * Namespace is determined in the following order of {@link Rdf#prefix() @Rdf(prefix)} annotation: 074 * <ol> 075 * <li>Class. 076 * <li>Package. 077 * <li>Superclasses. 078 * <li>Superclass packages. 079 * <li>Interfaces. 080 * <li>Interface packages. 081 * </ol> 082 * 083 * @return The namespace associated with this class, or <jk>null</jk> if no namespace is associated with it. 084 */ 085 protected Namespace getNamespace() { 086 return namespace; 087 } 088}