001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.etl.ui.model.impl;
042:
043: import java.io.StringReader;
044: import java.util.List;
045:
046: import com.sun.sql.framework.exception.BaseException;
047:
048: import org.netbeans.modules.etl.model.impl.ETLDefinitionImpl;
049: import org.netbeans.modules.etl.ui.ETLDataObject;
050: import org.netbeans.modules.sql.framework.common.utils.XmlUtil;
051: import org.netbeans.modules.sql.framework.ui.model.CollabSQLUIModel;
052: import org.netbeans.modules.sql.framework.ui.model.impl.CollabSQLUIModelImpl;
053:
054: /**
055: * This class represents a model for GUI collaboration objects
056: *
057: * @author Ritesh Adval
058: */
059:
060: public class ETLCollaborationModel extends CollabSQLUIModelImpl
061: implements CollabSQLUIModel {
062:
063: protected ETLDefinitionImpl etlDefinition;
064: private String eTLXml;
065: private ETLDataObject dObj;
066:
067: public ETLCollaborationModel() {
068: }
069:
070: public ETLCollaborationModel(String name) {
071: this ();
072: try {
073: this .etlDefinition = new ETLDefinitionImpl(name);
074: } catch (Exception ex) {
075: // ignore
076: }
077: etlDefinition.addSQLObjectListener(this );
078: super .setSQLDefinition(etlDefinition.getSQLDefinition());
079: this .isReloaded = false;
080: }
081:
082: public ETLCollaborationModel(ETLDataObject mObj)
083: throws BaseException {
084: this ();
085: this .dObj = mObj;
086: try {
087: this .etlDefinition = new ETLDefinitionImpl(this .dObj
088: .getName());
089: } catch (Exception ex) {
090: // ignore
091: }
092: etlDefinition.addSQLObjectListener(this );
093: super .setSQLDefinition(etlDefinition.getSQLDefinition());
094: this .isReloaded = false;
095:
096: }
097:
098: // Reload
099: public ETLCollaborationModel(ETLDataObject mObj,
100: String etlDefinitionXml) throws BaseException {
101: this ();
102: this .dObj = mObj;
103: this .eTLXml = etlDefinitionXml;
104: this .isReloaded = true;
105: }
106:
107: public ETLDefinitionImpl getETLDefinition() {
108: return etlDefinition;
109: }
110:
111: public List getSourceDatabaseModels() {
112: return etlDefinition.getSourceDatabaseModels();
113: }
114:
115: public List getTargetDatabaseModels() {
116: return etlDefinition.getTargetDatabaseModels();
117: }
118:
119: public boolean isDrawingRequired() {
120: boolean reloadStatus = isReloaded;
121: this .isReloaded = false;
122: return reloadStatus;
123: }
124:
125: public void reLoad() throws BaseException {
126: reLoad(this .eTLXml);
127: }
128:
129: @Override
130: public void reLoad(String etlDefinitionXml) throws BaseException {
131: this .eTLXml = etlDefinitionXml;
132:
133: // clear the listener
134: if (this .etlDefinition != null) {
135: this .etlDefinition.removeSQLObjectListener(this );
136: }
137:
138: this .etlDefinition = new ETLDefinitionImpl(XmlUtil
139: .loadXMLFile(new StringReader(etlDefinitionXml)), null);
140: this .etlDefinition.addSQLObjectListener(this );
141: super .setSQLDefinition(etlDefinition.getSQLDefinition());
142: }
143:
144: public void setDefinitionContent(String definitionXml) {
145: this .eTLXml = definitionXml;
146: }
147:
148: public void setDefinitionContent(ETLDefinitionImpl etlDefn) {
149: try {
150: if (etlDefinition != null) {
151: this .etlDefinition.removeSQLObjectListener(this );
152: }
153: this .etlDefinition = etlDefn;
154: this .eTLXml = etlDefinition.toXMLString("");
155: etlDefinition.addSQLObjectListener(this );
156: super .setSQLDefinition(etlDefinition.getSQLDefinition());
157: } catch (BaseException ex) {
158: ex.printStackTrace();
159: }
160: }
161: }
|