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

📄 bimldaofile.java

📁 为了下东西 随便发了个 datamining 的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			throw new BIMLException("Error getting or parsing the BIML file with name: " + aBimlName, e);
		}
		
	}

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


			File aFile = new File(aDirname, aBimlName);
			BufferedReader aBufferedReader = new BufferedReader(new FileReader(aFile));
			StringBuffer aFileContent = new StringBuffer();
			String aLine = null;
			while ((aLine = aBufferedReader.readLine()) != null)
			{
			
				aFileContent.append(aLine + "\n");
			}
			
			StringReader aStringReader = new StringReader(aFileContent.toString());
			
			return aStringReader;
				
		} 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);
		}
		
	}	
	
	public Reader getBIMLReaderById(String aBimlId, String aType) throws BIMLException
	{
		String aBimlName = Constants.BIML_FILE_PREFIX + aBimlId + "_" + aType + ".xml";
		return getBIMLReaderByName(aBimlName);		
	}	
*/

	/**
	 * 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.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBIMLStringByName(String)
	 */
	public String getBIMLStringByName(String aBimlName) throws BIMLException
	{
		BufferedReader aBufferedReader = null;
		try {
			String aDirname = SysConfig.getProperty(Constants.BIML_REPOSITORY_KEY);
			File aDir = new File(aDirname, "activate");

			File aBIMLFile = new File(aDir, aBimlName);
			if (!aBIMLFile.exists())
			{
				aDir = new File(aDirname, "inprogress");
				aBIMLFile = new File(aDir, aBimlName);
				if (!aBIMLFile.exists())
				{
					throw new BIMLException("BIML file " + aBimlName + " does not exist");
				}
			}



			aBufferedReader = new BufferedReader(new FileReader(aBIMLFile));
			StringBuffer aFileContent = new StringBuffer();
			String aLine = null;
			while ((aLine = aBufferedReader.readLine()) != null)
			{
			
				aFileContent.append(aLine + "\n");
			}
		
			return aFileContent.toString();
				
		} catch (Exception e) {
			SysLog.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);
		}finally
		{
			try
			{
				aBufferedReader.close();
			}catch(IOException e)
			{}
		}
		
	}	

	/**
	 * Find the BIML by the specified ID and transform it using the input XSLT style
	 * sheet. It finds the file with ID aBimlId in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "in progress" subdirectories. Then it uses the file with the
	 * name aBIMLStyleSheet for the XSLT transformation. The style sheet should be 
	 * within the same directory of the BIML file.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBIMLStringById(String, String)
	 */
	public String getBIMLFileNameById(String aBimlId, String aType)
	{
		return Constants.BIML_FILE_PREFIX + aBimlId + "_" + aType + ".xml";
	}
	

	/**
	 * Find the BIML by the specified ID and transform it using the input XSLT style
	 * sheet. It finds the file with ID aBimlId in
	 * the BIML repository directory. The "activate" subdirectories is searched first
	 * followed by the "in progress" subdirectories. Then it uses the file with the
	 * name aBIMLStyleSheet for the XSLT transformation. The style sheet should be 
	 * within the same directory of the BIML file.
	 * 
	 * @see hk.hku.eti.bi.bdm.BIMLDAO#getBIMLStringById(String, String)
	 */
	public String getBIMLStringById(String aBimlId, String aType) throws BIMLException
	{
		return getBIMLStringByName(getBIMLFileNameById(aBimlId, aType));		
	}	
	
	
	/**
	 * 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(), aBimlName.length()-8);			
			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) {
			e.printStackTrace();
			SysLog.error("Load Case "+ aCaseId + " fail!");
		}

		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();

⌨️ 快捷键说明

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