All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tldgen.model.Library Maven / Gradle / Ivy

package org.tldgen.model;

import java.util.Set;
import java.util.TreeSet;

/**
 * Holds the information of a JSP tag library, to be written as a TLD  file
 * @author icoloma
 *
 */
public class Library {
	
	/** the data identifying this library */
	private LibrarySignature librarySignature;
	
	/** list of tags in this library */
	private Set tags = new TreeSet();
	
	/** list of functions in this library */
	private Set functions = new TreeSet();

	public Library(LibrarySignature librarySignature) {
		this.librarySignature = librarySignature;
	}

	/**
	 * Convenience method to get tag by name
	 * @return the tag with a matching name,  null if none was found
	 */
	public Tag getTag(String name) {
		for (Tag tag : tags) {
			if (name.equals(tag.getName())) {
				return tag;
			}
		}
		return null;
	}
	
	/**
	 * Convenience method to get function by name
	 * @return the function with a matching name,  null if none was found
	 */
	public Function getFunction(String name) {
		for (Function function : functions) {
			if (name.equals(function.getName())) {
				return function;
			}
		}
		return null;
	}
	
	public void add(Tag tag) {
		tags.add(tag);
	}
	
	public void add(Function function) {
		functions.add(function);
	}
	
	public Set getTags() {
		return tags;
	}

	public Set getFunctions() {
		return functions;
	}

	public LibrarySignature getLibrarySignature() {
		return librarySignature;
	}

	public void validate() {
		if (librarySignature.getShortName() == null) {
			throw new IllegalArgumentException("Attribute shortName for @Library annotation is mandatory.");
		}
		if (librarySignature.getUri() == null) {
			throw new IllegalArgumentException("Attribute uri for library is mandatory.");
		}
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy