use of org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver in project jackrabbit by apache.
the class SessionImpl method setNamespacePrefix.
/**
* {@inheritDoc}
*/
@Override
public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException {
super.setNamespacePrefix(prefix, uri);
// Clear name and path caches
namePathResolver = new DefaultNamePathResolver(this, true);
}
use of org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver in project jackrabbit by apache.
the class OnWorkspaceInconsistency method logError.
/**
* Logs a generic workspace inconsistency error.
*
* @param exception the exception that was thrown when working on the workspace
* @param handler the query handler.
* @param path the path of the parent node.
* @param node the parent node state.
* @param child the child node entry, for which no node state could be
* found.
* @throws RepositoryException if another error occurs not related to item
* state reading.
*/
public void logError(ItemStateException exception, QueryHandler handler, Path path, NodeState node, ChildNodeEntry child) throws RepositoryException {
if (log.isErrorEnabled()) {
NamePathResolver resolver = new DefaultNamePathResolver(handler.getContext().getNamespaceRegistry());
StringBuilder err = new StringBuilder();
err.append("Workspace inconsistency error on node ");
err.append(resolver.getJCRPath(path));
err.append(" (");
err.append(node.getNodeId());
err.append(") with child ");
err.append(resolver.getJCRName(child.getName()));
err.append(" (");
err.append(child.getId());
err.append(").");
log.error(err.toString(), exception);
}
}
use of org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver in project jackrabbit by apache.
the class TargetImportHandler method startNamespaceContext.
/**
* Starts a local namespace context for the current XML element.
* This method is called by {@link ImportHandler} when the processing of
* an XML element starts. The given local namespace mappings have been
* recorded by {@link ImportHandler#startPrefixMapping(String, String)}
* for the current XML element.
*
* @param mappings local namespace mappings
*/
public final void startNamespaceContext(Map<String, String> mappings) {
nsContext = new NamespaceContext(nsContext, mappings);
resolver = new DefaultNamePathResolver(nsContext);
}
use of org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver in project jackrabbit by apache.
the class BatchTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
rs = helper.getRepositoryService();
si = helper.getAdminSessionInfo();
NamespaceResolver nsResolver = new AbstractNamespaceResolver() {
public String getURI(String prefix) {
return ("jcr".equals(prefix)) ? "http://www.jcp.org/jcr/1.0" : prefix;
}
public String getPrefix(String uri) {
return ("http://www.jcp.org/jcr/1.0".equals(uri)) ? "jcr" : uri;
}
};
resolver = new DefaultNamePathResolver(nsResolver);
try {
rs.getNodeInfo(si, getNodeId(testPath));
} catch (RepositoryException e) {
Batch b = rs.createBatch(si, getNodeId("/"));
b.addNode(getNodeId("/"), resolver.getQName("test"), NameConstants.NT_UNSTRUCTURED, null);
rs.submit(b);
}
}
use of org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver in project jackrabbit by apache.
the class Locked method with.
/**
* Executes the method {@link #run} within the scope of a lock held on
* <code>lockable</code>.
*
* @param lockable the node where the lock is obtained from.
* @param isDeep <code>true</code> if <code>lockable</code> will be locked
* deep.
* @param timeout time in milliseconds to wait at most to aquire the lock.
* @return the object returned by {@link #run} or {@link #TIMED_OUT} if the
* lock on <code>lockable</code> could not be aquired within the
* specified timeout.
* @throws IllegalArgumentException if <code>timeout</code> is negative or
* <code>lockable</code> is not
* <i>mix:lockable</i>.
* @throws RepositoryException if {@link #run} throws an exception.
* @throws UnsupportedRepositoryOperationException
* if this repository does not support
* locking.
* @throws InterruptedException if this thread is interrupted while
* waiting for the lock on node
* <code>lockable</code>.
*/
public Object with(Node lockable, boolean isDeep, long timeout) throws UnsupportedRepositoryOperationException, RepositoryException, InterruptedException {
if (timeout < 0) {
throw new IllegalArgumentException("timeout must be >= 0");
}
Session session = lockable.getSession();
NamePathResolver resolver = new DefaultNamePathResolver(session);
Lock lock;
EventListener listener = null;
try {
// check whether the lockable can be locked at all
if (!lockable.isNodeType(resolver.getJCRName(NameConstants.MIX_LOCKABLE))) {
throw new IllegalArgumentException("Node is not lockable");
}
lock = tryLock(lockable, isDeep);
if (lock != null) {
return runAndUnlock(lock);
}
if (timeout == 0) {
return TIMED_OUT;
}
long timelimit;
if (timeout == Long.MAX_VALUE) {
timelimit = Long.MAX_VALUE;
} else {
timelimit = System.currentTimeMillis() + timeout;
}
// node is locked by other session -> register event listener if possible
if (isObservationSupported(session)) {
ObservationManager om = session.getWorkspace().getObservationManager();
listener = new EventListener() {
public void onEvent(EventIterator events) {
synchronized (this) {
this.notify();
}
}
};
om.addEventListener(listener, Event.PROPERTY_REMOVED, lockable.getPath(), false, null, null, true);
}
// the current thread when the lockable node is possibly unlocked
for (; ; ) {
synchronized (this) {
lock = tryLock(lockable, isDeep);
if (lock != null) {
return runAndUnlock(lock);
} else {
// check timeout
if (System.currentTimeMillis() > timelimit) {
return TIMED_OUT;
}
if (listener != null) {
// event listener *should* wake us up, however
// there is a chance that removal of the lockOwner
// property is notified before the node is acutally
// unlocked. therefore we use a safety net to wait
// at most 1000 millis.
this.wait(Math.min(1000, timeout));
} else {
// repository does not support observation
// wait at most 50 millis then retry
this.wait(Math.min(50, timeout));
}
}
}
}
} catch (NameException e) {
throw new RepositoryException(e);
} finally {
if (listener != null) {
session.getWorkspace().getObservationManager().removeEventListener(listener);
}
}
}
Aggregations