Importing some code
* Various annotations * New component information class
This commit is contained in:
parent
48466ed511
commit
e2de94eb7b
14 changed files with 826 additions and 0 deletions
src/main/java/info/ebenoit/ebul/cmp
113
src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java
Normal file
113
src/main/java/info/ebenoit/ebul/cmp/DependencyInfo.java
Normal file
|
@ -0,0 +1,113 @@
|
|||
package info.ebenoit.ebul.cmp;
|
||||
|
||||
|
||||
/**
|
||||
* This class carries information about a dependency's target. Dependencies may be specified by name or by type.
|
||||
*
|
||||
* @author <a href="mailto:ebenoit@ebenoit.info">E. Benoît</a>
|
||||
*/
|
||||
public class DependencyInfo
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the component being depended upon, or <code>null</code> if the dependency information is based on
|
||||
* type.
|
||||
*/
|
||||
private final String name;
|
||||
/**
|
||||
* The type of the component being depended upon, or <code>null</code> if the dependency information is based on the
|
||||
* name.
|
||||
*/
|
||||
private final Class< ? > klass;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a name-based dependency information record
|
||||
*
|
||||
* @param name
|
||||
* the name of the component being depended upon
|
||||
*/
|
||||
public DependencyInfo( final String name )
|
||||
{
|
||||
this.name = name;
|
||||
this.klass = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a type-based dependency information record
|
||||
*
|
||||
* @param klass
|
||||
* the type of the component being depended upon
|
||||
* @throws ComponentDefinitionException
|
||||
* if the specified type is not supported (e.g. primitives or arrays)
|
||||
*/
|
||||
public DependencyInfo( final Class< ? > klass )
|
||||
throws ComponentDefinitionException
|
||||
{
|
||||
this.name = null;
|
||||
this.klass = klass;
|
||||
if ( klass.isPrimitive( ) ) {
|
||||
throw new ComponentDefinitionException( "specified dependency is a primitive type" );
|
||||
}
|
||||
if ( klass.isArray( ) ) {
|
||||
throw new ComponentDefinitionException( "specified dependency is an array type" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode( )
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ( this.klass == null ? 0 : this.klass.hashCode( ) );
|
||||
result = prime * result + ( this.name == null ? 0 : this.name.hashCode( ) );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if ( this == obj ) {
|
||||
return true;
|
||||
}
|
||||
if ( obj == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( this.getClass( ) != obj.getClass( ) ) {
|
||||
return false;
|
||||
}
|
||||
final DependencyInfo other = (DependencyInfo) obj;
|
||||
if ( this.klass == null ) {
|
||||
if ( other.klass != null ) {
|
||||
return false;
|
||||
}
|
||||
return this.name.equals( other.name );
|
||||
} else if ( this.klass != other.klass ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the name of the component being depended upon, or <code>null</code> if the dependency information is
|
||||
* based on type.
|
||||
*/
|
||||
public String getTargetName( )
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the type of the component being depended upon, or <code>null</code> if the dependency information is
|
||||
* based on the name.
|
||||
*/
|
||||
public Class< ? > getTargetClass( )
|
||||
{
|
||||
return this.klass;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue