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.internal.*;
019import org.apache.juneau.jena.annotation.*;
020import org.apache.juneau.xml.*;
021
022/**
023 * Metadata on classes specific to the RDF serializers and parsers pulled from the {@link Rdf @Rdf} annotation on the
024 * class.
025 */
026public class RdfClassMeta extends ClassMetaExtended {
027
028   private final Rdf rdf;
029   private final RdfCollectionFormat collectionFormat;
030   private final Namespace namespace;
031
032   /**
033    * Constructor.
034    *
035    * @param cm The class that this annotation is defined on.
036    */
037   public RdfClassMeta(ClassMeta<?> cm) {
038      super(cm);
039      Class<?> c = getInnerClass();
040      this.rdf = ClassUtils.getAnnotation(Rdf.class, c);
041      if (rdf != null) {
042         collectionFormat = rdf.collectionFormat();
043      } else {
044         collectionFormat = RdfCollectionFormat.DEFAULT;
045      }
046      List<Rdf> rdfs = ClassUtils.getAnnotations(Rdf.class, c);
047      List<RdfSchema> schemas = ClassUtils.getAnnotations(RdfSchema.class, c);
048      this.namespace = RdfUtils.findNamespace(rdfs, schemas);
049   }
050
051   /**
052    * Returns the {@link Rdf @Rdf} annotation defined on the class.
053    *
054    * @return The value of the annotation, or <jk>null</jk> if annotation is not specified.
055    */
056   protected Rdf getAnnotation() {
057      return rdf;
058   }
059
060   /**
061    * Returns the {@link Rdf#collectionFormat() @Rdf(collectionFormat)} annotation defined on the class.
062    *
063    * @return The value of the annotation, or <jk>null</jk> if annotation is not
064    * specified.
065    */
066   protected RdfCollectionFormat getCollectionFormat() {
067      return collectionFormat;
068   }
069
070   /**
071    * Returns the RDF namespace associated with this class.
072    *
073    * <p>
074    * Namespace is determined in the following order of {@link Rdf#prefix() @Rdf(prefix)} annotation:
075    * <ol>
076    *    <li>Class.
077    *    <li>Package.
078    *    <li>Superclasses.
079    *    <li>Superclass packages.
080    *    <li>Interfaces.
081    *    <li>Interface packages.
082    * </ol>
083    *
084    * @return The namespace associated with this class, or <jk>null</jk> if no namespace is associated with it.
085    */
086   protected Namespace getNamespace() {
087      return namespace;
088   }
089}