entityinstallationaction.java
来自「CRM源码This file describes some issues tha」· Java 代码 · 共 1,805 行 · 第 1/5 页
JAVA
1,805 行
/* * Copyright 2006-2007 Queplix Corp. * * Licensed under the Queplix Public License, Version 1.1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.queplix.core.modules.config.actions;import com.queplix.core.error.GenericSystemException;import com.queplix.core.jxb.entity.Chain;import com.queplix.core.jxb.entity.ChainTable;import com.queplix.core.jxb.entity.Chainref;import com.queplix.core.jxb.entity.Chains;import com.queplix.core.jxb.entity.Dataschema;import com.queplix.core.jxb.entity.Dataschemas;import com.queplix.core.jxb.entity.Dataset;import com.queplix.core.jxb.entity.Dsref;import com.queplix.core.jxb.entity.Efield;import com.queplix.core.jxb.entity.Entity;import com.queplix.core.jxb.entity.EntityConfig;import com.queplix.core.jxb.entity.Fkeys;import com.queplix.core.jxb.entity.Listref;import com.queplix.core.jxb.entity.Nods;import com.queplix.core.jxb.entity.Ref;import com.queplix.core.jxb.entity.types.DataSType;import com.queplix.core.jxb.entity.types.RefSType;import com.queplix.core.jxb.entity.types.ControlSType;import com.queplix.core.modules.config.ejb.EntityViewConfigManager;import com.queplix.core.modules.config.ejb.EntityViewConfigManagerHome;import com.queplix.core.modules.config.error.UnknownEfieldException;import com.queplix.core.modules.config.error.UnknownEntityException;import com.queplix.core.modules.config.utils.EntityDdobjectInfoVO;import com.queplix.core.modules.config.utils.EntityFieldInfoVO;import com.queplix.core.modules.config.utils.EntityHelper;import com.queplix.core.modules.config.utils.EntitySchema;import com.queplix.core.modules.config.utils.EntitySchemaFactory;import com.queplix.core.modules.services.Action;import com.queplix.core.utils.JNDINames;import com.queplix.core.utils.StringHelper;import com.queplix.core.utils.dao.AbstractPropertyFactory;import com.queplix.core.utils.xml.TransletWrapper;import com.queplix.core.utils.xml.XMLBinding;import com.queplix.core.utils.xml.XMLFactory;import com.queplix.core.utils.xml.XMLWrapper;import org.apache.regexp.RE;import org.apache.regexp.RESyntaxException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import javax.xml.parsers.DocumentBuilder;import javax.xml.transform.Templates;import javax.xml.transform.dom.DOMResult;import javax.xml.transform.dom.DOMSource;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileOutputStream;import java.io.FilenameFilter;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.io.Serializable;import java.rmi.RemoteException;import java.text.MessageFormat;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;/** * <p>Action wich parses config XML files and fills EntityViewConfig EJBs</p> * @author [ALB] Baranov Andrey * @version $Revision: 1.2 $ $Date: 2005/12/27 18:47:15 $ */public class EntityInstallationAction extends Action { // constants public static final String CONFIG_FILES_EXTENSION = "xml"; public static final String DATASCHEMA_SUB_FOLDER = "dataschema"; public static final String CHAIN_SUB_FOLDER = "chain"; public static final String ENTITY_XSL_RESOURCE = "xslt/entity.xsl"; public static final String ENTITY_VAR = "\\$entity"; public static final String DBOBJECT_VAR = "\\$dbobject"; public static final String ENTITY_XML_DIRS_PARAM = "entityXmlDirs"; // variables private Map<String, Entity> entityTable = new HashMap<String, Entity>(); private List<String> entityNames = new ArrayList<String>(); private Map<String, Dataschema> dataschemaTable = new HashMap<String, Dataschema>(); private List<String> dataschemaNames = new ArrayList<String>(); private List<Chain> chainList = new ArrayList<Chain>(); private Map<String, EntityDdobjectInfoVO> dbInfoTable = new HashMap<String, EntityDdobjectInfoVO>(); private XMLWrapper xmlWrapper; private XMLBinding xmlBind; // config params private Integer checkOnly; private String xmldir; private String logdir; private String xmlfile; private File entityDirFile; private File entityXslFile; private File entityOutXslFile; private File entityOutBindFile; private File entityOutDeployFile; private File entityXmlFile; // XSL translet implementation. private TransletWrapper transletWrapper; // initial entity in database private int INITIAL_ENTITY_SIZE = 0; // max entity config id private int ENTITY_COUNTER = 0; // current version private long CUR_VERSION = System.currentTimeMillis();// --------------------- PUBLIC METHODS -------------------- /* * No javadoc * @see Action#perform */ public Serializable perform() { // // Read parameters // this.checkOnly = getContext().getParamAsInt( "check" ); this.xmldir = getContext().getParamAsString( "xmldir" ); this.logdir = getContext().getParamAsString( "logdir" ); this.xmlfile = getContext().getParamAsString( "xmlfile" ); String[] xmlDirs = (String[])getContext().getParameter(ENTITY_XML_DIRS_PARAM); // // Checking // if( xmldir == null && (xmlDirs == null || xmlDirs.length == 0)) { throw new NullPointerException( "Parameter XML dir is NULL" ); } init(); initLogDirs(); // // Config file initialization // if(xmldir != null && (xmlDirs == null || xmlDirs.length == 0)) xmlDirs = new String[]{ xmldir }; INFO( "PROCESS STARTED..." ); long time = System.currentTimeMillis(); for(int i = 0; i < xmlDirs.length; i++){ String xmlDir = xmlDirs[i]; entityDirFile = new File( xmlDir ); if(!entityDirFile.exists() || !entityDirFile.isDirectory()) throw new IllegalStateException("Bad entity config dir: " + entityDirFile.getAbsolutePath());// if( checkOnly != null && checkOnly.intValue() > 0 ) {// // do checking// makeChecking();// INFO( "Checking - ok" );//// } else if( entityXmlFile != null ) {// // do file process// fileProcess();// INFO( "Deploy process last(s): " + ( System.currentTimeMillis() - time ) / 1000 );//// } else {// // do global process// globalProcess();// } parseEntityDir(entityDirFile); INFO( "parse entity configs - ok" ); parseDataschemas(); INFO( "parse dataschema config - ok" ); parseChains(); INFO( "parse chain config - ok" ); } EntityConfig[] entityConfigs = parseEntities0(); INFO("parse all entities - ok"); buildEntityList( entityConfigs ); INFO( "build entity - ok" ); deployEntityViewConfigs(); INFO( "deploy entity configs - ok" ); INFO( "Deploy process last(s): " + ( System.currentTimeMillis() - time ) / 1000 ); INFO( "PROCESS DONE !!!" );// if( xmlfile != null ) {// entityXmlFile = new File( entityDirFile, xmlfile );// if( !entityXmlFile.exists() || !entityXmlFile.isFile() ) {// throw new IllegalStateException( "Bad entity XML file: " +// entityXmlFile.getAbsolutePath() );// } return null; } private void initLogDirs() { if( logdir != null ) { try { entityOutXslFile = new File( logdir, "entity-xsl" ); if( !entityOutXslFile.exists() || !entityOutXslFile.isDirectory() ) { entityOutXslFile.mkdirs(); } } catch( SecurityException ex ) { entityOutXslFile = null; ERROR( ex ); } try { entityOutBindFile = new File( logdir, "entity-bind" ); if( !entityOutBindFile.exists() || !entityOutBindFile.isDirectory() ) { entityOutBindFile.mkdirs(); } } catch( SecurityException ex ) { entityOutBindFile = null; ERROR( ex ); } try { entityOutDeployFile = new File( logdir, "entity-deploy" ); if( !entityOutDeployFile.exists() || !entityOutDeployFile.isDirectory() ) { entityOutDeployFile.mkdirs(); } } catch( SecurityException ex ) { entityOutDeployFile = null; ERROR( ex ); } } } private void init() { // get XML wrapper instance xmlWrapper = XMLFactory.getXMLWrapper(); INFO( "get XML wrapper: '" + xmlWrapper.getClass().getName() + "'" ); // get XSL translet wrapper instance transletWrapper = XMLFactory.getTransletWrapper(); INFO( "get XSL translet wrapper: '" + transletWrapper.getClass().getName() + "'" ); // get XML binder xmlBind = XMLFactory.getXMLBinding(); INFO( "get XML binding: '" + xmlBind.getClass().getName() + "'" ); }// --------------------- PRIVATE METHODS ------------------- /** * Main global function. Perform processing with XML configs */ private void globalProcess() { EntityConfig[] entityConfigArray = parseEntities(); INFO( "parse entity config - ok" ); parseDataschemas(); INFO( "parse dataschema config - ok" ); parseChains(); INFO( "parse chain config - ok" ); buildEntityList( entityConfigArray ); INFO( "build entity - ok" ); deployEntityViewConfigs(); INFO( "deploy entity configs - ok" ); } /** * Main file function. Perform processing with one XML config */ private void fileProcess() { loadEntities(); INFO( "load entity configs - ok" ); EntityConfig entityConfig = parseEntity( entityXmlFile ); INFO( "parse entity config - ok" ); parseDataschemas(); INFO( "parse dataschema config - ok" ); parseChains(); INFO( "parse chain config - ok" ); buildEntityList( new EntityConfig[] {entityConfig} ); INFO( "build entity - ok" ); deployEntityViewConfigs(); INFO( "deploy entity configs - ok" ); } /** * Load entities from database */ private void loadEntities() { try { Collection list = getEntityViewConfigManager().getEntityViewConfigs(); Iterator it = list.iterator(); while( it.hasNext() ) { Entity entity = ( Entity ) it.next(); String name = entity.getName(); entityTable.put( name, entity ); entityNames.add( name ); // increment entity counters ENTITY_COUNTER++; INITIAL_ENTITY_SIZE++; } } catch( RemoteException ex ) { ERROR( ex ); throw new GenericSystemException( "Remote exception: " + ex.getMessage(), ex ); } } /**
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?