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

📄 bimldaofile.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	 * Find the BIML by the specified name. It finds the file with name aBimlName in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "inprogress" subdirectories. The founded BIMl is then stored
	 * in the class BICase and return it to the caller.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBICaseByName(String)
	 */
	public BICaseInfo getBICaseByName(String aBimlName) throws Exception
	{
		try {
			String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);
			Integer aStatus = null;
			boolean aHasCML = false;
			boolean aHasMML = false;

			String aBIMLId = aBimlName.substring(Constants.BIML_FILE_PREFIX.length(), Constants.BIML_FILE_PREFIX.length() + Constants.BIML_ID_PATTERN.length());			
			String aType = aBimlName.substring(aBimlName.length()-7, aBimlName.length()-4);
			File aDir = new File(aDirname, "activate");
			File aFile = new File(aDir, aBimlName);

			if (aFile!=null && aFile.exists())
			{
				aStatus = BICaseInfo.ACTIVATE;
			}
			else 
			{
			    throw new BIMLException("Error getting the BIML file with name: " + aBimlName);
			}
			
			if (aStatus != null)
			{
				File aCMLFile = new File(aDir, Constants.BIML_FILE_PREFIX + aBIMLId + "_CML.xml");
				if (aCMLFile.exists())
					aHasCML = true;
				File aMMLFile = new File(aDir, Constants.BIML_FILE_PREFIX + aBIMLId + "_MML.xml");
				if (aMMLFile.exists())
					aHasMML = true;
				System.err.println("aMMLFile="+aMMLFile.getAbsolutePath() + " hasMML="+aHasMML);
			}
			else
			{
				throw new BIMLException("Error getting the BIML file with name: " + aBimlName);
			}
			
			BufferedReader aBufferedReader = new BufferedReader(new FileReader(aFile));
			StringBuffer aFileContent = new StringBuffer();
			String aLine = null;
			while ((aLine = aBufferedReader.readLine()) != null)
			{
			
				aFileContent.append(aLine + "\n");
			}


			BICaseInfo aBICase = new BICaseInfo(aBIMLId, aType, null, aStatus, aHasCML, aHasMML, aFileContent.toString());
			return aBICase;
				
		} catch (Exception e) {
			//log.error("Error getting or parsing the BIML file with name: " + aBimlName + " Exception: " + e);
			throw new BIMLException("Error getting or parsing the BIML file with name: " + aBimlName, e);
		}
	}
	/**
	 * Find the BIML by the specified name. It finds the file with name aBimlName in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "inprogress" subdirectories. The founded BIMl is then stored
	 * in the class BICase and return it to the caller.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBICaseByName(String)
	 */
	public BICase getCaseByName(String aBimlName) throws BaseException
	{
		throw new CaseNotFoundException(aBimlName);
/*		try {
			String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);
			Integer aStatus = null;
			boolean aHasCML = false;
			boolean aHasMML = false;

			String aBIMLId = aBimlName.substring(Constants.BIML_FILE_PREFIX.length(), Constants.BIML_FILE_PREFIX.length() + Constants.BIML_ID_PATTERN.length());			
			String aType = aBimlName.substring(aBimlName.length()-7, aBimlName.length()-4);
			File aDir = new File(aDirname, "activate");
			File aFile = new File(aDir, aBimlName);
			if (aFile.exists())
			{
				aStatus = BICase.ACTIVATE;
			}
			else 
			{
				aDir = new File(aDirname, "inprogress");
				aFile = new File(aDir, aBimlName);
				if (aFile.exists())
				{
					aStatus = BICase.INPROGRESS;
				}

			}
			
			if (aStatus != null)
			{
				File aCMLFile = new File(aDir, Constants.BIML_FILE_PREFIX + aBIMLId + "_CML.xml");
				if (aCMLFile.exists())
					aHasCML = true;
				File aMMLFile = new File(aDir, Constants.BIML_FILE_PREFIX + aBIMLId + "_MML.xml");
				if (aMMLFile.exists())
					aHasMML = true;
				System.err.println("aMMLFile="+aMMLFile.getAbsolutePath() + " hasMML="+aHasMML);
			}
			else
			{
				throw new BIMLException("Error getting the BIML file with name: " + aBimlName);
			}
			
			BufferedReader aBufferedReader = new BufferedReader(new FileReader(aFile));
			StringBuffer aFileContent = new StringBuffer();
			String aLine = null;
			while ((aLine = aBufferedReader.readLine()) != null)
			{
			
				aFileContent.append(aLine + "\n");
			}


			BICase aBICase = new BICase(aBIMLId, aType, null, aStatus, aHasCML, aHasMML, aFileContent.toString());
			return aBICase;
				
		} catch (Exception e) {
			log.error("Error getting or parsing the BIML file with name: " + aBimlName + " Exception: " + e);
			throw new BIMLException("Error getting or parsing the BIML file with name: " + aBimlName, e);
		}
*/		
	}	
	
	
	/**
	 * Find the BIML by the specified ID. It finds the file with ID aBimlId in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "inprogress" subdirectories. The founded BIMl is then stored
	 * in the class BICase and return it to the caller.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBICaseById(String, String)
	 */
