001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2013 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.api.resources;
021
022import org.apache.commons.lang.StringUtils;
023import org.apache.commons.lang.builder.ToStringBuilder;
024
025/**
026 * A class that represents a Java package in Sonar
027 * 
028 * @since 1.10
029 */
030public class JavaPackage extends Resource {
031
032  /**
033   * Default package name for classes without package definition
034   */
035  public static final String DEFAULT_PACKAGE_NAME = "[default]";
036
037  /**
038   * Default constructor
039   */
040  public JavaPackage() {
041    this(null);
042  }
043
044  /**
045   * Creates a JavaPackage from its key. Will use DEFAULT_PACKAGE_NAME if key is null
046   */
047  public JavaPackage(String key) {
048    setKey(StringUtils.defaultIfEmpty(StringUtils.trim(key), DEFAULT_PACKAGE_NAME));
049  }
050
051  /**
052   * @return whether the JavaPackage key is the default key
053   */
054  public boolean isDefault() {
055    return StringUtils.equals(getKey(), DEFAULT_PACKAGE_NAME);
056  }
057
058  /**
059   * {@inheritDoc}
060   */
061  @Override
062  public boolean matchFilePattern(String antPattern) {
063    return false;
064  }
065
066  /**
067   * {@inheritDoc}
068   */
069  @Override
070  public String getDescription() {
071    return null;
072  }
073
074  /**
075   * @return SCOPE_SPACE
076   */
077  @Override
078  public String getScope() {
079    return Scopes.DIRECTORY;
080  }
081
082  /**
083   * @return QUALIFIER_PACKAGE
084   */
085  @Override
086  public String getQualifier() {
087    return Qualifiers.PACKAGE;
088  }
089
090  /**
091   * {@inheritDoc}
092   */
093  @Override
094  public String getName() {
095    return getKey();
096  }
097
098  /**
099   * {@inheritDoc}
100   */
101  @Override
102  public Resource getParent() {
103    return null;
104  }
105
106  /**
107   * {@inheritDoc}
108   */
109  @Override
110  public String getLongName() {
111    return null;
112  }
113
114  /**
115   * @return Java
116   */
117  @Override
118  public Language getLanguage() {
119    return Java.INSTANCE;
120  }
121
122  @Override
123  public String toString() {
124    return new ToStringBuilder(this)
125        .append("id", getId())
126        .append("key", getKey())
127        .toString();
128  }
129}