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.bootstrap;
042:
043: import java.util.ArrayList;
044: import java.util.HashMap;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.Map;
048:
049: import org.netbeans.modules.mashup.db.common.Property;
050: import org.netbeans.modules.mashup.db.common.PropertyKeys;
051:
052: /**
053: * Factory for creating property template with default value.
054: *
055: * @author Ahimanikya Satapathy
056: * @version $Revision$
057: */
058: public class TemplateFactory {
059:
060: private static Map<String, List<Property>> templateMap = new HashMap<String, List<Property>>(
061: 2);
062: private static List<Property> delimiterMap = new ArrayList<Property>(
063: 11);
064: private static List<Property> fixedwidthMap = new ArrayList<Property>(
065: 12);
066: private static List<Property> webMap = new ArrayList<Property>(12);
067: private static List<Property> xmlMap = new ArrayList<Property>(4);
068: private static List<Property> webrowsetMap = new ArrayList<Property>(
069: 2);
070: private static List<Property> rssMap = new ArrayList<Property>(2);
071: private static List<Property> spreadsheetMap = new ArrayList<Property>(
072: 3);
073:
074: private static Class STR_TYPE = java.lang.String.class;
075: private static Class INT_TYPE = java.lang.Integer.class;
076: private static Class BOOL_TYPE = java.lang.Boolean.class;
077:
078: private static String EMPTY_STR = "";
079: private static String ZERO = "0";
080: private static String CRLFORLF = "\r\n \n";
081: private static String CRLF = "\r\n";
082: private static String TRUE = "true";
083: private static String VARCHAR = "varchar";
084:
085: static {
086: webMap.add(new Property(PropertyKeys.LOADTYPE, STR_TYPE,
087: PropertyKeys.WEB));
088: webMap.add(new Property(PropertyKeys.REFRESH, BOOL_TYPE, TRUE));
089: webMap.add(new Property(PropertyKeys.ISFIRSTLINEHEADER,
090: BOOL_TYPE, TRUE));
091: webMap.add(new Property(PropertyKeys.RECORDDELIMITER, STR_TYPE,
092: CRLFORLF));
093: webMap.add(new Property(PropertyKeys.ROWSTOSKIP, INT_TYPE,
094: ZERO, false));
095: webMap.add(new Property(PropertyKeys.FIELDDELIMITER, STR_TYPE,
096: ","));
097: webMap.add(new Property(
098: PropertyKeys.WIZARDCUSTOMFIELDDELIMITER, STR_TYPE,
099: EMPTY_STR));
100: webMap
101: .add(new Property(PropertyKeys.QUALIFIER, STR_TYPE,
102: "\""));
103: webMap.add(new Property(PropertyKeys.MAXFAULTS, INT_TYPE, ZERO,
104: false));
105: webMap.add(new Property(PropertyKeys.WIZARDDEFAULTSQLTYPE,
106: STR_TYPE, VARCHAR, false));
107: webMap.add(new Property(PropertyKeys.WIZARDDEFAULTPRECISION,
108: INT_TYPE, "60", false));
109: webMap.add(new Property(PropertyKeys.WIZARDFILEPATH, STR_TYPE,
110: EMPTY_STR));
111: }
112:
113: static {
114: delimiterMap.add(new Property(PropertyKeys.LOADTYPE, STR_TYPE,
115: PropertyKeys.DELIMITED));
116: delimiterMap.add(new Property(PropertyKeys.FILENAME, STR_TYPE,
117: EMPTY_STR));
118: delimiterMap.add(new Property(PropertyKeys.ISFIRSTLINEHEADER,
119: BOOL_TYPE, TRUE));
120: delimiterMap.add(new Property(PropertyKeys.RECORDDELIMITER,
121: STR_TYPE, CRLFORLF));
122: delimiterMap.add(new Property(PropertyKeys.ROWSTOSKIP,
123: INT_TYPE, ZERO, false));
124: delimiterMap.add(new Property(PropertyKeys.FIELDDELIMITER,
125: STR_TYPE, ","));
126: delimiterMap.add(new Property(
127: PropertyKeys.WIZARDCUSTOMFIELDDELIMITER, STR_TYPE,
128: EMPTY_STR));
129: delimiterMap.add(new Property(PropertyKeys.QUALIFIER, STR_TYPE,
130: "\""));
131: delimiterMap.add(new Property(PropertyKeys.MAXFAULTS, INT_TYPE,
132: ZERO, false));
133: delimiterMap.add(new Property(
134: PropertyKeys.WIZARDDEFAULTSQLTYPE, STR_TYPE, VARCHAR,
135: false));
136: delimiterMap.add(new Property(
137: PropertyKeys.WIZARDDEFAULTPRECISION, INT_TYPE, "60",
138: false));
139: delimiterMap.add(new Property(PropertyKeys.WIZARDFILEPATH,
140: STR_TYPE, EMPTY_STR));
141: }
142:
143: static {
144: fixedwidthMap.add(new Property(PropertyKeys.LOADTYPE, STR_TYPE,
145: PropertyKeys.FIXEDWIDTH));
146: fixedwidthMap.add(new Property(PropertyKeys.FILENAME, STR_TYPE,
147: EMPTY_STR));
148: fixedwidthMap.add(new Property(PropertyKeys.ISFIRSTLINEHEADER,
149: BOOL_TYPE, TRUE));
150: fixedwidthMap.add(new Property(PropertyKeys.RECORDDELIMITER,
151: STR_TYPE, CRLF));
152: fixedwidthMap.add(new Property(PropertyKeys.ROWSTOSKIP,
153: INT_TYPE, ZERO, false));
154: fixedwidthMap.add(new Property(PropertyKeys.HEADERBYTESOFFSET,
155: INT_TYPE, ZERO));
156: fixedwidthMap.add(new Property(PropertyKeys.WIZARDRECORDLENGTH,
157: INT_TYPE, ZERO));
158: fixedwidthMap.add(new Property(PropertyKeys.MAXFAULTS,
159: INT_TYPE, ZERO, false));
160: fixedwidthMap.add(new Property(PropertyKeys.WIZARDFIELDCOUNT,
161: INT_TYPE, ZERO));
162: fixedwidthMap.add(new Property(
163: PropertyKeys.WIZARDDEFAULTSQLTYPE, STR_TYPE, VARCHAR,
164: false));
165: fixedwidthMap.add(new Property(PropertyKeys.WIZARDFILEPATH,
166: STR_TYPE, EMPTY_STR));
167: }
168:
169: static {
170: xmlMap.add(new Property(PropertyKeys.LOADTYPE, STR_TYPE,
171: PropertyKeys.XML));
172: xmlMap.add(new Property(PropertyKeys.WIZARDDEFAULTSQLTYPE,
173: STR_TYPE, VARCHAR, false));
174: xmlMap.add(new Property(PropertyKeys.WIZARDFILEPATH, STR_TYPE,
175: EMPTY_STR));
176: xmlMap.add(new Property(PropertyKeys.WIZARDDEFAULTPRECISION,
177: INT_TYPE, "60", false));
178: xmlMap.add(new Property(PropertyKeys.TYPE, STR_TYPE,
179: PropertyKeys.READWRITE));
180: xmlMap.add(new Property(PropertyKeys.ROWNAME, STR_TYPE,
181: EMPTY_STR));
182: }
183:
184: static {
185: webrowsetMap.add(new Property(PropertyKeys.LOADTYPE, STR_TYPE,
186: PropertyKeys.WEBROWSET));
187: webrowsetMap.add(new Property(
188: PropertyKeys.WIZARDDEFAULTSQLTYPE, STR_TYPE, VARCHAR,
189: false));
190: webrowsetMap.add(new Property(PropertyKeys.WIZARDFILEPATH,
191: STR_TYPE, EMPTY_STR));
192: webrowsetMap.add(new Property(
193: PropertyKeys.WIZARDDEFAULTPRECISION, INT_TYPE, "60",
194: false));
195: }
196:
197: static {
198: rssMap.add(new Property(PropertyKeys.LOADTYPE, STR_TYPE,
199: PropertyKeys.RSS));
200: rssMap.add(new Property(PropertyKeys.WIZARDDEFAULTSQLTYPE,
201: STR_TYPE, VARCHAR, false));
202: rssMap.add(new Property(PropertyKeys.WIZARDFILEPATH, STR_TYPE,
203: EMPTY_STR));
204: rssMap.add(new Property(PropertyKeys.WIZARDDEFAULTPRECISION,
205: INT_TYPE, "200", false));
206: }
207:
208: static {
209: spreadsheetMap.add(new Property(PropertyKeys.LOADTYPE,
210: STR_TYPE, PropertyKeys.SPREADSHEET));
211: spreadsheetMap.add(new Property(
212: PropertyKeys.WIZARDDEFAULTSQLTYPE, STR_TYPE, VARCHAR,
213: false));
214: spreadsheetMap.add(new Property(PropertyKeys.WIZARDFILEPATH,
215: STR_TYPE, EMPTY_STR));
216: spreadsheetMap.add(new Property(
217: PropertyKeys.WIZARDDEFAULTPRECISION, INT_TYPE, "60",
218: false));
219: }
220:
221: static {
222: templateMap.put(PropertyKeys.DELIMITED, delimiterMap);
223: templateMap.put(PropertyKeys.FIXEDWIDTH, fixedwidthMap);
224: templateMap.put(PropertyKeys.WEB, webMap);
225: templateMap.put(PropertyKeys.RSS, rssMap);
226: templateMap.put(PropertyKeys.XML, xmlMap);
227: templateMap.put(PropertyKeys.WEBROWSET, webrowsetMap);
228: templateMap.put(PropertyKeys.SPREADSHEET, spreadsheetMap);
229: }
230:
231: public synchronized static Map getProperties(String type) {
232: List base = (List) templateMap.get(type);
233: if (base == null) {
234: throw new IllegalArgumentException(
235: "File Type not recognized:" + type);
236: }
237:
238: Map clonedProps = new HashMap(base.size());
239: Iterator iter = base.iterator();
240: while (iter.hasNext()) {
241: Property p = (Property) ((Property) iter.next()).clone();
242: clonedProps.put(p.getName(), p);
243: }
244: return clonedProps;
245: }
246:
247: }
|