001 /* 002 * Copyright 2005 Stephen J. McConnell 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.library.info; 020 021 import java.util.Properties; 022 023 import net.dpml.lang.Version; 024 025 import net.dpml.library.Type; 026 027 import org.w3c.dom.Element; 028 029 /** 030 * The ModuleDirective class describes a module data-structure. 031 * 032 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 033 * @version 1.1.2 034 */ 035 public class TypeDirective extends DataDirective implements Type 036 { 037 private final String m_name; 038 private final Version m_version; 039 040 /** 041 * Creation of a new type directive. 042 * @param name the name 043 */ 044 public TypeDirective( String name ) 045 { 046 this( name, null ); 047 } 048 049 /** 050 * Creation of a new type directive. 051 * @param name the name 052 * @param version alias version 053 */ 054 public TypeDirective( String name, Version version ) 055 { 056 this( (Element) null, name, version ); 057 } 058 059 /** 060 * Creation of a new type directive. 061 * @param element DOM element defining the type 062 * @param id the type id 063 * @param version alias version 064 */ 065 public TypeDirective( Element element, String id, Version version ) 066 { 067 super( element ); 068 if( null == id ) 069 { 070 throw new NullPointerException( "id" ); 071 } 072 m_name = id; 073 m_version = version; 074 } 075 076 /** 077 * Creation of a new generic type directive. 078 * @param id the type id 079 * @param version alias version 080 * @param properties supplimentary properties 081 */ 082 public TypeDirective( String id, Version version, Properties properties ) 083 { 084 super( properties ); 085 if( null == id ) 086 { 087 throw new NullPointerException( "id" ); 088 } 089 m_name = id; 090 m_version = version; 091 } 092 093 /** 094 * Return the type name. 095 * @return the name 096 */ 097 public String getID() 098 { 099 return m_name; 100 } 101 102 /** 103 * Return the alias version. 104 * @return the alias version 105 */ 106 public Version getVersion() 107 { 108 return m_version; 109 } 110 111 /** 112 * Compare this object with another for equality. 113 * @param other the other object 114 * @return true if equal 115 */ 116 public boolean equals( Object other ) 117 { 118 if( super.equals( other ) && ( other instanceof TypeDirective ) ) 119 { 120 TypeDirective object = (TypeDirective) other; 121 if( !m_name.equals( object.m_name ) ) 122 { 123 return false; 124 } 125 else 126 { 127 return equals( m_version, object.m_version ); 128 } 129 } 130 else 131 { 132 return false; 133 } 134 } 135 136 /** 137 * Compute the hash value. 138 * @return the hascode value 139 */ 140 public int hashCode() 141 { 142 int hash = super.hashCode(); 143 hash ^= hashValue( m_name ); 144 hash ^= hashValue( m_version ); 145 return hash; 146 } 147 148 /** 149 * Return a string representation of the type. 150 * @return the string value 151 */ 152 public String toString() 153 { 154 return "type:" + m_name; 155 } 156 }