001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar 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 * Sonar 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
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.api.qualitymodel;
021
022 import org.apache.commons.lang.builder.ToStringBuilder;
023 import org.apache.commons.lang.builder.ToStringStyle;
024 import org.sonar.api.ServerExtension;
025
026 /**
027 *
028 * This extension point must be implemented to define a new quality model.
029 *
030 * @since 2.3
031 */
032 public abstract class ModelDefinition implements ServerExtension {
033
034 private String name;
035
036 protected ModelDefinition(String name) {
037 this.name = name;
038 }
039
040 public final String getName() {
041 return name;
042 }
043
044 public abstract Model createModel();
045
046 @Override
047 public final boolean equals(Object o) {
048 if (this == o) {
049 return true;
050 }
051 if (o == null || getClass() != o.getClass()) {
052 return false;
053 }
054
055 ModelDefinition that = (ModelDefinition) o;
056 return name.equals(that.name);
057 }
058
059 @Override
060 public final int hashCode() {
061 return name.hashCode();
062 }
063
064 @Override
065 public String toString() {
066 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
067 .append("name", name)
068 .toString();
069 }
070 }