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 java.sql.Types;
044: import java.util.ArrayList;
045: import java.util.Collections;
046: import java.util.HashMap;
047: import java.util.Iterator;
048: import java.util.List;
049: import java.util.Map;
050:
051: import org.netbeans.modules.sql.framework.model.RuntimeInput;
052: import org.netbeans.modules.sql.framework.model.SQLConstants;
053: import org.netbeans.modules.sql.framework.model.SQLDBColumn;
054:
055: import com.sun.sql.framework.exception.BaseException;
056: import com.sun.sql.framework.utils.RuntimeAttribute;
057: import org.netbeans.modules.sql.framework.model.DBTable;
058:
059: /**
060: * @author radval
061: */
062: public class RuntimeInputImpl extends SourceTableImpl implements
063: RuntimeInput {
064:
065: /** Array of Strings reprsenting available SQL datatypes */
066: protected static final List<String> VALID_TYPE_NAMES = new ArrayList<String>();
067:
068: static {
069:
070: VALID_TYPE_NAMES.add(String.valueOf(Types.CHAR));
071: VALID_TYPE_NAMES.add(String.valueOf(Types.DECIMAL));
072: VALID_TYPE_NAMES.add(String.valueOf(Types.DOUBLE));
073: VALID_TYPE_NAMES.add(String.valueOf(Types.FLOAT));
074: VALID_TYPE_NAMES.add(String.valueOf(Types.INTEGER));
075: VALID_TYPE_NAMES.add(String.valueOf(Types.TIMESTAMP));
076: VALID_TYPE_NAMES.add(String.valueOf(Types.VARCHAR));
077:
078: Collections.sort(VALID_TYPE_NAMES);
079: }
080:
081: /** Creates a new instance of InputTableImpl */
082: public RuntimeInputImpl() {
083: super ();
084: init();
085: }
086:
087: /**
088: * New instance
089: *
090: * @param src - src
091: */
092: public RuntimeInputImpl(DBTable src) {
093: super (src);
094: init();
095: }
096:
097: public Map getRuntimeAttributeMap() {
098: Map<String, RuntimeAttribute> inputAttrs = new HashMap<String, RuntimeAttribute>();
099:
100: Iterator attrIter = getColumnList().iterator();
101: while (attrIter.hasNext()) {
102: SQLDBColumn col = (SQLDBColumn) attrIter.next();
103: final String varName = col.getName();
104: final String defaultValue = col.getDefaultValue();
105: int jdbcType = col.getJdbcType();
106:
107: RuntimeAttribute attr = new RuntimeAttribute();
108: attr.setAttributeName(varName);
109: attr.setJdbcType(jdbcType);
110: if (defaultValue != null) {
111: attr.setAttributeValue(defaultValue);
112: }
113:
114: inputAttrs.put(varName, attr);
115: }
116:
117: return inputAttrs;
118: }
119:
120: /**
121: * Construct XML string
122: *
123: * @param prefix - prefix
124: * @param tableOnly - table only
125: * @return XML string
126: * @throws BaseException - exception
127: */
128: @Override
129: public String toXMLString(String prefix, boolean tableOnly)
130: throws BaseException {
131: StringBuilder xml = new StringBuilder(INIT_XMLBUF_SIZE);
132:
133: xml.append(prefix).append("<").append(TAG_RUNTIME_INPUT);
134: xml.append(" ").append(TABLE_NAME_ATTR).append("=\"").append(
135: name).append("\"");
136:
137: xml.append(" ").append(ID_ATTR).append("=\"").append(id)
138: .append("\"");
139:
140: if (displayName != null && displayName.trim().length() != 0) {
141: xml.append(" ").append(DISPLAY_NAME_ATTR).append("=\"")
142: .append(displayName).append("\"");
143: }
144:
145: xml.append(">\n");
146:
147: xml.append(toXMLAttributeTags(prefix));
148:
149: if (!tableOnly) {
150: writeColumns(prefix, xml);
151: }
152:
153: if (guiInfo != null) {
154: xml.append(guiInfo.toXMLString(prefix + INDENT));
155: }
156:
157: xml.append(prefix).append("</").append(TAG_RUNTIME_INPUT)
158: .append(">\n");
159:
160: return xml.toString();
161: }
162:
163: /**
164: * Gets String representing tag name for this table class.
165: *
166: * @return String representing element tag for this class
167: */
168: @Override
169: protected String getElementTagName() {
170: return TAG_RUNTIME_INPUT;
171: }
172:
173: private void init() {
174: type = SQLConstants.RUNTIME_INPUT;
175: this.setName(TAG_RUNTIME_INPUT);
176: }
177:
178: }
|