001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.etl.codegen.impl;
020:
021: //import com.sun.jbi.ui.devtool.codegen.framework.model.CodeGenException;
022: //import com.sun.jbi.ui.devtool.configuration.IConfiguration;
023: //import com.sun.jbi.ui.devtool.configuration.factory.Factory;
024: //import com.sun.jbi.ui.devtool.connector.framework.util.ConfigurationHelper;
025: //import com.sun.jbi.ui.devtool.connector.repository.ExternalSystem;
026: //import com.sun.jbi.ui.devtool.connector.repository.ExternalSystemComposite;
027: //import com.sun.jbi.ui.devtool.deployment.repository.ProjectDeployment;
028: //import org.netbeans.modules.etl.codegen.impl.GenerateEngineFile.LocalMessageManager;
029: //import org.netbeans.modules.model.database.DBRuntimeEnvAccessor;
030: //import com.sun.jbi.ui.devtool.eways.services.dbsupport.DBRuntimeEnvAccessorFactory;
031: //import com.sun.jbi.ui.devtool.model.common.Configurable;
032: //import com.sun.jbi.ui.devtool.model.common.EnvironmentElement;
033: //import com.sun.jbi.ui.devtool.model.common.cme.CMLink;
034: //import com.sun.jbi.ui.devtool.model.common.cme.ConnectorConfiguration;
035: //import com.sun.jbi.ui.devtool.repository.RepositoryException;
036: //import com.sun.jbi.ui.devtool.sql.framework.exception.BaseException;
037: //import com.sun.jbi.ui.devtool.sql.framework.utils.Logger;
038:
039: /**
040: * @author Girish Patil
041: * @version $Revision$
042: */
043: public class ETLCodegenHelper {
044: // private static final String LOG_CATEGORY = ETLCodegenHelper.class.getName();
045: // private static final LocalMessageManager MESSAGE_MGR = new LocalMessageManager();
046: //
047: // public static byte[] getConfigurationData(Configurable configurable) throws Exception {
048: // String configDataStr = (configurable != null) ? configurable.getConfigurationData() : null;
049: // return (configDataStr != null) ? configDataStr.getBytes() : null;
050: // }
051: //
052: // public static byte[] getConfigurationData(ConnectorConfiguration config) throws Exception {
053: // String configDataStr = config.getConfigurationData();
054: // return (configDataStr != null) ? configDataStr.getBytes() : null;
055: // }
056: //
057: // public static byte[] getConfigurationTemplateContent(Configurable configurable) throws Exception {
058: // String tmp = (configurable != null) ? configurable.getConfigurationTemplateContent() : null;
059: // return (tmp == null) ? null : tmp.getBytes();
060: // }
061: //
062: // public static byte[] getConfigurationTemplateContent(ConnectorConfiguration config) throws Exception {
063: // String tmp = (config != null) ? config.getConfigurationTemplateContent() : null;
064: // return (tmp == null) ? null : tmp.getBytes();
065: // }
066: //
067: // public static DBRuntimeEnvAccessor getDBRuntimeEnvAccessor(String externalSystemType, IConfiguration extSubSysCfg, IConfiguration extSysCommonCfg) throws BaseException {
068: // DBRuntimeEnvAccessor runtimeEnv = null;
069: // try {
070: // IConfiguration mergedCfg = ConfigurationHelper.mergeConfiguration(extSubSysCfg, extSysCommonCfg, false);
071: // runtimeEnv = DBRuntimeEnvAccessorFactory.createDBRuntimeEnvAccessor(externalSystemType, mergedCfg);
072: // }catch(Exception ex){
073: // throw new BaseException(ex);
074: // }
075: // return runtimeEnv;
076: // }
077: //
078: // public static IConfiguration getExternalSystemCommonConfiguration(CMLink cmLink, ProjectDeployment dp) throws BaseException, CodeGenException {
079: // IConfiguration config = null;
080: // try {
081: // EnvironmentElement envElement = dp.getDeployedElement(cmLink, dp.getEnvironment());
082: // if (envElement instanceof ExternalSystemComposite) {
083: // ExternalSystemComposite extSysComposite = (ExternalSystemComposite) envElement;
084: // String configData = extSysComposite.getCommonConfigurationInstance();
085: // String configTemplate = extSysComposite.getCommonConfigurationTemplate();
086: //
087: // if ((configData != null) && (configTemplate != null)) {
088: // config = getIConfiguration(configTemplate.getBytes("UTF-8"), configData.getBytes("UTF-8"));
089: // }
090: // }
091: // } catch (Exception ex) {
092: // if (ex instanceof CodeGenException) {
093: // throw ((CodeGenException) ex);
094: // } else {
095: // throw new BaseException(ex);
096: // }
097: // }
098: //
099: // return config;
100: // }
101: //
102: // public static IConfiguration getExternalSystemConfiguration(CMLink link, ProjectDeployment deploy, String extSysTypeName) throws BaseException , CodeGenException {
103: // String extAppName = MESSAGE_MGR.getString("LBL_UNKNOWN");
104: // String extSystemName = null;
105: // byte[] configData = null;
106: // byte[] configTemplate = null;
107: // IConfiguration config = null;
108: //
109: // try {
110: // extAppName = link.getDestinationNode().getName();
111: // } catch (RepositoryException ignore) {
112: // // Ignore.
113: // }
114: // try {
115: // EnvironmentElement envElement = deploy.getDeployedElement(link, deploy.getEnvironment());
116: // extSystemName = envElement.getName();
117: //
118: // if (envElement.getEnvironmentElementType().indexOf("ExternalSystem") > 0) {
119: // ExternalSystem extSystem = null;
120: //
121: // if (envElement instanceof ExternalSystemComposite) {
122: // ExternalSystemComposite extSysComposite = (ExternalSystemComposite) envElement;
123: // extSystem = extSysComposite.getExternalSystem(extSysTypeName);
124: // if (extSystem != null) {
125: // Configurable envCfg = extSystem.getConfiguration();
126: // configData = getConfigurationData(envCfg);
127: // if (configData == null || configData.length == 0) {
128: // throw new CodeGenException(MESSAGE_MGR.getString("ERR_EXTSYS_DATA_MISSING", extSystemName, extSysTypeName));
129: // }
130: //
131: // configTemplate = getConfigurationTemplateContent(envCfg);
132: // if (configTemplate == null || configTemplate.length == 0) {
133: // throw new CodeGenException(MESSAGE_MGR.getString("ERR_EXTSYS_TEMPLATE_MISSING", extSystemName, extSysTypeName));
134: // }
135: //
136: // config = getIConfiguration(configTemplate, configData);
137: // }
138: // }else{
139: // // TODO use eways ExternalSystem
140: // if (envElement instanceof org.netbeans.modules.mashup.db.model.ExternalSystem){
141: // org.netbeans.modules.mashup.db.model.ExternalSystem flatfileXSystem = (org.netbeans.modules.mashup.db.model.ExternalSystem) envElement;
142: // if (flatfileXSystem != null){
143: // configData = getConfigurationData(flatfileXSystem.getConfiguration());
144: // if (configData == null || configData.length == 0) {
145: // throw new CodeGenException(MESSAGE_MGR.getString("ERR_EXTSYS_DATA_MISSING", extSystemName, extSysTypeName));
146: // }
147: //
148: // configTemplate = getConfigurationTemplateContent(flatfileXSystem.getConfiguration());
149: // if (configTemplate == null || configTemplate.length == 0) {
150: // throw new CodeGenException(MESSAGE_MGR.getString("ERR_EXTSYS_TEMPLATE_MISSING", extSystemName, extSysTypeName));
151: // }
152: //
153: // config = getIConfiguration(configTemplate, configData);
154: // }
155: // }
156: // }
157: // }
158: // } catch (Exception e) {
159: // if (e instanceof CodeGenException) {
160: // throw ((CodeGenException) e);
161: // }
162: //
163: // StringBuffer msg = new StringBuffer();
164: // msg.append("Error occurred while retrieving connection parameters from ");
165: // if (extSysTypeName != null) {
166: // msg.append(" section " + extSysTypeName + " of ");
167: // }
168: //
169: // if (extSystemName != null) {
170: // msg.append("External System \"" + extSystemName + "\".");
171: // } else {
172: // msg.append("External System associated with External Application \"" + extAppName + "\"");
173: // }
174: //
175: // throw new BaseException(msg.toString(), e);
176: // }
177: // return config;
178: // }
179: //
180: // public static IConfiguration getIConfiguration(byte[] template, byte[] data) throws Exception {
181: // Factory factory = new Factory();
182: // return factory.getConfiguration(template, data);
183: // }
184: //
185: // public static IConfiguration getIConfiguration(Configurable configurable) throws Exception {
186: // IConfiguration ret = null;
187: // byte[] configData = null;
188: // byte[] configTemplate = null;
189: // configData = getConfigurationData(configurable);
190: // configTemplate = getConfigurationTemplateContent(configurable);
191: // ret = getIConfiguration(configTemplate, configData);
192: // return ret;
193: // }
194: //
195: // public static IConfiguration getIConfiguration(ConnectorConfiguration connectorConfiguration, String linkName) throws CodeGenException {
196: // IConfiguration iconfiguration = null;
197: // if (connectorConfiguration != null) {
198: // try {
199: // // TODO Conform message to match instructions in eGate docs for CME.
200: // byte[] configData = getConfigurationData(connectorConfiguration);
201: // if (configData == null || configData.length == 0) {
202: // throw new CodeGenException(MESSAGE_MGR.getString(
203: // "ERR_ICONFIGURATION_DATA_MISSING", linkName));
204: // }
205: //
206: // byte[] configTemplate = getConfigurationTemplateContent(connectorConfiguration);
207: // if (configTemplate == null || configTemplate.length == 0) {
208: // throw new CodeGenException(MESSAGE_MGR.getString(
209: // "ERR_ICONFIGURATION_TEMPLATE_MISSING", linkName));
210: // }
211: //
212: // iconfiguration = getIConfiguration(configTemplate, configData);
213: // } catch (CodeGenException e) {
214: // throw e;
215: // } catch (Exception e) {
216: // Logger.print(Logger.ERROR, LOG_CATEGORY,
217: // "Failed to get configuration data", e);
218: // throw new CodeGenException(e);
219: // }
220: // }
221: // return iconfiguration;
222: // }
223:
224: }
|