?? xpathmanager.java
字號:
/**
*
* Return the BeanDescriptor object
*
* @see BeanDescriptor
* @param e -Element xml node in the repository
* @return BeanDescriptor
* @throws MappingException
*
*/
protected BeanDescriptor getBeanDescriptor(Element e) throws MappingException{
BeanDescriptor beanDescriptor = new BeanDescriptor();
String attribute = e.getAttribute("name");
logger.log(Level.INFO,Messages.format("XPathManager.beanDesc",attribute));
if(attribute == null || attribute.equals("")){
logger.throwing(getClass().getName(), "getBeanDescriptor",
new MappingException("mapping.repositoryViewNameMissing"));
throw new MappingException("mapping.repositoryViewNameMissing");
}
else
beanDescriptor.setRepositoryViewName(attribute);
attribute = e.getAttribute("table-name");
if(attribute == null || attribute.equals("")){
logger.throwing(getClass().getName(), "getBeanDescriptor",
new MappingException("mapping.noTableName",xPath));
throw new MappingException("mapping.noTableName",xPath);
}
else
beanDescriptor.setTableName(attribute);
attribute = e.getAttribute("object-name");
if(attribute == null || attribute.equals("")){
logger.throwing(getClass().getName(), "getBeanDescriptor",
new MappingException("mapping.classMapNotFound",xPath));
throw new MappingException("mapping.classMapNotFound",xPath);
}
else
beanDescriptor.setClassName(attribute);
attribute = e.getAttribute("database-name");
if(attribute == null || attribute.equals("")){
logger.throwing(getClass().getName(), "getBeanDescriptor",
new MappingException("mapping.databaseNameMissing"));
throw new MappingException("mapping.databaseNameMissing");
}
else
beanDescriptor.setDatabaseName(attribute);
logger.log(Level.FINEST,beanDescriptor.toString());
return beanDescriptor;
}
/**
*
* Return the ItemDescriptor object
*
* If the xPath is incorrect MappingException is throwed
*
* @see ItemDescriptor
* @param xPath path the repositoryView on the repository
* @return Collection of ItemDescriptor
* @throws MappingException
*
*/
protected ArrayList getItemDescriptor(String xPath,
BeanDescriptor beanDescriptor)
throws MappingException{
ArrayList itemDescriptors = new ArrayList();
PrimaryKeyMap pk = new PrimaryKeyMap();
try{
NodeList nl = XPathAPI.selectNodeList(document, xPath);
for (int i = 0 ; i < nl.getLength(); i++) {
ItemDescriptor itemDescriptor = new ItemDescriptor();
Element e =(Element)nl.item(i);
String primaryKey = e.getAttribute("primary-key");
if(primaryKey == null || primaryKey.equals("")){
logger.throwing(getClass().getName(), "getItemDescriptor()",
new MappingException("mapping.primaryKeyMissing"));
throw new MappingException("mapping.primaryKeyMissing");
}
else{
//if item is unique key
if(primaryKey.equalsIgnoreCase("yes"))
itemDescriptor.setIsPrimaryKey(true);
else
itemDescriptor.setIsPrimaryKey(false);
}
String attribute = e.getAttribute("property-name");
if(attribute == null || attribute.equals("")){
logger.throwing(getClass().getName(), "getItemDescriptor()",
new MappingException("mapping.propertyNameMissing"));
throw new MappingException("mapping.propertyNameMissing");
}
else
itemDescriptor.setPropertyName(attribute);
attribute = e.getAttribute("data-type");
if(attribute == null || attribute.equals("")){
logger.throwing(getClass().getName(), "getItemDescriptor()",
new MappingException("mapping.sqlTypeMissing"));
throw new MappingException("mapping.sqlTypeMissing");
}
else
itemDescriptor.setDataType(attribute);
attribute = e.getAttribute("column-name");
if(attribute == null || attribute.equals("")){
logger.throwing(getClass().getName(), "getItemDescriptor()",
new MappingException("mapping.columnNameMissing"));
throw new MappingException("mapping.columnNameMissing");
}
else
itemDescriptor.setColumnTableName(attribute);
if(itemDescriptor.isPrimaryKey()){
pk.addKey(itemDescriptor);
beanDescriptor.setPrimaryKeyMap(pk);
}
else
itemDescriptors.add(itemDescriptor);
}
}
catch(TransformerException e){
logger.throwing(getClass().getName(), "getItemDescriptor()",
new MappingException(e));
throw new MappingException(e);
}
finally{
return itemDescriptors;
}
}
/**
*
* Load all repositoryView object in RepositoryFactory.
*
* @throws MappingException if error occurs
*
*/
protected void loadRepositoryFactory() throws MappingException {
try{
logger.log(Level.INFO,Messages.message("XPathManager.loadingRep"));
xPath = "/repository/*";
NodeList nl = XPathAPI.selectNodeList(document, xPath);
for(int i = 0 ; i < nl.getLength() ; i++) {
Element node = (Element) nl.item(i);
RepositoryView repository = (RepositoryView)
createRepositoryView(node);
String repositoryViewName = repository.getBeanDescriptor()
.getRepositoryViewName();
repFactory.addRepository(repositoryViewName,repository);
logger.log(Level.INFO,Messages.format("XPathManager.repAdd",
repositoryViewName));
}
}
catch(TransformerException e){
logger.throwing(getClass().getName(), "loadRepositoryFactory()",
new MappingException(e));
throw new MappingException(e);
}
}
/**
*
* Return RepositoryFactory
*
* @return RepositoryFactory
*
*/
public RepositoryFactory getRepositoryFactory() {
return repFactory;
}
/**
*
* Parses the repository file specified in fileName
*
* @param fileName name of repository file
* @return Document
* @throws MappingException
* @throws SAXException
* @throws ParserConfigurationExcpetion
*
*/
protected Document parse(String fileName) throws ParserConfigurationException,SAXException,MappingException {
DocumentBuilderFactory dfactory = null;
InputSource in = null;
Document doc = null;
try{
//Set up a DOM tree to query
in = new InputSource( new FileInputStream(fileName) );
dfactory = DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(true);
doc = dfactory.newDocumentBuilder().parse(in);
}
catch(FileNotFoundException e){
logger.throwing(getClass().getName(), "parse()",
new MappingException("mapping.missingRepositoryConf",fileName));
throw new MappingException("mapping.missingRepositoryConf",fileName);
//return null;
}
catch(IOException e){
logger.throwing(getClass().getName(), "parse()",
new MappingException("mapping.missingRepositoryConf",fileName));
throw new MappingException("mapping.missingRepositoryConf",fileName);
//return null;
}
finally{
return doc;
}
}
}
/*
$Log: XPathManager.java,v $
Revision 1.16 2004/05/31 22:51:19 gmartone
changed for task 99533 (Composite Primary Key)
Revision 1.15 2004/05/20 22:44:15 gmartone
Changed for task 99073 (Coverage Javadocs)
Revision 1.14 2004/05/18 18:18:47 gmartone
resolved bug 953273 and changed javadocs
Revision 1.13 2004/04/29 22:34:46 gmartone
Task 66484 (Logging System)
Revision 1.12 2004/01/25 00:32:58 giabac
Correct banal error, otherwise it don't compile
Revision 1.11 2004/01/22 00:11:31 gmartone
Task 66484 (Logging System) added management of logs
Revision 1.10 2003/10/30 15:44:08 lechertl
cosmetic changes
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -