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 BeanPropertyMetaExtended { 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 */ 042 public RdfBeanPropertyMeta(BeanPropertyMeta bpm) { 043 super(bpm); 044 045 List<Rdf> rdfs = bpm.findAnnotations(Rdf.class); 046 List<RdfSchema> schemas = bpm.findAnnotations(RdfSchema.class); 047 048 for (Rdf rdf : rdfs) { 049 if (collectionFormat == RdfCollectionFormat.DEFAULT) 050 collectionFormat = rdf.collectionFormat(); 051 if (rdf.beanUri()) 052 isBeanUri = true; 053 } 054 055 namespace = RdfUtils.findNamespace(rdfs, schemas); 056 } 057 058 private RdfBeanPropertyMeta() { 059 super(null); 060 } 061 062 /** 063 * Returns the RDF collection format of this property from the {@link Rdf#collectionFormat} annotation on this bean 064 * property. 065 * 066 * @return The RDF collection format, or {@link RdfCollectionFormat#DEFAULT} if annotation not specified. 067 */ 068 protected RdfCollectionFormat getCollectionFormat() { 069 return collectionFormat; 070 } 071 072 /** 073 * Returns the RDF namespace associated with this bean property. 074 * 075 * <p> 076 * Namespace is determined in the following order of {@link Rdf#prefix() @Rdf(prefix)} annotations: 077 * <ol> 078 * <li>Bean property field. 079 * <li>Bean getter. 080 * <li>Bean setter. 081 * <li>Bean class. 082 * <li>Bean package. 083 * <li>Bean superclasses. 084 * <li>Bean superclass packages. 085 * <li>Bean interfaces. 086 * <li>Bean interface packages. 087 * </ol> 088 * 089 * @return The namespace associated with this bean property, or <jk>null</jk> if no namespace is associated with it. 090 */ 091 public Namespace getNamespace() { 092 return namespace; 093 } 094 095 /** 096 * Returns <jk>true</jk> if this bean property is marked with {@link Rdf#beanUri() @Rdf(beanUri)} as <jk>true</jk>. 097 * 098 * @return <jk>true</jk> if this bean property annotation is <jk>true</jk>. 099 */ 100 public boolean isBeanUri() { 101 return isBeanUri; 102 } 103}