entityinstallationaction.java
来自「CRM源码This file describes some issues tha」· Java 代码 · 共 1,805 行 · 第 1/5 页
JAVA
1,805 行
* Make checking confuig structure in database * @return checking status (<code>true</code> - ok) */ private boolean makeChecking() { boolean status = false; long time = System.currentTimeMillis(); try { Collection list = getEntityViewConfigManager().getEntityViewConfigs(); if( !list.isEmpty() && ( ( Entity ) list.iterator().next() ) != null ) { status = true; } INFO( "checking complete [count=" + list.size() + "]" ); } catch( Exception ex ) { INFO( "checking complete [error=" + ex.getMessage() + "]" ); } INFO( "Checking process last: " + ( System.currentTimeMillis() - time ) / 1000 + ", status: " + status ); return status; } /** * Parse entity xml configs and create array of EntityConfig objects * @return array of EntityConfig objects */ private EntityConfig[] parseEntities() { // get list of files File[] files = entityDirFile.listFiles( new FilenameFilter() { public boolean accept( File dir, String name ) { String ext = CONFIG_FILES_EXTENSION; if( name.substring( name.length() - ext.length() ).equals( ext ) ) { return true; } else { return false; } } } ); if( files.length == 0 ) { throw new IllegalStateException( "Can't find any XML configs in path '" + entityDirFile.getAbsolutePath() + "'" ); } // initialise array of EntityConfig objects EntityConfig[] entityConfigArray = new EntityConfig[files.length]; // cycle read entity config XML files for( int i = 0; i < files.length; i++ ) { entityConfigArray[i] = parseEntity( files[i] ); } return entityConfigArray; } /** * Parse entity xml config * @param file XML config file * @return EntityConfig object */ private EntityConfig parseEntity( File file ) { String fileName = file.getName(); EntityConfig entityConfig = null; try { // read entity config XML file INFO( " read from " + file.getCanonicalPath() ); // make XSLT ByteArrayOutputStream baos = ( ByteArrayOutputStream ) transletWrapper.transform( entityXslFile, file, null ); // write log if( entityOutXslFile != null ) { try { File outFile = new File( entityOutXslFile, fileName ); FileOutputStream fos = new FileOutputStream( outFile ); fos.write( baos.toByteArray() ); fos.close(); } catch( SecurityException ex ) { ERROR( ex ); } catch( IOException ex ) { ERROR( ex ); } } // build EntityConfig object (make binding) Document document = xmlWrapper.getDocument( new ByteArrayInputStream( baos.toByteArray() ), false ); entityConfig = ( EntityConfig ) xmlBind.xmlToJava( EntityConfig.class, document ); // write log if( entityOutBindFile != null ) { try { File outFile = new File( entityOutBindFile, fileName ); FileOutputStream fos = new FileOutputStream( outFile ); xmlBind.javaToXml( entityConfig, new PrintWriter( new OutputStreamWriter( fos, "UTF-8" ) ) ); fos.close(); } catch( SecurityException ex ) { ERROR( ex ); } catch( IOException ex ) { ERROR( ex ); } } } catch( IOException ex ) { ERROR( ex ); throw new GenericSystemException( "IO exception. Can't process parsing entity from file '" + fileName + "': " + ex.getMessage(), ex ); } return entityConfig; } private Map<Document, String> entityDocuments = new HashMap<Document, String>(); private Map<String, Element> entityElements = new HashMap<String, Element>(); private Map<String, Element> partialEntityElements = new HashMap<String, Element>(); private EntityConfig[] parseEntities0() { processPartialEntities(); List<EntityConfig> entityConfigs = new ArrayList<EntityConfig>(); // Do entity transformation Templates templates = transletWrapper.loadTemplate( AbstractPropertyFactory.loadResourceAsStream(getClass(), ENTITY_XSL_RESOURCE)); DocumentBuilder builder = xmlWrapper.getDOMParser(false); for (Document document : entityDocuments.keySet()) { NodeList entities = document.getDocumentElement().getElementsByTagName(EntityHelper.ENTITY_TAG); if(entities.getLength() == 0) continue; DEBUG("Applying xslt transformation to xml document from '" + entityDocuments.get(document) + "'"); DOMResult result = new DOMResult(builder.newDocument()); transletWrapper.transform(new DOMSource(document), result, templates, null); EntityConfig entityConfig = (EntityConfig) xmlBind.xmlToJava(EntityConfig.class, result.getNode()); entityConfigs.add(entityConfig); } EntityConfig[] answer = (EntityConfig[]) entityConfigs.toArray(new EntityConfig[ entityElements.size() ]); entityElements.clear(); entityDocuments.clear(); return answer; } private void processPartialEntities() { List<String> partialNames = new ArrayList<String>(partialEntityElements.keySet()); if(!partialNames.isEmpty()){ Collections.sort(partialNames); for (String partialName : partialNames) { INFO("Processing partial entity " + partialName); String[] names = StringHelper.split(partialName, EntityHelper.NAME_SEPARATOR); String name = names[0]; if(!entityElements.containsKey(name)) throw new GenericSystemException( "Cannot process '" + partialName + "'. Parent entity '" + name + "' is undefined"); Element element = entityElements.get(name); boolean lastReached = false; for (int i = 1; i < names.length; i++) { name = names[i]; boolean childFound = false; lastReached = i == (names.length - 1); NodeList childs = element.getElementsByTagName(EntityHelper.ENTITY_TAG); for(int j = 0; j < childs.getLength(); j++){ Element _element = (Element)childs.item(j); if(name.equals(_element.getAttribute(EntityHelper.NAME_ATTRIBUTE))){ element = _element; childFound = true; break; } } if (!childFound && !lastReached) throw new GenericSystemException("Cannot find entity '" + StringHelper.join(Arrays.copyOfRange(names, 0, i + 1), EntityHelper.NAME_SEPARATOR) + "' to process partial entity '" + partialName + "'"); } Element partialElem = partialEntityElements.get(partialName); partialElem = (Element)partialElem.getParentNode().removeChild(partialElem); partialElem = (Element)element.getOwnerDocument().importNode(partialElem, true); partialElem.setAttribute(EntityHelper.NAME_ATTRIBUTE, names[names.length - 1]); if (lastReached) { element.appendChild(partialElem); } else { element.getParentNode().replaceChild(partialElem, element); } } } partialEntityElements.clear(); } private void parseEntityDir(File entityDirFile) { INFO("Parse entity directory " + entityDirFile.getAbsolutePath()); // get list of files File[] files = entityDirFile.listFiles( new FilenameFilter() { public boolean accept( File dir, String name ) { return name.substring(name.length() - CONFIG_FILES_EXTENSION.length()).equals(CONFIG_FILES_EXTENSION); } } ); String dirPath = entityDirFile.getAbsolutePath(); if (files.length == 0) { //throw new IllegalStateException( "Can't find any XML configs in directory '" + dirPath + "'" ); WARN("Can't find any XML configs in directory '" + dirPath + "'"); return; } Map<String, Element> _entityNodes = new HashMap<String, Element>(); Map<String, Element> _partialEntityNodes = new HashMap<String, Element>(); // cycle read entity config XML files for (File file : files) { String filePath = file.getAbsolutePath(); INFO(" read from " + filePath); Document document = xmlWrapper.getDocument(file, false); NodeList nodes = document.getDocumentElement().getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if(node.getNodeType() != Node.ELEMENT_NODE) continue; Element element = (Element)node; String name = element.getAttribute(EntityHelper.NAME_ATTRIBUTE); if (name.contains(EntityHelper.NAME_SEPARATOR)) { if(_partialEntityNodes.containsKey(name)) throw new GenericSystemException("Entity '" + name + "' was found more than once in directory " + dirPath); _partialEntityNodes.put(name, element); } else { if(_entityNodes.containsKey(name)) throw new GenericSystemException("Entity '" + name + "' was found more than once in directory " + dirPath); _entityNodes.put(name, element); } entityDocuments.put(document, dirPath); } } collectEntityNodes(_entityNodes); collectPartialEntityNodes(_partialEntityNodes); } private void collectEntityNodes(Map<String, Element> elements){ for (String name : elements.keySet()) { if(entityElements.containsKey(name)){ Element oldElem = entityElements.get(name); Document oldDoc = oldElem.getOwnerDocument(); String oldPath = entityDocuments.get(oldDoc); Document newDoc = elements.get(name).getOwnerDocument(); String newPath = entityDocuments.get(newDoc); DEBUG(MessageFormat.format("Entity '{0}' from ({1}) will be replaced with entity from ({2})", new Object[]{ name, oldPath, newPath})); oldElem.getParentNode().removeChild(oldElem); } } entityElements.putAll(elements); } private void collectPartialEntityNodes(Map<String, Element> elements){ for (String name : elements.keySet()) { if(partialEntityElements.containsKey(name)){ Element oldElem = partialEntityElements.get(name); Document oldDoc = oldElem.getOwnerDocument(); String oldPath = entityDocuments.get(oldDoc); Document newDoc = elements.get(name).getOwnerDocument(); String newPath = entityDocuments.get(newDoc); DEBUG(MessageFormat.format("Partial entity '{0}' from ({1}) will be replaced with entity from ({2})", new Object[]{ name, oldPath, newPath})); oldElem.getParentNode().removeChild(oldElem); } } partialEntityElements.putAll(elements); } /** * Parse dataschema xml configs and fill the table of Dataschema objects */ private void parseDataschemas() { File dataschemaDirFile = new File( entityDirFile, DATASCHEMA_SUB_FOLDER ); if(!dataschemaDirFile.exists() || !dataschemaDirFile.isDirectory()) return; // get list of files File[] files = dataschemaDirFile.listFiles( new FilenameFilter() { public boolean accept( File dir, String name ) { String ext = CONFIG_FILES_EXTENSION; if( name.substring( name.length() - ext.length() ).equals( ext ) ) { return true; } else { return false; } } } ); try { // cycle read dataschema config XML files for( int i = 0; i < files.length; i++ ) { INFO( " read from " + files[i].getCanonicalPath() ); // build Dataschemas object Document document = xmlWrapper.getDocument( files[i], false ); Dataschemas dss = ( Dataschemas ) xmlBind.xmlToJava( Dataschemas.class, document ); int dataschema_count = dss.getDataschemaCount(); for( int j = 0; j < dataschema_count; j++ ) { Dataschema ds = dss.getDataschema( j ); String name = ds.getName(); dataschemaNames.add( name ); dataschemaTable.put( name, ds ); } } } catch( IOException ex ) { ERROR( ex ); throw new GenericSystemException( "IO exception. Can't process parsing dataschemas: " + ex.getMessage(), ex ); } } /** * Parse chain xml configs and fill the table of Chain objects */ private void parseChains() { File chainDirFile = new File( entityDirFile, CHAIN_SUB_FOLDER ); if(!chainDirFile.exists() || !chainDirFile.isDirectory()) return; // get list of files
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?