repositoryimpl.java

来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,761 行 · 第 1/5 页

JAVA
1,761
字号
            setDefaultRepositoryProperties(props);            // and store            storeRepProps(props);            return props;        } catch (Exception e) {            String msg = "failed to load repository properties";            log.debug(msg);            throw new RepositoryException(msg, e);        }    }    /**     * Stores the properties to a persistent resource in the meta filesytem.     *     * @throws RepositoryException     */    protected void storeRepProps(Properties props) throws RepositoryException {        FileSystemResource propFile = new FileSystemResource(metaDataStore, PROPERTIES_RESOURCE);        try {            propFile.makeParentDirs();            OutputStream os = propFile.getOutputStream();            try {                props.store(os, null);            } finally {                // make sure stream is closed                os.close();            }        } catch (Exception e) {            String msg = "failed to persist repository properties";            log.debug(msg);            throw new RepositoryException(msg, e);        }    }    /**     * Creates a workspace persistence manager based on the given     * configuration. The persistence manager is instantiated using     * information in the given persistence manager configuration and     * initialized with a persistence manager context containing the other     * arguments.     *     * @return the created workspace persistence manager     * @throws RepositoryException if the persistence manager could     *                             not be instantiated/initialized     */    private static PersistenceManager createPersistenceManager(File homeDir,                                                               FileSystem fs,                                                               PersistenceManagerConfig pmConfig,                                                               NodeId rootNodeId,                                                               NamespaceRegistry nsReg,                                                               NodeTypeRegistry ntReg)            throws RepositoryException {        try {            PersistenceManager pm = (PersistenceManager) pmConfig.newInstance();            pm.init(new PMContext(homeDir, fs, rootNodeId, nsReg, ntReg));            return pm;        } catch (Exception e) {            String msg = "Cannot instantiate persistence manager " + pmConfig.getClassName();            throw new RepositoryException(msg, e);        }    }    /**     * Creates a <code>SharedItemStateManager</code> or derivative.     *     * @param persistMgr     persistence manager     * @param rootNodeId     root node id     * @param ntReg          node type registry     * @param usesReferences <code>true</code> if the item state manager should use     *                       node references to verify integrity of its reference properties;     *                       <code>false</code> otherwise     * @param cacheFactory   cache factory     * @return item state manager     * @throws ItemStateException if an error occurs     */    protected SharedItemStateManager createItemStateManager(PersistenceManager persistMgr,                                                            NodeId rootNodeId,                                                            NodeTypeRegistry ntReg,                                                            boolean usesReferences,                                                            ItemStateCacheFactory cacheFactory)            throws ItemStateException {        return new SharedItemStateManager(persistMgr, rootNodeId, ntReg, true, cacheFactory);    }    //-----------------------------------------------------------< Repository >    /**     * {@inheritDoc}     */    public Session login(Credentials credentials, String workspaceName)            throws LoginException, NoSuchWorkspaceException, RepositoryException {        try {            shutdownLock.readLock().acquire();        } catch (InterruptedException e) {            throw new RepositoryException("Login lock could not be acquired", e);        }        try {            // check sanity of this instance            sanityCheck();            if (workspaceName == null) {                workspaceName = repConfig.getDefaultWorkspaceName();            }            // check if workspace exists (will throw NoSuchWorkspaceException if not)            getWorkspaceInfo(workspaceName);            if (credentials == null) {                // null credentials, obtain the identity of the already-authenticated                // subject from access control context                AccessControlContext acc = AccessController.getContext();                Subject subject = Subject.getSubject(acc);                if (subject != null) {                    return createSession(subject, workspaceName);                }            }            // login either using JAAS or our own LoginModule            AuthContext authCtx;            LoginModuleConfig lmc = repConfig.getLoginModuleConfig();            if (lmc == null) {                authCtx = new AuthContext.JAAS(repConfig.getAppName(), credentials);            } else {                authCtx = new AuthContext.Local(                        lmc.getLoginModule(), lmc.getParameters(), credentials);            }            authCtx.login();            // create session            return createSession(authCtx, workspaceName);        } catch (SecurityException se) {            throw new LoginException(                    "Unable to access authentication information", se);        } catch (javax.security.auth.login.LoginException le) {            throw new LoginException(le.getMessage(), le);        } catch (AccessDeniedException ade) {            // authenticated subject is not authorized for the specified workspace            throw new LoginException("Workspace access denied", ade);        } finally {            shutdownLock.readLock().release();        }    }    /**     * {@inheritDoc}     */    public Session login(String workspaceName)            throws LoginException, NoSuchWorkspaceException, RepositoryException {        return login(null, workspaceName);    }    /**     * {@inheritDoc}     */    public Session login() throws LoginException, RepositoryException {        return login(null, null);    }    /**     * {@inheritDoc}     */    public Session login(Credentials credentials)            throws LoginException, RepositoryException {        return login(credentials, null);    }    /**     * {@inheritDoc}     */    public String getDescriptor(String key) {        return repProps.getProperty(key);    }    /**     * {@inheritDoc}     */    public String[] getDescriptorKeys() {        String[] keys = (String[]) repProps.keySet().toArray(new String[repProps.keySet().size()]);        Arrays.sort(keys);        return keys;    }    //------------------------------------------------------< SessionListener >    /**     * {@inheritDoc}     */    public void loggingOut(SessionImpl session) {    }    /**     * {@inheritDoc}     */    public void loggedOut(SessionImpl session) {        synchronized (activeSessions) {            // remove session from active sessions            activeSessions.remove(session);        }    }    //--------------------------------------------------------< EventListener >    /**     * {@inheritDoc}     */    public void onEvent(EventIterator events) {        // check status of this instance        if (disposed) {            // ignore, repository instance has been shut down            return;        }        synchronized (repProps) {            while (events.hasNext()) {                Event event = events.nextEvent();                long type = event.getType();                if ((type & Event.NODE_ADDED) == Event.NODE_ADDED) {                    nodesCount++;                    repProps.setProperty(STATS_NODE_COUNT_PROPERTY, Long.toString(nodesCount));                }                if ((type & Event.NODE_REMOVED) == Event.NODE_REMOVED) {                    nodesCount--;                    repProps.setProperty(STATS_NODE_COUNT_PROPERTY, Long.toString(nodesCount));                }                if ((type & Event.PROPERTY_ADDED) == Event.PROPERTY_ADDED) {                    propsCount++;                    repProps.setProperty(STATS_PROP_COUNT_PROPERTY, Long.toString(propsCount));                }                if ((type & Event.PROPERTY_REMOVED) == Event.PROPERTY_REMOVED) {                    propsCount--;                    repProps.setProperty(STATS_PROP_COUNT_PROPERTY, Long.toString(propsCount));                }            }        }    }    //------------------------------------------< overridable factory methods >    /**     * Creates an instance of the {@link SessionImpl} class representing a     * user authenticated by the <code>loginContext</code> instance attached     * to the workspace configured by the <code>wspConfig</code>.     *     * @throws AccessDeniedException if the subject of the given login context     *                               is not granted access to the specified     *                               workspace     * @throws RepositoryException   If any other error occurrs creating the     *                               session.     */    protected SessionImpl createSessionInstance(AuthContext loginContext,                                                WorkspaceConfig wspConfig)            throws AccessDeniedException, RepositoryException {        return new XASessionImpl(this, loginContext, wspConfig);    }    /**     * Creates an instance of the {@link SessionImpl} class representing a     * user represented by the <code>subject</code> instance attached     * to the workspace configured by the <code>wspConfig</code>.     *     * @throws AccessDeniedException if the subject of the given login context     *                               is not granted access to the specified     *                               workspace     * @throws RepositoryException   If any other error occurrs creating the     *                               session.     */    protected SessionImpl createSessionInstance(Subject subject,                                                WorkspaceConfig wspConfig)            throws AccessDeniedException, RepositoryException {        return new XASessionImpl(this, subject, wspConfig);    }    /**     * Creates a new {@link RepositoryImpl.WorkspaceInfo} instance for     * <code>wspConfig</code>.     *     * @param wspConfig the workspace configuration.     * @return a new <code>WorkspaceInfo</code> instance.     */    protected WorkspaceInfo createWorkspaceInfo(WorkspaceConfig wspConfig) {        return new WorkspaceInfo(wspConfig);    }    //--------------------------------------------------------< inner classes >    /**     * <code>WorkspaceInfo</code> holds the objects that are shared     * among multiple per-session <code>WorkspaceImpl</code> instances     * representing the same named workspace, i.e. the same physical     * storage.     */    protected class WorkspaceInfo implements UpdateEventListener {        /**         * workspace configuration (passed in constructor)         */        private final WorkspaceConfig config;        /**         * file system (instantiated on init)         */        private FileSystem fs;        /**         * persistence manager (instantiated on init)         */        private PersistenceManager persistMgr;        /**         * item state provider (instantiated on init)         */        private SharedItemStateManager itemStateMgr;        /**         * observation dispatcher (instantiated on init)         */        private ObservationDispatcher dispatcher;        /**         * system session (lazily instantiated)         */        private SystemSession systemSession;        /**         * search manager (lazily instantiated)         */        private SearchManager searchMgr;        /**         * lock manager (lazily instantiated)         */        private LockManagerImpl lockMgr;        /**         * flag indicating whether this instance has been initialized.         */        private boolean initialized;        /**         * lock that guards the initialization of this instance         */        private final ReadWriteLock initLock =                new ReentrantWriterPreferenceReadWriteLock();        /**         * timestamp when the workspace has been determined being idle         */        private long idleTimestamp;        /**         * mutex for this workspace, used for locking transactions         */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?