⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localservice.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			_systemConfig.removeRepository(repositoryId);		}		synchronized (_repositoryMap) {			_repositoryMap.remove(repositoryId);		}	}	/**	 * Adds a new repository definition to this LocalService and	 * creates a SesameRepository object for it.	 *	 * @param repConfig A repository configuration.	 * @return A SesameRepository matching the supplied configuration.	 * @exception ConfigurationException If the supplied configuration	 * cannot be added for some reason.	 **/	public LocalRepository createRepository(RepositoryConfig repConfig)		throws ConfigurationException	{		addRepository(repConfig);		try {			return (LocalRepository)getRepository(repConfig.getRepositoryId());		}		catch (UnknownRepositoryException e) {			// This exception should never be thrown			throw new RuntimeException("Program error", e);		}	}	protected static SessionContext _getSessionContext() {		SessionContext sc = SessionContext.getContext();		if (sc == null) {			sc = new SessionContext();			sc.bLogged = false;			sc.VersionState = -1;			SessionContext.setContext(sc);		}		return sc;	}		/**	 * Adds a new repository with the supplied ID to this LocalService and	 * creates a LocalRepository object for it. The repository will be a world-readable/writeable, 	 * synchronized in-memory repository, without persistence.	 * 	 * @param repositoryId the ID for this repository.	 * @param inferencing indicates if the repository should be an inferencing repository.	 * 	 * @return A SesameRepository using the in-memory sail, and a synchronization layer.	 * 	 * @exception ConfigurationException If a repository with the supplied ID	 * cannot be added for some reason, e.g. if the ID was already in use.	 */	public LocalRepository createRepository(String repositoryId, boolean inferencing) 		throws ConfigurationException 	{		RepositoryConfig config = new RepositoryConfig(repositoryId);		SailConfig syncSail;		SailConfig memSail;				if (inferencing) {			syncSail = new SailConfig("org.openrdf.sesame.sailimpl.sync.SyncRdfSchemaRepository");			memSail = new SailConfig("org.openrdf.sesame.sailimpl.memory.RdfSchemaRepository");		}		else {			syncSail = new SailConfig("org.openrdf.sesame.sailimpl.sync.SyncRdfRepository");			memSail = new SailConfig("org.openrdf.sesame.sailimpl.memory.RdfRepository");		}		config.addSail(syncSail);		config.addSail(memSail);		config.setWorldReadable(true);		config.setWorldWriteable(true);				return createRepository(config);	}	private LocalRepository _createRepository(RepositoryConfig repConfig)		throws ConfigurationException	{		try {			// Create a new Sail for the bottom of the Sail stack			List sailList = repConfig.getSailList();			ListIterator sailIter = sailList.listIterator(sailList.size());			SailConfig sailConfig = (SailConfig)sailIter.previous();			String className = sailConfig.getSailClass();			Class sailClass = Class.forName(className);			Sail topSail = null;			try {				topSail = (Sail)sailClass.newInstance();			}			catch (ClassCastException e) {				throw new ConfigurationException(sailClass + " does not implement Sail interface.");			}			topSail.initialize(sailConfig.getConfigParameters());			// Add any stacked Sails on top			while (sailIter.hasPrevious()) {				sailConfig = (SailConfig)sailIter.previous();				className = sailConfig.getSailClass();				sailClass = Class.forName(className);				StackedSail stackedSail = null;				try {					stackedSail = (StackedSail)sailClass.newInstance();				}				catch (ClassCastException e) {					throw new ConfigurationException(className + " is not a StackedSail.");				}				stackedSail.setBaseSail(topSail);				stackedSail.initialize(sailConfig.getConfigParameters());				topSail = stackedSail;			}			if (topSail instanceof RdfSource) {				return new LocalRepository(repConfig.getRepositoryId(),						(RdfSource)topSail, this);			}			else {				throw new ConfigurationException(						"top Sail class does not implement RdfSource");			}		}		catch (ClassNotFoundException e) {			throw new ConfigurationException(e);		}		catch (InstantiationException e) {			throw new ConfigurationException(e);		}		catch (IllegalAccessException e) {			throw new ConfigurationException(e);		}		catch (SailInitializationException e) {			throw new ConfigurationException(e);		}	}	/**	 * Shuts down all repositories that are configured for this service.	 **/	public void shutDown() {		synchronized (_repositoryMap) {			Iterator iter = _repositoryMap.values().iterator();			while (iter.hasNext()) {				LocalRepository rep = (LocalRepository)iter.next();				rep.shutDown();			}			_repositoryMap.clear();		}	}	/**	 * Checks whether the user that has logged in has read access on the	 * specified repository. If no user has been logged in, this method will	 * only return <tt>true</tt> if the repository is world-readable.	 *	 * @param repository A repository ID.	 * @return <tt>true</tt> if the user has read access, <tt>false</tt>	 * otherwise.	 **/	public boolean hasReadAccess(String repository)		throws UnknownRepositoryException	{		RepositoryConfig repConfig = _systemConfig.getRepositoryConfig(repository);		if (repConfig == null) {			throw new UnknownRepositoryException("Unknown repository: " + repository);		}		if (repConfig.isWorldReadable()) {			// repository is world-readable			return true;		}		// Not world-readable, check if user has access		String username = _getSessionContext().user;		UserInfo userInfo = _systemConfig.getUserInfo(username);		if (userInfo != null) {			return userInfo.hasReadAccess(repConfig.getRepositoryId());		}		return false;	}	/**	 * Checks whether the user that has logged in has write access on the	 * specified repository. If no user has been logged in, this method will	 * only return <tt>true</tt> if the repository is world-writeable.	 *	 * @param repository A repository ID.	 * @return <tt>true</tt> if the user has write access, <tt>false</tt>	 * otherwise.	 **/	public boolean hasWriteAccess(String repository)		throws UnknownRepositoryException	{		RepositoryConfig repConfig = _systemConfig.getRepositoryConfig(repository);		if (repConfig == null) {			throw new UnknownRepositoryException("Unknown repository: " + repository);		}		if (repConfig.isWorldWriteable()) {			// repository is world-writeable			return true;		}		// Not world-writeable, check if user has access		String username = _getSessionContext().user;		UserInfo userInfo = _systemConfig.getUserInfo(username);		if (userInfo != null) {			return userInfo.hasWriteAccess(repConfig.getRepositoryId());		}		return false;	}		public File getTmpDir()	throws IOException	{		String tmpDirStr = _systemConfig.getTmpDir();		File tmpDir = null;				if (tmpDirStr != null) {			tmpDir = new File(SesameServer.getBaseDir(), tmpDirStr);						if (!tmpDir.exists()) {				boolean tmpDirCreated = tmpDir.mkdirs();								if (!tmpDirCreated) {					throw new IOException("Unable to create directory " + tmpDir.getAbsolutePath());				}			}		}				return tmpDir;	}		/**	 * Creates a new temporary file with the supplied prefix and suffix.	 * The temporary file will be automatically deleted when the JVM	 * shuts down, but one is encouraged to delete it as soon as the file	 * is not needed anymore.	 *	 * @param prefix The prefix string to be used in generating the file's	 * name; must be at least three characters long.	 * @param suffix The suffix string to be used in generating the file's	 * name; may be null, in which case the suffix ".tmp" will be used	 * @return A new tmp file, or null if no tmp directory has been configured.	 * @throws IOException If an I/O error occured during the creation of the	 * tmp file.	 **/	public File createTmpFile(String prefix, String suffix)	throws IOException	{		File tmpDir = getTmpDir();		File tmpFile = null;				if (tmpDir != null) {			tmpFile = File.createTempFile(prefix, suffix, tmpDir);			tmpFile.deleteOnExit();		}				return tmpFile;	}}

⌨️ 快捷键说明

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