Search in sources :

Example 1 with SecuredLiteral

use of org.apache.jena.permissions.model.SecuredLiteral in project jena by apache.

the class SecuredLiteralImpl method getInstance.

/**
	 * Get an instance of SecuredLiteral
	 * 
	 * @param securedModel
	 *            the item providing the security context.
	 * @param literal
	 *            the literal to secure
	 * @return SecuredLiteral
	 */
public static SecuredLiteral getInstance(final SecuredModel securedModel, final Literal literal) {
    if (securedModel == null) {
        throw new IllegalArgumentException("Secured securedModel may not be null");
    }
    if (literal == null) {
        throw new IllegalArgumentException("literal may not be null");
    }
    // check that literal has a securedModel.
    Literal goodLiteral = literal;
    if (goodLiteral.getModel() == null) {
        goodLiteral = securedModel.createTypedLiteral(literal.getLexicalForm(), literal.getDatatype());
    }
    final ItemHolder<Literal, SecuredLiteral> holder = new ItemHolder<>(goodLiteral);
    final SecuredLiteralImpl checker = new SecuredLiteralImpl(securedModel, holder);
    // one.
    if (goodLiteral instanceof SecuredLiteral) {
        if (checker.isEquivalent((SecuredLiteral) goodLiteral)) {
            return (SecuredLiteral) goodLiteral;
        }
    }
    return holder.setSecuredItem(new SecuredItemInvoker(literal.getClass(), checker));
}
Also used : ItemHolder(org.apache.jena.permissions.impl.ItemHolder) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) SecuredLiteral(org.apache.jena.permissions.model.SecuredLiteral) Literal(org.apache.jena.rdf.model.Literal) SecuredLiteral(org.apache.jena.permissions.model.SecuredLiteral)

Aggregations

ItemHolder (org.apache.jena.permissions.impl.ItemHolder)1 SecuredItemInvoker (org.apache.jena.permissions.impl.SecuredItemInvoker)1 SecuredLiteral (org.apache.jena.permissions.model.SecuredLiteral)1 Literal (org.apache.jena.rdf.model.Literal)1