001 /*
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.
005 *
006 * The contents of this file are subject to the terms of either the GNU
007 * General Public License Version 2 only ("GPL") or the Common Development
008 * and Distribution License("CDDL") (collectively, the "License"). You
009 * may not use this file except in compliance with the License. You can
010 * obtain a copy of the License at
011 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
012 * or packager/legal/LICENSE.txt. See the License for the specific
013 * language governing permissions and limitations under the License.
014 *
015 * When distributing the software, include this License Header Notice in each
016 * file and include the License file at packager/legal/LICENSE.txt.
017 *
018 * GPL Classpath Exception:
019 * Oracle designates this particular file as subject to the "Classpath"
020 * exception as provided by Oracle in the GPL Version 2 section of the License
021 * file that accompanied this code.
022 *
023 * Modifications:
024 * If applicable, add the following below the License Header, with the fields
025 * enclosed by brackets [] replaced by your own identifying information:
026 * "Portions Copyright [year] [name of copyright owner]"
027 *
028 * Contributor(s):
029 * If you wish your version of this file to be governed by only the CDDL or
030 * only the GPL Version 2, indicate your decision by adding "[Contributor]
031 * elects to include this software in this distribution under the [CDDL or GPL
032 * Version 2] license." If you don't indicate a single choice of license, a
033 * recipient has the option to distribute your version of this file under
034 * either the CDDL, the GPL Version 2 or to extend the choice of license to
035 * its licensees as provided above. However, if you add GPL Version 2 code
036 * and therefore, elected the GPL Version 2 license, then the option applies
037 * only if the new code is made subject to such option by the copyright
038 * holder.
039 */
040
041 package com.sun.enterprise.admin.cli.schemadoc;
042
043 import java.util.HashMap;
044 import java.util.HashSet;
045 import java.util.Map;
046 import java.util.Set;
047 import java.util.TreeMap;
048 import java.util.TreeSet;
049 import java.util.Comparator;
050 import java.util.List;
051
052 import org.jvnet.hk2.config.Dom;
053 import org.jvnet.hk2.config.Attribute;
054 import org.glassfish.api.admin.config.PropertyDesc;
055
056 /**
057 * Contains metadata information about a class
058 */
059 public class ClassDef {
060 private final String def;
061 private List<String> interfaces;
062 private Set<ClassDef> subclasses = new HashSet<ClassDef>();
063 private Map<String, String> types = new HashMap<String, String>();
064 private Map<String, Attribute> attributes = new TreeMap<String, Attribute>();
065 private boolean deprecated;
066 private Set<PropertyDesc> properties = new TreeSet<PropertyDesc>(new Comparator<PropertyDesc>() {
067 @Override
068 public int compare(PropertyDesc left, PropertyDesc right) {
069 return left.name().compareTo(right.name());
070 }
071 });
072
073 public ClassDef(String def, List<String> interfaces) {
074 this.def = def;
075 this.interfaces = interfaces;
076 }
077
078 public String getDef() {
079 return def;
080 }
081
082 public List<String> getInterfaces() {
083 return interfaces;
084 }
085
086 @Override
087 public boolean equals(Object o) {
088 if (this == o) {
089 return true;
090 }
091 if (o == null || getClass() != o.getClass()) {
092 return false;
093 }
094 final ClassDef classDef = (ClassDef) o;
095 if (def != null ? !def.equals(classDef.def) : classDef.def != null) {
096 return false;
097 }
098 return true;
099 }
100
101 @Override
102 public int hashCode() {
103 return def != null ? def.hashCode() : 0;
104 }
105
106 public void addSubclass(ClassDef classDef) {
107 subclasses.add(classDef);
108 }
109
110 public Set<ClassDef> getSubclasses() {
111 return subclasses;
112 }
113
114 public void addAggregatedType(String name, String type) {
115 types.put(name, type);
116 }
117
118 public Map<String, String> getAggregatedTypes() {
119 return types;
120 }
121
122 @Override
123 public String toString() {
124 return def;
125 }
126
127 public Map<String, Attribute> getAttributes() {
128 return attributes;
129 }
130
131 public void addAttribute(String name, Attribute annotation) {
132 attributes.put(Dom.convertName(name), annotation);
133 }
134
135 public void removeAttribute(String name) {
136 attributes.remove(Dom.convertName(name));
137 }
138
139 public boolean isDeprecated() {
140 return deprecated;
141 }
142
143 public void setDeprecated(boolean deprecated) {
144 this.deprecated = deprecated;
145 }
146
147 public Set<PropertyDesc> getProperties() {
148 return properties;
149 }
150
151 public void addProperty(PropertyDesc prop) {
152 properties.add(prop);
153 }
154
155 public String getXmlName() {
156 return Dom.convertName(def.substring(def.lastIndexOf(".")+1));
157 }
158 }