Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addded convenience predicates for detecting types of Fedora resources
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
fcrepo-kernel/src/main/java/org/fcrepo/utils/FedoraTypesUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
package org.fcrepo.utils; | ||
|
||
import static com.google.common.collect.Collections2.transform; | ||
import static com.google.common.collect.ImmutableSet.copyOf; | ||
import static org.fcrepo.utils.FedoraJcrTypes.FEDORA_DATASTREAM; | ||
import static org.fcrepo.utils.FedoraJcrTypes.FEDORA_OBJECT; | ||
|
||
import java.util.Collection; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.nodetype.NodeType; | ||
|
||
import org.modeshape.common.SystemFailureException; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.base.Predicate; | ||
|
||
public class FedoraTypesUtils { | ||
|
||
static public Predicate<Node> isFedoraObject = new Predicate<Node>() { | ||
|
||
@Override | ||
public boolean apply(Node node) { | ||
|
||
try { | ||
return map(node.getMixinNodeTypes(), nodetype2name).contains( | ||
FEDORA_OBJECT); | ||
} catch (RepositoryException e) { | ||
throw new SystemFailureException(e); | ||
} | ||
} | ||
}; | ||
|
||
static public Predicate<Node> isFedoraDatastream = new Predicate<Node>() { | ||
|
||
@Override | ||
public boolean apply(Node node) { | ||
|
||
try { | ||
return map(node.getMixinNodeTypes(), nodetype2name).contains( | ||
FEDORA_DATASTREAM); | ||
} catch (RepositoryException e) { | ||
throw new SystemFailureException(e); | ||
} | ||
} | ||
}; | ||
|
||
static public Function<NodeType, String> nodetype2name = | ||
new Function<NodeType, String>() { | ||
|
||
@Override | ||
public String apply(NodeType t) { | ||
return t.getName(); | ||
} | ||
}; | ||
|
||
private static <From, To> Collection<To> map(From[] input, | ||
Function<From, To> f) { | ||
return transform(copyOf(input), f); | ||
} | ||
} |