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.mashup.db.ui.model;
042:
043: import java.util.List;
044:
045: import org.netbeans.modules.mashup.db.common.PropertyKeys;
046: import org.netbeans.modules.mashup.db.model.FlatfileDBTable;
047: import org.netbeans.modules.sql.framework.model.DBColumn;
048:
049: import com.sun.sql.framework.utils.StringUtil;
050: import net.java.hulp.i18n.Logger;
051: import org.netbeans.modules.etl.logger.Localizer;
052: import org.netbeans.modules.etl.logger.LogUtil;
053: import org.netbeans.modules.sql.framework.model.ForeignKey;
054: import org.netbeans.modules.sql.framework.model.Index;
055: import org.netbeans.modules.sql.framework.model.PrimaryKey;
056:
057: /**
058: * Abstract bean wrapper for FlatfileDBTable instances to expose common read-only
059: * properties for display in a Flatfile Database definition property sheet.
060: *
061: * @author Jonathan Giron
062: * @version $Revision$
063: */
064: public abstract class FlatfileTable {
065: private FlatfileDBTable mDelegate;
066: private static transient final Logger mLogger = LogUtil
067: .getLogger(FlatfileTable.class.getName());
068: private static transient final Localizer mLoc = Localizer.get();
069: public static final Integer ZERO = new Integer(0);
070:
071: /**
072: * Creates new instance of FlatfileTable, wrapping the given FlatfileDBTable instance.
073: *
074: * @param dbTable FlatfileDBTable instance (delimited type) to be wrapped.
075: */
076: protected FlatfileTable(FlatfileDBTable dbTable) {
077: mDelegate = dbTable;
078: }
079:
080: /**
081: * Gets instance of FlatfileDBTble wrapped by this object.
082: *
083: * @return FlatfileDBTable associated with this instance
084: */
085: public final FlatfileDBTable getSource() {
086: return mDelegate;
087: }
088:
089: /**
090: * Gets file name.
091: *
092: * @return file name
093: */
094: public String getFileName() {
095: return mDelegate.getFileName();
096: }
097:
098: /**
099: * Gets table name associated with this flatfile.
100: *
101: * @return table name
102: */
103: public String getTableName() {
104: return mDelegate.getTableName();
105: }
106:
107: /**
108: * Gets property string associated with the given name.
109: *
110: * @param propName property key
111: * @return property associated with propName, or null if no such property exists.
112: */
113: public String getProperty(String propName) {
114: return mDelegate.getProperty(propName);
115: }
116:
117: /**
118: * Gets name of this instance - ordinarily the same as getTableName().
119: *
120: * @return name
121: * @see #getTableName()
122: */
123: public String getName() {
124: return mDelegate.getName();
125: }
126:
127: /**
128: * Gets optional description of this table.
129: *
130: * @return table description string
131: */
132: public String getDescription() {
133: String desc = mDelegate.getDescription();
134: String nbBundle1 = mLoc.t("PRSR001: <None>");
135: return (StringUtil.isNullString(desc)) ? Localizer
136: .parse(nbBundle1) : desc;
137: }
138:
139: /**
140: * Gets schema, if any, with which the table is associated.
141: *
142: * @return name of associated schema; may return "<None>" if value is null or empty
143: * string
144: */
145: public String getSchema() {
146: String schema = mDelegate.getSchema();
147: String nbBundle2 = mLoc.t("PRSR001: <None>");
148: return (StringUtil.isNullString(schema)) ? Localizer
149: .parse(nbBundle2) : schema;
150: }
151:
152: /**
153: * Gets catalog, if any, with which the table is associated.
154: *
155: * @return name of associated catalog; may return "<None>" if value is null or empty
156: * string
157: */
158: public String getCatalog() {
159: String catalog = mDelegate.getCatalog();
160: String nbBundle3 = mLoc.t("PRSR001: <None>");
161: return (StringUtil.isNullString(catalog)) ? Localizer
162: .parse(nbBundle3) : catalog;
163: }
164:
165: /**
166: * Gets column, if any, with the given name.
167: *
168: * @param name name of column to get
169: * @return DBColumn associated with <code>name</code>, or null if no such column
170: * exists
171: */
172: public DBColumn getColumn(String name) {
173: return mDelegate.getColumn(name);
174: }
175:
176: /**
177: * Gets List of columns contained by this instance.
178: *
179: * @return List of FlatfileDBColumns that are part of this instance
180: */
181: public List getColumnList() {
182: return mDelegate.getColumnList();
183: }
184:
185: /**
186: * Gets PrimaryKey instance, if any, associated with this table.
187: *
188: * @return PrimaryKey instance, or null if no PK exists
189: */
190: public PrimaryKey getPrimaryKey() {
191: return mDelegate.getPrimaryKey();
192: }
193:
194: /**
195: * Gets List, possibly empty, of foreign keys associated with this table.
196: *
197: * @return List, possibly empty, of associated foreign keys
198: */
199: public List getForeignKeys() {
200: return mDelegate.getForeignKeys();
201: }
202:
203: /**
204: * Gets ForeignKey instance, if any, with the given name and associated with this
205: * table.
206: *
207: * @return ForeignKey instance, or null if no such key exists with the name
208: * <code>keyname</code>
209: */
210: public ForeignKey getForeignKey(String keyName) {
211: return mDelegate.getForeignKey(keyName);
212: }
213:
214: /**
215: * Gets List, possibly empty, of Indexes associated with this table.
216: *
217: * @return List, possibly empty, of assocaited Index objects
218: */
219: public List getIndexes() {
220: return mDelegate.getIndexes();
221: }
222:
223: /**
224: * Gets Index instance, if any, associated with the given name.
225: *
226: * @param name name of index to get
227: * @return Index instance, or null if no such Index exists with the name
228: * <code>name</code>
229: */
230: public Index getIndex(String name) {
231: return mDelegate.getIndex(name);
232: }
233:
234: /**
235: * Gets name of encoding scheme to use in parsing underlying flatfile data
236: *
237: * @return current encoding scheme
238: */
239: public String getEncodingScheme() {
240: return mDelegate.getEncodingScheme();
241: }
242:
243: /**
244: * Gets the current file type - Delimited or FixedWidth
245: *
246: * @return String representing current file type, one of 'Delimited' or 'FixedWidth'
247: */
248: public String getFileType() {
249: return mDelegate.getProperty(PropertyKeys.LOADTYPE);
250: }
251:
252: /**
253: * Gets number of rows to skip as header information (non-data)
254: *
255: * @return Integer representing rows to skip
256: */
257: public Integer getRowsToSkip() {
258: String valStr = mDelegate.getProperty(PropertyKeys.ROWSTOSKIP);
259: return (valStr != null) ? Integer.valueOf(valStr) : ZERO;
260: }
261:
262: /**
263: * Gets threshold number of faults, above which further parsing/execution should be
264: * halted.
265: *
266: * @return Integer representing maximum number of parsing faults to tolerate before
267: * raising an exception.
268: */
269: public Integer getMaxFaults() {
270: String valStr = mDelegate.getProperty(PropertyKeys.MAXFAULTS);
271: return (valStr != null) ? Integer.valueOf(valStr) : ZERO;
272: }
273:
274: /**
275: * Gets the character(s) used to delimit records in this file.
276: *
277: * @return record delimiter string
278: */
279: public String getRecordDelimiter() {
280: String delimiter = getProperty(PropertyKeys.RECORDDELIMITER);
281: String nbBundle4 = mLoc.t("PRSR001: <None>");
282: if (delimiter == null || delimiter.length() == 0) {
283: delimiter = Localizer.parse(nbBundle4);
284: } else {
285: delimiter = StringUtil.escapeControlChars(delimiter);
286: }
287: return delimiter;
288: }
289:
290: /**
291: * Indicates whether the first physical record of the flatfile contains field header
292: * information.
293: *
294: * @return true if first physical record contains field header information; false
295: * otherwise
296: */
297: public boolean isFirstLineHeader() {
298: return Boolean.valueOf(
299: getProperty(PropertyKeys.ISFIRSTLINEHEADER))
300: .booleanValue();
301: }
302:
303: /**
304: * Indicates whether white space trimming is enabled or not
305: **/
306: public boolean enableWhiteSpaceTrimming() {
307: String whiteSpaceStr = getProperty(PropertyKeys.TRIMWHITESPACE);
308: whiteSpaceStr = (whiteSpaceStr == null) ? "true"
309: : whiteSpaceStr;
310: return Boolean.valueOf(whiteSpaceStr).booleanValue();
311: }
312:
313: /**
314: * Gets the SQL select statement to retrieve a result set displaying this file's
315: * contents, using the given value as a limit to the number of rows returned.
316: *
317: * @param rowCount number of rows to display; 0 returns all available rows
318: * @return SQL statement to select the contents of this file in the column order
319: * specified by this instance's FlatfileFields.
320: */
321: public String getSelectStatementSQL(int rows) {
322: return mDelegate.getSelectStatementSQL(rows);
323: }
324: }
|