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 bean properties specific to the RDF serializers and parsers pulled from the {@link Rdf @Rdf} annotation 023 * on the bean property. 024 */ 025public class RdfBeanPropertyMeta extends ExtendedBeanPropertyMeta { 026 027 /** 028 * Default instance. 029 */ 030 public static final RdfBeanPropertyMeta DEFAULT = new RdfBeanPropertyMeta(); 031 032 033 private RdfCollectionFormat collectionFormat = RdfCollectionFormat.DEFAULT; 034 private Namespace namespace = null; 035 private boolean isBeanUri; 036 037 /** 038 * Constructor. 039 * 040 * @param bpm The metadata of the bean property of this additional metadata. 041 * @param mp RDF metadata provider (for finding information about other artifacts). 042 */ 043 public RdfBeanPropertyMeta(BeanPropertyMeta bpm, RdfMetaProvider mp) { 044 super(bpm); 045 046 List<Rdf> rdfs = bpm.getAllAnnotations(Rdf.class); 047 List<RdfSchema> schemas = bpm.getAllAnnotations(RdfSchema.class); 048 049 for (Rdf rdf : rdfs) { 050 if (collectionFormat == RdfCollectionFormat.DEFAULT) 051 collectionFormat = rdf.collectionFormat(); 052 if (rdf.beanUri()) 053 isBeanUri = true; 054 } 055 056 namespace = RdfUtils.findNamespace(rdfs, schemas); 057 } 058 059 private RdfBeanPropertyMeta() { 060 super(null); 061 } 062 063 /** 064 * Returns the RDF collection format of this property from the {@link Rdf#collectionFormat} annotation on this bean 065 * property. 066 * 067 * @return The RDF collection format, or {@link RdfCollectionFormat#DEFAULT} if annotation not specified. 068 */ 069 protected RdfCollectionFormat getCollectionFormat() { 070 return collectionFormat; 071 } 072 073 /** 074 * Returns the RDF namespace associated with this bean property. 075 * 076 * <p> 077 * Namespace is determined in the following order of {@link Rdf#prefix() @Rdf(prefix)} annotations: 078 * <ol> 079 * <li>Bean property field. 080 * <li>Bean getter. 081 * <li>Bean setter. 082 * <li>Bean class. 083 * <li>Bean package. 084 * <li>Bean superclasses. 085 * <li>Bean superclass packages. 086 * <li>Bean interfaces. 087 * <li>Bean interface packages. 088 * </ol> 089 * 090 * @return The namespace associated with this bean property, or <jk>null</jk> if no namespace is associated with it. 091 */ 092 public Namespace getNamespace() { 093 return namespace; 094 } 095 096 /** 097 * Returns <jk>true</jk> if this bean property is marked with {@link Rdf#beanUri() @Rdf(beanUri)} as <jk>true</jk>. 098 * 099 * @return <jk>true</jk> if this bean property annotation is <jk>true</jk>. 100 */ 101 public boolean isBeanUri() { 102 return isBeanUri; 103 } 104}