001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.kernel.modeshape.utils; 019 020import java.util.concurrent.atomic.AtomicBoolean; 021 022import org.apache.jena.rdf.listeners.StatementListener; 023import org.apache.jena.rdf.model.Resource; 024import org.apache.jena.rdf.model.Statement; 025 026/** 027 * Listen to Jena statement events to see whether a certain 028 * property was added or removed. 029 * 030 * @author acoburn 031 */ 032public class PropertyChangedListener extends StatementListener { 033 034 private final Resource property; 035 036 private final AtomicBoolean changed; 037 038 /** 039 * Create a listener for a particular RDF predicate. 040 * 041 * @param property the predicate for which to watch 042 * @param changed a value to keep track of whether the value changed 043 */ 044 public PropertyChangedListener(final Resource property, final AtomicBoolean changed) { 045 this.property = property; 046 this.changed = changed; 047 } 048 049 @Override 050 public void addedStatement(final Statement s) { 051 if (property.equals(s.getPredicate())) { 052 changed.set(true); 053 } 054 } 055 056 @Override 057 public void removedStatement(final Statement s) { 058 if (property.equals(s.getPredicate())) { 059 changed.set(true); 060 } 061 } 062}