/*	public Case getCaseById(String aBimlId, String aType) throws BaseException
	{
		String aBimlName = Constants.BIML_FILE_PREFIX + aBimlId + "_" + aType + ".xml";
		return getCaseByName(aBimlName);		

	}	
*/	
	/**
	 * Find the BIML by the specified ID. It finds the file with ID aBimlId in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "inprogress" subdirectories. The founded BIMl is then stored
	 * in the class BICase and return it to the caller.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBICaseById(String, String)
	 */
	public BICaseInfo getBICaseById(String aBimlId, String aType) throws Exception
	{
		String aBimlName = Constants.BIML_FILE_PREFIX + aBimlId + "_" + aType + ".xml";
		return getBICaseByName(aBimlName);		
	}	

	/**
	 * Find the BIML by the specified ID. It finds the file with ID aBimlId in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "inprogress" subdirectories. The founded BIMl is then stored
	 * in the class BICase and return it to the caller.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBICaseById(String, String)
	 */
	public BICase getCaseById(String aCaseId) throws BaseException
	{
//		String aCMLName = Constants.BIML_FILE_PREFIX + aBimlId + "_CML.xml";

		BICase createCase = null;
		try {
			//System.out.println("Enter getCaseById()");
			String aCMLString = getBIMLStringById(aCaseId,"CML");
			String aPMLString = getBIMLStringById(aCaseId,"PML");
//			String aMMLString = getBIMLStringById(aCaseId,"MML");
//			String aDMLString = getBIMLStringById(aCaseId,"DML");
			
			/* Create Case instance */			
			createCase = CaseFactory.createCase(aCaseId, aCMLString);
			
			/* Create task node for case */

			/* Set operator nodes and process for case */ 
			createCase = NodeFactory.insertProcessNodes(createCase, aPMLString);

		} catch (Exception e) {
			SysLog.error(e.getMessage());
		}

		return createCase;		
	}	

	public String getBICasePathByName(String aBimlName) throws BIMLException
	{
		String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);

		File aActiveDir = new File(aDirname, "activate");
		File aInProgressDir = new File(aDirname, "inprogress");
		File aFile = null;
		
		if (aActiveDir.exists())
		{
			aFile = new File(aActiveDir, aBimlName);
		}else if(aInProgressDir.exists())
		{
			aFile = new File(aInProgressDir, aBimlName);
		}else
		{
		    return null;
		}
		
		if (aFile!=null && aFile.exists())
		{
			return aFile.getPath();
		}
		return null;
	}	
	
	
	
	public String getBICasePathById(String aBimlId, String aType) throws BIMLException
	{
		String aBimlName = Constants.BIML_FILE_PREFIX + aBimlId + "_" + aType + ".xml";
		return getBICasePathByName(aBimlName);		
	}	
	
	public String saveCase(BICase aCase)throws BaseException
	{
		String aBIMLId = aCase.getCaseID();
		if (aCase.getStatus().equals("new"))
		{
			aBIMLId = getNextId();
			aCase.setStatus(BICase.DEACTIVATE);
		}
		aCase.setCaseID(aBIMLId);		
		String aCMLString = CommonCaseHandler.getCML(aCase);
		String aPMLString = CommonCaseHandler.getPML(aCase);
		saveBIMLFile(aCMLString, "CML", aBIMLId, BICaseInfo.ACTIVATE);
		saveBIMLFile(aPMLString, "PML", aBIMLId, BICaseInfo.ACTIVATE);
		return aBIMLId;
	}	


	public class CaseFileFilter implements FilenameFilter
	{
		private String m_Pattern = new String();
		
		CaseFileFilter(String aPattern)
		{
			m_Pattern = aPattern;	
		}
		
		public void setPattern(String aPattern)
		{
			m_Pattern = aPattern;	
		}
		
		public boolean accept(File dir, String name)
		{//
			if (name.matches(m_Pattern))
				return true;
			else
				return false;
		}
		
	}

	public boolean removeCase(String aCaseID)throws BaseException
	{
		Object[] obj = {aCaseID};
		boolean result = false;
		setCaseStatus(aCaseID, BICase.REMOVE_PENDING);
		try {
			String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);
			File aDir = new File(aDirname, "activate");
			File aTrashDir = new File(aDirname, "trash");
			
			if (!aTrashDir.exists())
			{
			    aTrashDir.mkdir();
			}
			
			CaseFileFilter aFilter = new CaseFileFilter(Constants.BIML_FILE_PREFIX + aCaseID+ ".*xml");
			File [] aFiles = aDir.listFiles(aFilter);

			SimpleDateFormat format = new SimpleDateFormat("_yyyy_MM_dd_hh_mm",Locale.getDefault());
			String date = format.format(new Date());
			for (int i=0;i<aFiles.length;i++)
			{
				//				<<Mark 03/03/2005: Fix the duplicated name in trash folder				
//				File aFile = new File(aTrashDir, aFiles[i].getName());
				File aFile = new File(aTrashDir, aFiles[i].getName().substring(0,aFiles[i].getName().length()-".xml".length())+date+".xml");
//				Mark 03/03/2005: Fix the duplicated name in trash folder>>
				if (!aFiles[i].renameTo(aFile))
					
				{			
					return false;	
					
				}else
				{
					result = true;
				}
			}
			return result;			
		}catch(Exception e)
		{
			throw new SysException(e,obj);
		}
	}

	public void setCaseStatus(String aCaseID, String aStatus) throws BaseException
	{
		BICase aCase = getCaseById(aCaseID);
		if (aCase==null)
			throw new CaseNotFoundException(aCaseID);
		aCase.setStatus(aStatus);
		saveCase(aCase);
	}

	
	/**
	 * Saves the content in the FormFile to the BIML repository. The location to be
	 * stored is determined by the aStatus.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#saveBIMLFile(FormFile, String, String, Integer)
	 */
//	public String saveBIMLFile(FormFile aFormFile, String aBIMLType, String aBIMLId, Integer aStatus) throws BIMLException
//	{
//			File aTargetFile = null;
//			try {
//				String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);
//				
//				DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//				DocumentBuilder builder = factory.newDocumentBuilder();
//				if (aBIMLId == null)
//					aBIMLId = getNextId();
//
//				File aDir = null;
//				if (aStatus == null || aStatus.equals(BICaseInfo.ACTIVATE))
//				{
//					aDir = new File(aDirname, "activate");
//				}
//				else
//				{
//					aDir = new File(aDirname, "inprogress");
//				}
//				aTargetFile = new File(aDir, Constants.BIML_FILE_PREFIX + aBIMLId + "_" + aBIMLType + ".xml");
//				FileOutputStream aFOS = new FileOutputStream(aTargetFile);
//				aFOS.write(aFormFile.getFileData());

⌨️ 快捷键说明

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