001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.marshall.jena; 018 019import static org.apache.juneau.commons.utils.CollectionUtils.*; 020import static org.apache.juneau.commons.utils.Shorts.*; 021import static org.apache.juneau.commons.utils.StringUtils.*; 022import static org.apache.juneau.marshall.jena.Constants.*; 023 024import java.io.*; 025import java.util.*; 026import java.util.concurrent.atomic.*; 027 028import org.apache.jena.rdf.model.*; 029import org.apache.jena.riot.*; 030import org.apache.jena.riot.lang.*; 031import org.apache.jena.sparql.util.Context; 032import org.apache.jena.util.iterator.*; 033import org.apache.juneau.commons.bean.*; 034import org.apache.juneau.commons.reflect.*; 035import org.apache.juneau.marshall.*; 036import org.apache.juneau.marshall.collections.*; 037import org.apache.juneau.marshall.parser.*; 038import org.apache.juneau.marshall.swap.spi.*; 039import org.apache.juneau.marshall.xml.*; 040 041import com.apicatalog.jsonld.JsonLdOptions; 042 043/** 044 * Session object that lives for the duration of a single use of {@link RdfParser}. 045 * 046 * <h2 class='section'>Notes:</h2><ul> 047 * <li class='warn'>This class is not thread safe and is typically discarded after one use. 048 * </ul> 049 * 050 * <h2 class='section'>See Also:</h2><ul> 051 * <li class='link'>{doc jmr.RdfDetails} 052 053 * </ul> 054 */ 055@SuppressWarnings({ 056 "java:S138", // RDF parsing requires complex dispatch logic 057 "java:S3776", // Cognitive complexity - RDF graph traversal is inherently complex 058 "java:S6541", // Brain method - RDF graph-to-POJO conversion requires complex dispatch 059 "rawtypes", // Raw types necessary for generic type handling 060 "unchecked" // Type erasure requires unchecked casts 061}) 062public class RdfParserSession extends ReaderParserSession { 063 064 /** 065 * Builder class. 066 */ 067 public static class Builder extends ReaderParserSession.Builder<Builder> { 068 069 private final RdfParser ctx; 070 071 /** 072 * Constructor 073 * 074 * @param ctx The context creating this session. 075 * <br>Cannot be <jk>null</jk>. 076 */ 077 protected Builder(RdfParser ctx) { 078 super(ctx); 079 this.ctx = ctx; 080 } 081 082 @Override 083 public RdfParserSession build() { 084 return new RdfParserSession(this); 085 } 086 087 } 088 089 /** 090 * Creates a new builder for this object. 091 * 092 * @param ctx The context creating this session. 093 * <br>Cannot be <jk>null</jk>. 094 * @return A new builder. 095 */ 096 public static Builder create(RdfParser ctx) { 097 return new Builder(ctx); 098 } 099 100 private final Model model; 101 private final org.apache.jena.rdf.model.Property pRoot; 102 private final org.apache.jena.rdf.model.Property pValue; 103 private final org.apache.jena.rdf.model.Property pType; 104 private final org.apache.jena.rdf.model.Property pRdfType; 105 private final Lang lang; 106 private final RdfParser ctx; 107 private final Set<Resource> urisVisited = st(); 108 109 /** 110 * Constructor. 111 * 112 * @param builder The builder for this object. 113 * <br>Cannot be <jk>null</jk>. 114 */ 115 protected RdfParserSession(Builder builder) { 116 super(builder); 117 ctx = builder.ctx; 118 model = ModelFactory.createDefaultModel(); 119 addModelPrefix(ctx.getJuneauNs()); 120 addModelPrefix(ctx.getJuneauBpNs()); 121 pRdfType = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); 122 pRoot = model.createProperty(ctx.getJuneauNs().getUri(), "root"); 123 pType = model.createProperty(ctx.getJuneauBpNs().getUri(), "_type"); 124 pValue = model.createProperty(ctx.getJuneauNs().getUri(), "value"); 125 126 // Map legacy language names to RIOT Lang 127 var langName = ctx.getLanguage(); 128 lang = toLang(langName); 129 if (lang == null) 130 throw isex("Unknown RDF language: %s", langName); 131 } 132 133 /** 134 * Creates the RIOT context used for parsing, restricting JSON-LD to local documents unless remote contexts are allowed. 135 */ 136 static Context parserContext(boolean allowRemoteContexts) { 137 var c = Context.create(); 138 if (! allowRemoteContexts) { 139 var o = new JsonLdOptions(); 140 o.setDocumentLoader(RdfNoNetworkDocumentLoader.INSTANCE); 141 c.set(LangJSONLD11.JSONLD_OPTIONS, o); 142 } 143 return c; 144 } 145 146 // Package-private (not private) for white-box testing. 147 static Lang toLang(String langName) { 148 var lang = RDFLanguages.nameToLang(langName); 149 if (lang != null) 150 return lang; 151 if (eq(langName, "RDF/PROTO")) 152 return Lang.RDFPROTO; 153 return null; 154 } 155 156 private final void addModelPrefix(Namespace ns) { 157 model.setNsPrefix(ns.getName(), ns.getUri()); 158 } 159 160 /** 161 * Decodes the specified string. 162 * If {@link RdfParser#RDF_trimWhitespace} is <jk>true</jk>, the resulting string is trimmed before decoding. 163 * If {@link #isTrimStrings()} is <jk>true</jk>, the resulting string is trimmed after decoding. 164 */ 165 // Package-private (not private) for white-box testing. 166 String decodeString(Object o) { 167 if (o == null) 168 return null; 169 var s = o.toString(); 170 if (s.isEmpty()) 171 return s; 172 if (isTrimWhitespace()) 173 s = s.trim(); 174 s = XmlUtils.decode(s, null); 175 if (isTrimStrings()) 176 s = s.trim(); 177 return s; 178 } 179 180 /* 181 * Finds the roots in the model using either the "root" property to identify it, 182 * or by resorting to scanning the model for all nodes with no incoming predicates. 183 */ 184 // Package-private (not private) for white-box testing. 185 List<Resource> getRoots(Model m) { 186 var l = new LinkedList<Resource>(); 187 188 // First try to find the root using the "http://www.apache.org/juneau/root" property. 189 var root = m.createProperty(getJuneauNs().getUri(), "root"); 190 for (ResIterator i = m.listResourcesWithProperty(root); i.hasNext();) 191 l.add(i.next()); 192 193 if (! l.isEmpty()) 194 return l; 195 196 // Otherwise, we need to find all resources that aren't objects. 197 // We want to explicitly ignore statements where the subject 198 // and object are the same node. 199 var objects = new HashSet<RDFNode>(); 200 for (StmtIterator i = m.listStatements(); i.hasNext();) { 201 var st = i.next(); 202 var subject = st.getSubject(); 203 var object = st.getObject(); 204 if (object.isResource() && ! object.equals(subject)) 205 objects.add(object); 206 } 207 for (ResIterator i = m.listSubjects(); i.hasNext();) { 208 var r = i.next(); 209 if (! objects.contains(r)) 210 l.add(r); 211 } 212 return l; 213 } 214 215 // Package-private (not private) for white-box testing. 216 Object getValue(RDFNode n, Object outer) throws ParseException { 217 if (n.isLiteral()) 218 return n.asLiteral().getValue(); 219 if (n.isResource()) { // HTT: RDFNode has only two concrete kinds (Literal, Resource); this is always true once isLiteral() is false. 220 var st = n.asResource().getProperty(pValue); 221 if (nn(st)) { 222 n = st.getObject(); 223 if (n.isLiteral()) 224 return n.asLiteral().getValue(); 225 return readAnything(object(), st.getObject(), outer, null); 226 } 227 } 228 throw new ParseException(this, "Unknown value type for node '%s'", n); 229 } 230 231 // Package-private (not private) for white-box testing. 232 boolean isBag(RDFNode n) { 233 if (n.isResource()) { 234 var st = n.asResource().getProperty(pRdfType); 235 if (nn(st)) 236 return RDF_BAG.equals(st.getResource().getURI()); 237 } 238 return false; 239 } 240 241 // Package-private (not private) for white-box testing. 242 boolean isMultiValuedCollections(BeanPropertyMeta pMeta) { 243 var bpRdf = getRdfBeanPropertyMeta(pMeta); 244 245 if (bpRdf.getCollectionFormat() != RdfCollectionFormat.DEFAULT) 246 return bpRdf.getCollectionFormat() == RdfCollectionFormat.MULTI_VALUED; 247 248 return getCollectionFormat() == RdfCollectionFormat.MULTI_VALUED; 249 } 250 251 // Package-private (not private) for white-box testing. 252 boolean isSeq(RDFNode n) { 253 if (n.isResource()) { 254 var st = n.asResource().getProperty(pRdfType); 255 if (nn(st)) 256 return RDF_SEQ.equals(st.getResource().getURI()); 257 } 258 return false; 259 } 260 261 // Package-private (not private) for white-box testing. 262 <T> T readAnything(ClassMeta<?> eType, RDFNode n, Object outer, BeanPropertyMeta pMeta) throws ParseException { 263 264 if (eType == null) 265 eType = object(); 266 var swap = (ObjectSwap<T,Object>)eType.getSwap(this); 267 var builder = (BuilderSwap<T,Object>)eType.getBuilderSwap(this); 268 ClassMeta<?> sType; 269 if (nn(builder)) 270 sType = builder.getBuilderClassMeta(this); 271 else if (nn(swap)) 272 sType = swap.getSwapClassMeta(this); 273 else 274 sType = eType; 275 276 if (sType.isOptional()) 277 return (T)o(readAnything(eType.getElementType(), n, outer, pMeta)); 278 279 setCurrentClass(sType); 280 281 if (! sType.canCreateNewInstance(outer) && n.isResource()) { 282 var st = n.asResource().getProperty(pType); 283 if (nn(st)) { 284 var c = st.getLiteral().getString(); 285 var tcm = getClassMeta(c, pMeta, eType); 286 if (nn(tcm)) 287 sType = eType = tcm; 288 } 289 } 290 291 Object o = null; 292 if (n.isResource() && nn(n.asResource().getURI()) && n.asResource().getURI().equals(RDF_NIL)) { 293 // Do nothing. Leave o == null. 294 } else if (sType.isObject()) { 295 if (n.isLiteral()) { 296 o = n.asLiteral().getValue(); 297 if (o instanceof String o2) { 298 o = decodeString(o2); 299 } 300 } else if (n.isResource()) { // HTT: RDFNode has only two concrete kinds (Literal, Resource); this is always true once isLiteral() (above) is false -- the else below is defensive dead code. 301 var r = n.asResource(); 302 if (! urisVisited.add(r)) 303 o = r.getURI(); 304 else if (nn(r.getProperty(pValue))) { 305 o = readAnything(object(), n.asResource().getProperty(pValue).getObject(), outer, null); 306 } else if (isSeq(r)) { 307 o = new JsonList(this); 308 readIntoCollection(r.as(Seq.class), (Collection)o, sType, pMeta); 309 } else if (isBag(r)) { 310 o = new JsonList(this); 311 readIntoCollection(r.as(Bag.class), (Collection)o, sType, pMeta); 312 } else if (r.canAs(RDFList.class)) { 313 o = new JsonList(this); 314 readIntoCollection(r.as(RDFList.class), (Collection)o, sType, pMeta); 315 } else { 316 // If it has a URI and no child properties, we interpret this as an 317 // external resource, and convert it to just a URL. 318 var uri = r.getURI(); 319 if (nn(uri) && ! r.listProperties().hasNext()) { 320 o = r.getURI(); 321 } else { 322 var m2 = new JsonMap(this); 323 readIntoMap(r, m2, null, null, pMeta); 324 o = cast(m2, pMeta, eType); 325 } 326 } 327 } else { // HTT: unreachable -- n is always Literal or Resource; see guard above. 328 throw new ParseException(this, "Unrecognized node type '%s' for object", n); // HTT: unreachable -- see guard above. 329 } 330 } else if (nn(builder)) { 331 var r = n.asResource(); 332 if (! urisVisited.add(r)) 333 return null; 334 var bm = toBeanMap(builder.create(this, eType)); 335 o = builder.build(this, checkRequired(readIntoBeanMap(r, bm)).getBean(), eType); 336 } else if (sType.canCreateNewBean(outer)) { 337 var r = n.asResource(); 338 if (! urisVisited.add(r)) 339 return null; 340 var bm = newBeanMap(outer, sType.inner()); 341 o = checkRequired(readIntoBeanMap(r, bm)).getBean(); 342 } else if (sType.isMap()) { 343 var r = n.asResource(); 344 if (! urisVisited.add(r)) 345 return null; 346 var m = (sType.canCreateNewInstance(outer) ? (Map)sType.newInstance(outer) : newGenericMap(sType)); 347 o = readIntoMap(r, m, eType.getKeyType(), eType.getValueType(), pMeta); 348 } else if (sType.isCollectionOrArray() || sType.isArgs()) { // HTT: isArgs() requires method-argument list ClassMeta; not reachable through public parse() API -- always false here. 349 if (sType.isArray() || sType.isArgs()) // HTT: isArgs() requires method-argument list ClassMeta; not reachable through public parse() API -- always false here. 350 o = list(); 351 else 352 o = (sType.canCreateNewInstance(outer) ? (Collection<?>)sType.newInstance(outer) : new JsonList(this)); 353 var r = n.asResource(); 354 if (! urisVisited.add(r)) 355 return null; 356 if (isSeq(r)) { 357 readIntoCollection(r.as(Seq.class), (Collection)o, sType, pMeta); 358 } else if (isBag(r)) { 359 readIntoCollection(r.as(Bag.class), (Collection)o, sType, pMeta); 360 } else if (r.canAs(RDFList.class)) { 361 readIntoCollection(r.as(RDFList.class), (Collection)o, sType, pMeta); 362 } else { 363 throw new ParseException(this, "Unrecognized node type '%s' for collection", n); 364 } 365 if (sType.isArray() || sType.isArgs()) // HTT: isArgs() requires method-argument list ClassMeta; not reachable through public parse() API -- always false here. 366 o = toArray(sType, (Collection)o); 367 } else if (sType.isCharSequence()) { 368 o = decodeString(getValue(n, outer)); 369 } else if (sType.isChar()) { 370 o = parseCharacter(decodeString(getValue(n, outer))); 371 } else if (sType.isNumber()) { 372 o = parseNumber(getValue(n, outer).toString(), (Class<? extends Number>)sType.inner()); 373 } else if (sType.isBoolean()) { 374 o = convertToType(getValue(n, outer), boolean.class); 375 } else if (sType.isUri() && n.isResource()) { 376 // RDF URIs must be reconstructed from the resource's URI string (not from a literal), 377 // so this branch is kept here to fire before the temporal/scalar coercion fallbacks. 378 o = sType.newInstanceFromString(outer, decodeString(n.asResource().getURI())); 379 } else if (sType.isDate()) { 380 o = readDate(getValue(n, outer).toString(), sType); 381 } else if (sType.isCalendar()) { 382 o = readCalendar(getValue(n, outer).toString(), sType); 383 } else if (sType.isTemporal()) { 384 o = readTemporal(getValue(n, outer).toString(), sType); 385 } else if (sType.isDuration()) { 386 o = readDuration(getValue(n, outer).toString()); 387 } else if (sType.isPeriod()) { 388 o = readPeriod(getValue(n, outer).toString()); 389 } else if (sType.canCreateNewInstanceFromString(outer)) { 390 o = sType.newInstanceFromString(outer, decodeString(getValue(n, outer))); 391 } else if (n.isResource()) { 392 var r = n.asResource(); 393 var m = newGenericMap(sType); 394 readIntoMap(r, m, sType.getKeyType(), sType.getValueType(), pMeta); 395 if (m.containsKey(getBeanTypePropertyName(eType))) 396 o = cast((MarshalledMap)m, pMeta, eType); 397 else if (nn(sType.getProxyInvocationHandler())) 398 o = checkRequired(newBeanMap(outer, sType.inner()).load(m)).getBean(); 399 else 400 throw new ParseException(this, "Class '%s' could not be instantiated. Reason: '%s'", cn(sType), sType.getNotABeanReason()); 401 } else { 402 throw new ParseException(this, "Class '%s' could not be instantiated. Reason: '%s'", cn(sType), sType.getNotABeanReason()); 403 } 404 405 if (nn(swap) && nn(o)) 406 o = unswap(swap, o, eType); 407 408 if (nn(outer)) 409 setParent(eType, o, outer); 410 411 return (T)o; 412 } 413 414 // Package-private (not private) for white-box testing. 415 <T> BeanMap<T> readIntoBeanMap(Resource r2, BeanMap<T> m) throws ParseException { 416 var bm = m.getMeta(); 417 var rbm = getRdfBeanMeta(bm); 418 if (rbm.hasBeanUri() && nn(r2.getURI())) 419 rbm.getBeanUriProperty().set(m, null, r2.getURI()); 420 for (StmtIterator i = r2.listProperties(); i.hasNext();) { 421 var st = i.next(); 422 var p = st.getPredicate(); 423 var key = decodeString(p.getLocalName()); 424 var pMeta = m.getPropertyMeta(key); 425 setCurrentProperty(pMeta); 426 if (nn(pMeta)) { 427 var o = st.getObject(); 428 var cm = (ClassMeta<?>) pMeta.getBeanInfo(); 429 if (cm.isCollectionOrArray() && isMultiValuedCollections(pMeta)) { 430 var et = cm.getElementType(); 431 var value = readAnything(et, o, m.getBean(false), pMeta); 432 setName(et, value, key); 433 try { 434 pMeta.add(m, key, value); 435 } catch (BeanRuntimeException e) { 436 onBeanSetterException(pMeta, e); 437 throw e; 438 } 439 } else { 440 var value = readAnything(cm, o, m.getBean(false), pMeta); 441 setName(cm, value, key); 442 try { 443 pMeta.set(m, key, value); 444 } catch (BeanRuntimeException e) { 445 onBeanSetterException(pMeta, e); 446 throw e; 447 } 448 } 449 } else if (! (p.equals(pRoot) || p.equals(pType))) { 450 var o = st.getObject(); 451 var value = readAnything(object(), o, m.getBean(false), null); 452 onUnknownProperty(key, m, value); 453 } 454 setCurrentProperty(null); 455 } 456 return m; 457 } 458 459 // Package-private (not private) for white-box testing. 460 <E> Collection<E> readIntoCollection(Container c, Collection<E> l, ClassMeta<?> type, BeanPropertyMeta pMeta) throws ParseException { 461 int argIndex = 0; 462 for (NodeIterator ni = c.iterator(); ni.hasNext();) { 463 E e = (E)readAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), ni.next(), l, pMeta); // HTT: isArgs() requires method-argument list ClassMeta; not reachable through public parse() API. 464 l.add(e); 465 } 466 return l; 467 } 468 469 // Package-private (not private) for white-box testing. 470 <E> Collection<E> readIntoCollection(RDFList list, Collection<E> l, ClassMeta<?> type, BeanPropertyMeta pMeta) throws ParseException { 471 int argIndex = 0; 472 for (ExtendedIterator<RDFNode> ni = list.iterator(); ni.hasNext();) { 473 E e = (E)readAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), ni.next(), l, pMeta); // HTT: isArgs() requires method-argument list ClassMeta; not reachable through public parse() API. 474 l.add(e); 475 } 476 return l; 477 } 478 479 // Package-private (not private) for white-box testing. 480 <K,V> Map<K,V> readIntoMap(Resource r, Map<K,V> m, ClassMeta<K> keyType, ClassMeta<V> valueType, BeanPropertyMeta pMeta) throws ParseException { 481 // Add URI as "uri" to generic maps. 482 if (nn(r.getURI())) { 483 var uri = convertAttrToType(m, "uri", keyType); 484 var value = convertAttrToType(m, r.getURI(), valueType); 485 m.put(uri, value); 486 } 487 for (StmtIterator i = r.listProperties(); i.hasNext();) { 488 var st = i.next(); 489 var p = st.getPredicate(); 490 var key = p.getLocalName(); 491 if (! (eq(key, "root") && p.getURI().equals(getJuneauNs().getUri()))) { // Bug: p.getURI() is the property's FULL URI, never equal to the bare namespace URI on the right; the inner && is therefore always false and this guard's "skip" branch is permanently unreachable. 492 key = decodeString(key); 493 var o = st.getObject(); 494 var key2 = convertAttrToType(m, key, keyType); 495 V value = readAnything(valueType, o, m, pMeta); 496 setName(valueType, value, key); 497 m.put(key2, value); 498 } 499 500 } 501 return m; 502 } 503 504 @Override /* Overridden from ReaderParserSession */ 505 protected <T> T doRead(ParserPipe pipe, ClassMeta<T> type) throws IOException, ParseException, ExecutableException { 506 507 // RDFDataMgr.read accepts StringReader; use RDFParser for Reader input 508 var content = pipe.asString(); 509 RDFParser.fromString(content, lang) 510 .base("http://unknown/") 511 .context(parserContext(ctx.allowRemoteContexts)) 512 .parse(model); 513 514 var roots = getRoots(model); 515 516 // Special case where we're parsing a loose collection of resources. 517 if (isLooseCollections() && type.isCollectionOrArray()) { 518 Collection c; 519 if (type.isArray() || type.isArgs()) // HTT: isArgs() requires method-argument list ClassMeta; not reachable through public parse() API. 520 c = list(); 521 else 522 c = (type.canCreateNewInstance(getOuter()) ? (Collection<?>)type.newInstance(getOuter()) : new JsonList(this)); 523 524 var argIndex = new AtomicInteger(0); 525 var c2 = c; 526 roots.forEach(x -> c2.add(readAnything(type.isArgs() ? type.getArg(argIndex.getAndIncrement()) : type.getElementType(), x, getOuter(), null))); // HTT: isArgs() guard -- same constraint as above. 527 528 if (type.isArray() || type.isArgs()) // HTT: isArgs() guard -- same constraint as above. 529 return (T)toArray(type, c); 530 return (T)c; 531 } 532 533 if (roots.isEmpty()) 534 return type.isOptional() ? (T)oe() : null; 535 536 if (roots.size() > 1) 537 throw new ParseException(this, "Too many root nodes found in model: %s", roots.size()); 538 var resource = roots.get(0); 539 540 return readAnything(type, resource, getOuter(), null); 541 } 542 543 /** 544 * RDF format for representing collections and arrays. 545 * 546 * @see RdfParser.Builder#collectionFormat(RdfCollectionFormat) 547 * @return 548 * RDF format for representing collections and arrays. 549 */ 550 protected final RdfCollectionFormat getCollectionFormat() { return ctx.getCollectionFormat(); } 551 552 /** 553 * All Jena-related configuration properties. 554 * 555 * @return 556 * A map of all Jena-related configuration properties. 557 */ 558 protected final Map<String,Object> getJenaSettings() { return ctx.getJenaSettings(); } 559 560 /** 561 * Default XML namespace for bean properties. 562 * 563 * @see RdfParser.Builder#juneauBpNs(Namespace) 564 * @return 565 * Default XML namespace for bean properties. 566 */ 567 protected final Namespace getJuneauBpNs() { return ctx.getJuneauBpNs(); } 568 569 /** 570 * XML namespace for Juneau properties. 571 * 572 * @see RdfParser.Builder#juneauNs(Namespace) 573 * @return 574 * XML namespace for Juneau properties. 575 */ 576 protected final Namespace getJuneauNs() { return ctx.getJuneauNs(); } 577 578 /** 579 * RDF language. 580 * 581 * @see RdfParser.Builder#language(String) 582 * @return 583 * The RDF language to use. 584 */ 585 protected final String getLanguage() { return ctx.getLanguage(); } 586 587 /** 588 * Returns the language-specific metadata on the specified bean. 589 * 590 * @param bm The bean to return the metadata on. 591 * @return The metadata. 592 */ 593 protected RdfBeanMeta getRdfBeanMeta(BeanMeta<?> bm) { 594 return ctx.getRdfBeanMeta(bm); 595 } 596 597 /** 598 * Returns the language-specific metadata on the specified bean property. 599 * 600 * @param bpm The bean property to return the metadata on. 601 * @return The metadata. 602 */ 603 protected RdfBeanPropertyMeta getRdfBeanPropertyMeta(BeanPropertyMeta bpm) { 604 return ctx.getRdfBeanPropertyMeta(bpm); 605 } 606 607 /** 608 * Returns the language-specific metadata on the specified class. 609 * 610 * @param cm The class to return the metadata on. 611 * @return The metadata. 612 */ 613 protected RdfClassMeta getRdfClassMeta(ClassMeta<?> cm) { 614 return ctx.getRdfClassMeta(cm); 615 } 616 617 /** 618 * Returns the language-specific metadata on the specified bean property. 619 * 620 * @param bpm The bean property to return the metadata on. 621 * @return The metadata. 622 */ 623 protected XmlBeanPropertyMeta getXmlBeanPropertyMeta(BeanPropertyMeta bpm) { 624 return ctx.getXmlBeanPropertyMeta(bpm); 625 } 626 627 /** 628 * Collections should be serialized and parsed as loose collections. 629 * 630 * @see RdfParser.Builder#looseCollections() 631 * @return 632 * <jk>true</jk> if collections of resources are handled as loose collections of resources in RDF instead of 633 * resources that are children of an RDF collection (e.g. Sequence, Bag). 634 */ 635 protected final boolean isLooseCollections() { return ctx.isLooseCollections(); } 636 637 /** 638 * Trim whitespace from text elements. 639 * 640 * @see RdfParser.Builder#trimWhitespace() 641 * @return 642 * <jk>true</jk> if whitespace in text elements will be automatically trimmed. 643 */ 644 protected final boolean isTrimWhitespace() { return ctx.isTrimWhitespace(); } 645}