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