001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.sql.old;
020
021import java.io.Serializable;
022import java.util.StringTokenizer;
023
024public class ZAliasedName
025    implements Serializable
026{
027
028    public ZAliasedName()
029    {
030        strform_ = "";
031        schema_ = null;
032        table_ = null;
033        column_ = null;
034        alias_ = null;
035        form_ = FORM_COLUMN;
036    }
037
038    public ZAliasedName(String s, int i)
039    {
040        strform_ = "";
041        schema_ = null;
042        table_ = null;
043        column_ = null;
044        alias_ = null;
045        form_ = FORM_COLUMN;
046        form_ = i;
047        strform_ = new String(s);
048        StringTokenizer stringtokenizer = new StringTokenizer(s, ".");
049        switch(stringtokenizer.countTokens())
050        {
051        case 1: // '\001'
052            if(i == FORM_TABLE)
053                table_ = new String(stringtokenizer.nextToken());
054            else
055                column_ = new String(stringtokenizer.nextToken());
056            break;
057
058        case 2: // '\002'
059            if(i == FORM_TABLE)
060            {
061                schema_ = new String(stringtokenizer.nextToken());
062                table_ = new String(stringtokenizer.nextToken());
063            } else
064            {
065                table_ = new String(stringtokenizer.nextToken());
066                column_ = new String(stringtokenizer.nextToken());
067            }
068            break;
069
070        case 3: // '\003'
071        default:
072            schema_ = new String(stringtokenizer.nextToken());
073            table_ = new String(stringtokenizer.nextToken());
074            column_ = new String(stringtokenizer.nextToken());
075            break;
076        }
077    }
078
079    public String toString()
080    {
081        if(alias_ == null)
082            return strform_;
083        return strform_ + " " + alias_;
084    }
085
086    public String getSchema()
087    {
088        return schema_;
089    }
090
091    public String getTable()
092    {
093        return table_;
094    }
095
096    public String getColumn()
097    {
098        return column_;
099    }
100
101    public boolean isWildcard()
102    {
103        if(form_ == FORM_TABLE)
104            return table_ != null && table_.equals("*");
105        return column_ != null && column_.indexOf('*') >= 0;
106    }
107
108    public String getAlias()
109    {
110        return alias_;
111    }
112
113    public void setAlias(String s)
114    {
115        alias_ = new String(s);
116    }
117    
118
119    String strform_;
120    String schema_;
121    String table_;
122    String column_;
123    String alias_;
124    public static int FORM_TABLE = 1;
125    public static int FORM_COLUMN = 2;
126    int form_;
127
128}