001    package org.apache.myfaces.tobago.apt.generate;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import java.util.HashSet;
021    import java.util.Set;
022    
023    
024    public class ClassInfo {
025      private String className;
026      private String packageName;
027      private Imports imports;
028      private String superClassName;
029      private Set<String> interfaces = new HashSet<String>();
030      private String sourceClass;
031    
032      public ClassInfo(String sourceClass, String qualifiedName) {
033        this.sourceClass = sourceClass;
034        this.className = ClassUtils.getSimpleName(qualifiedName);
035        this.packageName = ClassUtils.getPackageName(qualifiedName);
036        imports = new Imports(packageName);
037      }
038    
039      public String getClassName() {
040        return className;
041      }
042    
043      public String getPackageName() {
044        return packageName;
045      }
046    
047      public void setSuperClass(String qualifiedName) {
048        String name = ClassUtils.getSimpleName(qualifiedName);
049        if (!name.equals(className)) {
050          imports.addImport(qualifiedName);
051          this.superClassName = name;
052        } else {
053          this.superClassName = qualifiedName;
054        }
055      }
056    
057      public String getSuperClassName() {
058        return superClassName;
059      }
060    
061      public boolean hasSuperClass() {
062        return superClassName != null && superClassName.length() > 0;
063      }
064    
065      public void addImport(String qualifiedName) {
066        imports.addImport(qualifiedName);
067      }
068    
069      public Set<String> getImports() {
070        return imports.getImports();
071      }
072    
073      public void addInterface(String qualifiedName) {
074        String name = ClassUtils.getSimpleName(qualifiedName);
075        if (!name.equals(className)) {
076          imports.addImport(qualifiedName);
077          this.interfaces.add(name);
078        } else {
079          this.interfaces.add(qualifiedName);
080        }
081      }
082    
083      public Set<String> getInterfaces() {
084        return interfaces;
085      }
086    
087      public String getSourceClass() {
088        return sourceClass;
089      }
090    }