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.sql.framework.model.impl;
042:
043: import org.netbeans.modules.sql.framework.model.DBColumn;
044: import org.netbeans.modules.sql.framework.model.SQLConstants;
045: import org.netbeans.modules.sql.framework.model.SourceColumn;
046:
047: /**
048: * Concrete implementation of SourceColumn describing column metadata for source columns.
049: *
050: * @author Sudhendra Seshachala, Jonathan Giron
051: * @version $Revision$
052: */
053: public class SourceColumnImpl extends AbstractDBColumn implements
054: SourceColumn {
055:
056: /* Log4J category name */
057: static final String LOG_CATEGORY = SourceColumnImpl.class.getName();
058:
059: /** Constructs default instance of SourceColumnImpl. */
060: public SourceColumnImpl() {
061: super ();
062: init();
063: }
064:
065: /**
066: * Constructs a new instance of SourceColumnImpl, cloning the contents of the given
067: * DBColumn implementation instance.
068: *
069: * @param src DBColumn instance to be cloned
070: */
071: public SourceColumnImpl(DBColumn src) {
072: this ();
073:
074: if (src == null) {
075: throw new IllegalArgumentException(
076: "Must supply non-null DBColumn instance for src.");
077: }
078:
079: copyFrom(src);
080: }
081:
082: /**
083: * Constructs a new instance of SourceColumnImpl using the given parameters and
084: * assuming that the column is not part of a foreign key or primary key, and that it
085: * accepts null values.
086: *
087: * @param colName name of this column
088: * @param sqlJdbcType JDBC type of this column
089: * @param colScale scale of this column
090: * @param colPrecision precision of this column
091: * @param isNullable true if nullable, false otherwise
092: * @see java.sql.Types
093: */
094: public SourceColumnImpl(String colName, int sqlJdbcType,
095: int colScale, int colPrecision, boolean isNullable) {
096: super (colName, sqlJdbcType, colScale, colPrecision, isNullable);
097: init();
098: }
099:
100: /**
101: * @see org.netbeans.modules.sql.framework.model.impl.AbstractDBColumn
102: * (java.lang.String,int,int,boolean,int,boolean,boolean,boolean)
103: */
104: public SourceColumnImpl(String colName, int sqlJdbcType,
105: int colScale, int colPrecision, boolean isPrimaryKey,
106: boolean isForeignKey, boolean isIndexed, boolean isNullable) {
107: super (colName, sqlJdbcType, colScale, colPrecision,
108: isPrimaryKey, isForeignKey, isIndexed, isNullable);
109: init();
110: }
111:
112: /**
113: * Clone a deep copy of SourceColumnImpl.
114: *
115: * @return a copy of SourceColumnImpl.
116: */
117: public Object clone() {
118: return new SourceColumnImpl(this );
119: }
120:
121: /**
122: * @see org.netbeans.modules.sql.framework.model.impl.AbstractDBColumn#equals(java.lang.Object)
123: */
124: public boolean equals(Object refObj) {
125: if (!(refObj instanceof SourceColumn)) {
126: return false;
127: }
128:
129: return super .equals(refObj);
130: }
131:
132: /**
133: * @see org.netbeans.modules.sql.framework.model.impl.AbstractDBColumn#hashCode
134: */
135: public int hashCode() {
136: return super .hashCode();
137: }
138:
139: /**
140: * Overrides default implementation to return evaluated column name.
141: *
142: * @return evaluated column name.
143: */
144: public String toString() {
145: return super .toString();
146: }
147:
148: /**
149: * @see org.netbeans.modules.sql.framework.model.SQLObject#toXMLString
150: */
151: public String toXMLString(String prefix) {
152: StringBuilder xml = new StringBuilder(50);
153:
154: xml.append(prefix).append("<").append(ELEMENT_TAG);
155:
156: // Allow superclass to write its attributes out first.
157: appendXMLAttributes(xml);
158: xml.append(" >\n");
159:
160: // write out attributes
161: xml.append(super .toXMLAttributeTags(prefix));
162: xml.append(prefix).append("</").append(ELEMENT_TAG).append(
163: ">\n");
164:
165: return xml.toString();
166: }
167:
168: /**
169: * @see org.netbeans.modules.sql.framework.model.impl.AbstractDBColumn#getElementTagName
170: */
171: protected String getElementTagName() {
172: return ELEMENT_TAG;
173: }
174:
175: /*
176: * Performs sql framework initialization functions for constructors which cannot first
177: * call this().
178: */
179: private void init() {
180: type = SQLConstants.SOURCE_COLUMN;
181: }
182:
183: }
|