Index: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java (revision 1679973) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java (working copy) @@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import static org.apache.jackrabbit.oak.api.Type.STRING; +import static java.util.Collections.emptyList; import static org.apache.jackrabbit.oak.api.Type.STRINGS; import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE; import static org.apache.jackrabbit.oak.plugins.name.NamespaceConstants.NAMESPACES_PATH; @@ -35,13 +35,13 @@ import javax.annotation.Nonnull; import javax.jcr.RepositoryException; -import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; import org.apache.jackrabbit.oak.api.Tree; import org.apache.jackrabbit.oak.plugins.tree.RootFactory; import org.apache.jackrabbit.oak.plugins.tree.TreeFactory; import org.apache.jackrabbit.oak.spi.state.NodeBuilder; import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.apache.jackrabbit.oak.util.TreeUtil; /** * Name mapper with no local prefix remappings. URI to prefix mappings @@ -71,18 +71,26 @@ } } - protected final Tree namespaces; - protected final Tree nsdata; + private final Root root; + private Tree namespaces; + private Tree nsdata; public GlobalNameMapper(Root root) { - this.namespaces = root.getTree(NAMESPACES_PATH); - this.nsdata = namespaces.getChild(REP_NSDATA); + this.root = root; + init(); } public GlobalNameMapper(NodeState root) { this(RootFactory.createReadOnlyRoot(root)); } + private void init() { + if (root != null) { + this.namespaces = root.getTree(NAMESPACES_PATH); + this.nsdata = namespaces.getChild(REP_NSDATA); + } + } + public GlobalNameMapper(Map mappings) { NodeBuilder forward = EMPTY_NODE.builder(); NodeBuilder reverse = EMPTY_NODE.builder(); @@ -98,6 +106,7 @@ reverse.setProperty(REP_PREFIXES, mappings.keySet(), STRINGS); reverse.setProperty(REP_URIS, mappings.values(), STRINGS); + this.root = null; this.namespaces = TreeFactory.createReadOnlyTree(forward.getNodeState()); this.nsdata = TreeFactory.createReadOnlyTree(reverse.getNodeState()); } @@ -165,12 +174,7 @@ return uri; } - PropertyState mapping = nsdata.getProperty(encodeUri(uri)); - if (mapping != null && mapping.getType() == STRING) { - return mapping.getValue(STRING); - } - - return null; + return getNsData(encodeUri(uri)); } @CheckForNull @@ -179,12 +183,28 @@ return prefix; } - PropertyState mapping = namespaces.getProperty(prefix); - if (mapping != null && mapping.getType() == STRING) { - return mapping.getValue(STRING); + return getNamespacesProperty(prefix); + } + + protected String getNamespacesProperty(String prefix) { + return TreeUtil.getString(namespaces, prefix); + } + + private String getNsData(String uri) { + return TreeUtil.getString(nsdata, uri); + } + + protected Iterable getPrefixes() { + Iterable prefs = TreeUtil.getStrings(nsdata, REP_PREFIXES); + if (prefs != null) { + return prefs; + } else { + return emptyList(); } + } - return null; + protected void onSessionRefresh() { + init(); } } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java (revision 1679973) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java (working copy) @@ -18,14 +18,12 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import static org.apache.jackrabbit.oak.api.Type.STRING; import java.util.Map; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; /** @@ -61,12 +59,11 @@ int colon = oakName.indexOf(':'); if (colon > 0) { String oakPrefix = oakName.substring(0, colon); - PropertyState mapping = namespaces.getProperty(oakPrefix); - if (mapping == null || mapping.getType() != STRING) { + String uri = getNamespacesProperty(oakPrefix); + if (uri == null) { throw new IllegalStateException( "No namespace mapping found for " + oakName); } - String uri = mapping.getValue(STRING); for (Map.Entry entry : local.entrySet()) { if (uri.equals(entry.getValue())) { @@ -123,10 +120,9 @@ } // Check that a global mapping is present and not remapped - PropertyState mapping = namespaces.getProperty(jcrPrefix); + String mapping = getNamespacesProperty(jcrPrefix); if (mapping != null - && mapping.getType() == STRING - && local.values().contains(mapping.getValue(STRING))) { + && local.values().contains(mapping)) { return null; } } Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java (revision 1679973) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java (working copy) @@ -43,6 +43,7 @@ import javax.jcr.nodetype.ConstraintViolationException; import com.google.common.collect.ImmutableMap; + import org.apache.jackrabbit.oak.api.AuthInfo; import org.apache.jackrabbit.oak.api.CommitFailedException; import org.apache.jackrabbit.oak.api.ContentSession; @@ -52,6 +53,7 @@ import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.jcr.observation.EventFactory; import org.apache.jackrabbit.oak.jcr.session.RefreshStrategy; +import org.apache.jackrabbit.oak.jcr.session.RefreshStrategy.Composite; import org.apache.jackrabbit.oak.jcr.session.SessionStats; import org.apache.jackrabbit.oak.jcr.session.SessionStats.Counters; import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation; @@ -79,7 +81,7 @@ private final SecurityProvider securityProvider; private final RefreshAtNextAccess refreshAtNextAccess = new RefreshAtNextAccess(); private final SaveCountRefresh saveCountRefresh; - private final RefreshStrategy refreshStrategy; + private final Composite refreshStrategy; private final Root root; private final IdentifierManager idManager; @@ -135,7 +137,7 @@ this.contentSession = checkNotNull(contentSession); this.securityProvider = checkNotNull(securityProvider); this.saveCountRefresh = new SaveCountRefresh(checkNotNull(threadSaveCount)); - this.refreshStrategy = RefreshStrategy.Composite.create( + this.refreshStrategy = Composite.create( checkNotNull(refreshStrategy), refreshAtNextAccess, saveCountRefresh); this.root = contentSession.getLatestRoot(); this.idManager = new IdentifierManager(root); @@ -885,4 +887,8 @@ } } + public Composite getRefreshStrategy() { + return refreshStrategy; + } + } Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java (revision 1679973) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java (working copy) @@ -63,7 +63,9 @@ private final RefreshStrategy[] refreshStrategies; - public static RefreshStrategy create(RefreshStrategy... refreshStrategies) { + private RefreshObserver observer; + + public static Composite create(RefreshStrategy... refreshStrategies) { ArrayList strategies = newArrayList(); for (RefreshStrategy strategy : refreshStrategies) { if (strategy instanceof Composite) { @@ -110,6 +112,9 @@ for (RefreshStrategy refreshStrategy : refreshStrategies) { refreshStrategy.refreshed(); } + if (observer != null) { + observer.refreshed(); + } } @Override @@ -122,6 +127,10 @@ } return sb.toString(); } + + public void setObserver(RefreshObserver observer) { + this.observer = observer; + } } /** @@ -207,4 +216,8 @@ } } + public interface RefreshObserver { + void refreshed(); + } + } Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java (revision 1679973) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java (working copy) @@ -131,6 +131,7 @@ namespaces, delegate.getIdManager()); this.valueFactory = new ValueFactoryImpl( delegate.getRoot(), namePathMapper); + delegate.getRefreshStrategy().setObserver(this.namespaces); } public final Map getAttributes() { Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionNamespaces.java =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionNamespaces.java (revision 1679973) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionNamespaces.java (working copy) @@ -18,9 +18,6 @@ import static com.google.common.collect.Iterables.toArray; import static com.google.common.collect.Sets.newHashSet; -import static java.util.Collections.emptyList; -import static org.apache.jackrabbit.oak.api.Type.STRINGS; -import static org.apache.jackrabbit.oak.plugins.name.NamespaceConstants.REP_PREFIXES; import java.util.HashSet; import java.util.Locale; @@ -31,8 +28,8 @@ import javax.jcr.NamespaceException; import javax.jcr.Session; -import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.api.Root; +import org.apache.jackrabbit.oak.jcr.session.RefreshStrategy.RefreshObserver; import org.apache.jackrabbit.oak.namepath.LocalNameMapper; import org.apache.jackrabbit.util.XMLChar; @@ -44,7 +41,7 @@ * re-mappings and takes a snapshot of the namespace registry when initialized * (see JCR 2.0 specification, section 3.5.1). */ -class SessionNamespaces extends LocalNameMapper { +class SessionNamespaces extends LocalNameMapper implements RefreshObserver { SessionNamespaces(@Nonnull Root root) { super(root, Maps.newHashMap()); @@ -97,11 +94,7 @@ */ synchronized String[] getNamespacePrefixes() { // get registered namespace prefixes - Iterable global = emptyList(); - PropertyState property = nsdata.getProperty(REP_PREFIXES); - if (property != null && property.getType() == STRINGS) { - global = property.getValue(STRINGS); - } + Iterable global = getPrefixes(); // unless there are local remappings just use the registered ones if (local.isEmpty()) { @@ -181,4 +174,9 @@ local.clear(); } + @Override + public void refreshed() { + onSessionRefresh(); + } + }