1 /* 2 * ModeShape (http://www.modeshape.org) 3 * See the COPYRIGHT.txt file distributed with this work for information 4 * regarding copyright ownership. Some portions may be licensed 5 * to Red Hat, Inc. under one or more contributor license agreements. 6 * See the AUTHORS.txt file in the distribution for a full listing of 7 * individual contributors. 8 * 9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape 10 * is licensed to you under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation; either version 2.1 of 12 * the License, or (at your option) any later version. 13 * 14 * ModeShape is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this software; if not, write to the Free 21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 23 */ 24 package org.modeshape.graph.query.model; 25 26 import net.jcip.annotations.Immutable; 27 import org.modeshape.common.util.CheckArg; 28 29 /** 30 * 31 */ 32 @Immutable 33 public abstract class Selector implements Source { 34 private static final long serialVersionUID = 1L; 35 36 private final SelectorName name; 37 private final SelectorName alias; 38 39 /** 40 * Create a selector with a name. 41 * 42 * @param name the name for this selector 43 * @throws IllegalArgumentException if the selector name is null 44 */ 45 protected Selector( SelectorName name ) { 46 CheckArg.isNotNull(name, "name"); 47 this.name = name; 48 this.alias = null; 49 } 50 51 /** 52 * Create a selector with the supplied name and alias. 53 * 54 * @param name the name for this selector 55 * @param alias the alias for this selector; may be null 56 * @throws IllegalArgumentException if the selector name is null 57 */ 58 protected Selector( SelectorName name, 59 SelectorName alias ) { 60 CheckArg.isNotNull(name, "name"); 61 this.name = name; 62 this.alias = alias; 63 } 64 65 /** 66 * Get the name for this selector. 67 * 68 * @return the selector name; never null 69 */ 70 public SelectorName name() { 71 return name; 72 } 73 74 /** 75 * Get the alias name for this source, if there is one. 76 * 77 * @return the alias name, or null if there is none. 78 */ 79 public SelectorName alias() { 80 return alias; 81 } 82 83 /** 84 * Get the alias if this selector has one, or the name. 85 * 86 * @return the alias or name; never null 87 */ 88 public SelectorName aliasOrName() { 89 return alias != null ? alias : name; 90 } 91 92 /** 93 * Determine if this selector has an alias. 94 * 95 * @return true if this selector has an alias, or false otherwise. 96 */ 97 public boolean hasAlias() { 98 return alias != null; 99 } 100 }