KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > visualeditor > querymodel > Identifier


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.db.sql.visualeditor.querymodel;
20
21 /**
22  * Represents an identifier (schema/table/column name)
23  */

24 public class Identifier {
25
26     // Fields
27
private String JavaDoc _name;
28     private boolean _delimited;
29
30
31     // Constructors
32

33     // Create an Identifier with delimiter status explicitly specified.
34
// Only occurs when the parser has that information
35
public Identifier(String JavaDoc name, boolean delimited) {
36         _name = name;
37         _delimited = delimited;
38     }
39
40
41     // Create an Identifier with delimiter status decided heuristically,
42
// depending whether the name contains any special characters
43
public Identifier(String JavaDoc name) {
44         _name=name;
45         _delimited = needsDelimited(name);
46     }
47
48
49     // Accessors
50

51     public String JavaDoc genText() {
52         if (_delimited)
53             return "\"" + _name + "\"";
54         else
55             return _name;
56     }
57
58
59     public String JavaDoc getName() {
60         return _name;
61     }
62
63
64     /**
65      * Returns true if the argument contains any non-word characters, which
66      * will require it to be delimited.
67      */

68     private boolean needsDelimited(String JavaDoc name) {
69         String JavaDoc[] split=name.split("\\W");
70         return (split.length>1);
71     }
72
73 }
74
75
Popular Tags