001/* 002 * Shredzone Commons 003 * 004 * Copyright (C) 2012 Richard "Shred" Körber 005 * http://commons.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU Library General Public License as 009 * published by the Free Software Foundation, either version 3 of the 010 * License, or (at your option) any later version. 011 * 012 * This program is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU Library General Public License 018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 019 */ 020package org.shredzone.commons.taglib.processor; 021 022import java.util.Collection; 023import java.util.HashMap; 024import java.util.Map; 025 026import javax.annotation.Nonnull; 027 028/** 029 * This bean stores all information about a tag library. 030 * 031 * @author Richard "Shred" Körber 032 */ 033public class TaglibBean { 034 035 private Map<String, TagBean> classTagMap = new HashMap<>(); 036 private Map<String, TagBean> tags = new HashMap<>(); 037 038 private String tlibversion; 039 private String jspversion; 040 private String shortname; 041 private String uri; 042 private String info; 043 private String tldName; 044 045 private String beanFactoryReference; 046 047 /** 048 * The tag lib version. 049 */ 050 public String getTlibversion() { return tlibversion; } 051 public void setTlibversion(String tlibversion) { this.tlibversion = tlibversion; } 052 053 /** 054 * The JSP version. 055 */ 056 public String getJspversion() { return jspversion; } 057 public void setJspversion(String jspversion) { this.jspversion = jspversion; } 058 059 /** 060 * The short name of the tag library. 061 */ 062 public String getShortname() { return shortname; } 063 public void setShortname(String shortname) { this.shortname = shortname; } 064 065 /** 066 * The tag library URI. 067 */ 068 public String getUri() { return uri; } 069 public void setUri(String uri) { this.uri = uri; } 070 071 /** 072 * Information about the tag library. 073 */ 074 public String getInfo() { return info; } 075 public void setInfo(String info) { this.info = info; } 076 077 /** 078 * Name of the TLD file. 079 */ 080 public String getTldName() { return tldName; } 081 public void setTldName(String tldName) { this.tldName = tldName; } 082 083 /** 084 * A reference to the bean factory. 085 */ 086 public String getBeanFactoryReference() { return beanFactoryReference; } 087 public void setBeanFactoryReference(String beanFactoryReference) { this.beanFactoryReference = beanFactoryReference; } 088 089 /** 090 * Adds a {@link TagBean} to this tag library. 091 * 092 * @param tag 093 * {@link TagBean} to be added 094 */ 095 public void addTag(@Nonnull TagBean tag) { 096 if (tags.containsKey(tag.getName())) { 097 throw new ProcessorException("Tag '" + tag.getName() + "' already defined"); 098 } 099 tags.put(tag.getName(), tag); 100 classTagMap.put(tag.getClassName(), tag); 101 } 102 103 /** 104 * Gets all tags of this tag library. 105 * 106 * @return Collection of {@link TagBean} 107 */ 108 public @Nonnull Collection<TagBean> getTags() { 109 return tags.values(); 110 } 111 112 /** 113 * Gets the {@link TagBean} that is related to the given implementation class. 114 * 115 * @param className 116 * Implementation class name 117 * @return {@link TagBean} that belongs to that class, or {@code null} if there is 118 * none. 119 */ 120 public TagBean getTagForClass(@Nonnull String className) { 121 return classTagMap.get(className); 122 } 123 124}