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.common.utils.TagParserUtility;
045: import org.netbeans.modules.sql.framework.model.SQLCanvasObject;
046: import org.netbeans.modules.sql.framework.model.SQLInputObject;
047: import org.netbeans.modules.sql.framework.model.SQLObject;
048:
049: import com.sun.sql.framework.exception.BaseException;
050: import com.sun.sql.framework.utils.StringUtil;
051:
052: /**
053: * UI wrapper class for SQLObjects which serve as inputs to SQLConnectableObjects.
054: *
055: * @author Jonathan Giron
056: * @version $Revision$
057: */
058: public class SQLInputObjectImpl implements SQLInputObject {
059:
060: /* Argument name */
061: private String argName;
062:
063: /* Display name */
064: private String dispName;
065:
066: /* SQLObject representing input value */
067: private SQLObject input;
068:
069: /**
070: * Creates a new instance of SQLInputObject with the given argument name and input
071: * object.
072: *
073: * @param argumentName argument name to associate with the given SQLObject
074: * @param displayName display name for this instance
075: * @param inputObject SQLObject providing input value for the given argument name
076: */
077: public SQLInputObjectImpl(String argumentName, String displayName,
078: SQLObject inputObject) {
079: if (StringUtil.isNullString(argumentName)) {
080: throw new IllegalArgumentException(
081: "Must supply non-empty String ref for argumentName.");
082: }
083:
084: argName = argumentName;
085: dispName = displayName;
086: input = inputObject;
087: }
088:
089: /**
090: * Overrides default implementation to compute hashcode based on any associated
091: * SQLInputObjects as well as values of non-transient member variables.
092: *
093: * @param o Object to compare against this
094: * @return hashcode for this instance
095: */
096: public boolean equals(Object o) {
097: if (o == null) {
098: return false;
099: } else if (o == this ) {
100: return true;
101: } else if (!(o instanceof SQLInputObjectImpl)) {
102: return false;
103: }
104:
105: SQLInputObjectImpl impl = (SQLInputObjectImpl) o;
106: boolean response = (argName != null) ? argName
107: .equals(impl.argName) : (impl.argName == null);
108: response &= (input != null) ? (input.equals(impl.input))
109: : (impl.input == null);
110:
111: return response;
112: }
113:
114: /**
115: * Gets argument name associated with this input.
116: *
117: * @return argument name
118: */
119: public String getArgName() {
120: return argName;
121: }
122:
123: /**
124: * Gets display name of this input.
125: *
126: * @return current display name
127: */
128: public String getDisplayName() {
129: return (dispName != null) ? dispName : argName;
130: }
131:
132: /**
133: * Gets reference to SQLObject holding value of this input
134: *
135: * @return input object
136: */
137: public SQLObject getSQLObject() {
138: return input;
139: }
140:
141: /**
142: * Overrides default implementation to compute hashcode based on any associated
143: * attributes as well as values of non-transient member variables.
144: *
145: * @return hashcode for this instance
146: */
147: public int hashCode() {
148: int hashCode = (argName != null) ? argName.hashCode() : 0;
149: hashCode += (input != null) ? input.hashCode() : 0;
150:
151: return hashCode;
152: }
153:
154: /**
155: * Sets display name of this input.
156: *
157: * @param newName new display name
158: */
159: public void setDisplayName(String newName) {
160: dispName = newName;
161: }
162:
163: /**
164: * Sets reference to SQLObject holding value of this input
165: *
166: * @param newInput reference to new input object
167: */
168: public void setSQLObject(SQLObject newInput) {
169: input = newInput;
170: }
171:
172: /**
173: * @see SQLInputObject
174: */
175: public String toXMLString(String prefix) {
176: StringBuilder buf = new StringBuilder();
177:
178: if (prefix == null) {
179: prefix = "";
180: }
181:
182: buf.append(prefix).append("<" + TAG_INPUT + " ");
183: buf.append(ATTR_ARGNAME + "=\"").append(argName).append("\" ");
184: buf.append(ATTR_DISPLAY_NAME + "=\"").append(getDisplayName())
185: .append("\">\n");
186:
187: try {
188: // TODO: make Source and target columns as canvas objects
189: // if input is a canvas object then it is refered object
190: if (input instanceof SQLCanvasObject
191: || input instanceof DBColumn) {
192: buf.append(TagParserUtility.toXMLObjectRefTag(input,
193: prefix + "\t"));
194: } else {
195: // if input is not canvas object then it is part of object
196: buf.append(input.toXMLString(prefix + "\t"));
197: }
198: } catch (BaseException e) {
199: // @TODO log this exception
200: }
201:
202: buf.append(prefix).append("</" + TAG_INPUT + ">\n");
203:
204: return buf.toString();
205: }
206: }
|