Skip to content

Commit

Permalink
javadocs/comments/toStrings
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@378 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Nov 28, 2008
1 parent 6525e24 commit 7ed0252
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 74 deletions.
Expand Up @@ -29,15 +29,19 @@
/**
* Meta model for the merged stereotype for a bean
*
* @author pmuir
*
* @author Pete Muir
*/
public class MergedStereotypes<T, E>
{
// The possible deployment types
private AnnotationMap possibleDeploymentTypes;
// The possible scope types
private Set<Annotation> possibleScopeTypes;
// Is the bean name defaulted?
private boolean beanNameDefaulted;
// The required types
private Set<Class<?>> requiredTypes;
// The supported scopes
private Set<Class<? extends Annotation>> supportedScopes;

/**
Expand Down Expand Up @@ -148,6 +152,11 @@ public boolean isDeclaredInXml()
return false;
}

/**
* Gets a string representation of the merged stereotypes
*
* @return The string representation
*/
@Override
public String toString()
{
Expand Down
@@ -1,3 +1,20 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jboss.webbeans.model;

import java.lang.annotation.Annotation;
Expand All @@ -7,58 +24,106 @@
import org.jboss.webbeans.introspector.AnnotatedAnnotation;
import org.jboss.webbeans.introspector.jlr.AnnotatedAnnotationImpl;

/**
* Abstract representation of an annotation model
*
* @author Pete Muir
*/
public abstract class AnnotationModel<T extends Annotation>
{

// The underlying annotation
private AnnotatedAnnotation<T> annotatedAnnotation;
// Is the data valid?
private boolean valid;


/**
* Constructor
*
* @param type The annotation type
*/
public AnnotationModel(Class<T> type)
{
this.annotatedAnnotation = new AnnotatedAnnotationImpl<T>(type);
init();
}


/**
* Initializes the type and validates it
*/
protected void init()
{
initType();
initValid();
}


/**
* Initializes the type
*/
protected void initType()
{
if (!Annotation.class.isAssignableFrom(getType()))
{
throw new DefinitionException(getMetaAnnotation().toString() + " can only be applied to an annotation, it was applied to " + getType());
}
}


/**
* Validates the data for correct annotation
*/
protected void initValid()
{
this.valid = annotatedAnnotation.isAnnotationPresent(getMetaAnnotation());
}

/**
* Gets the type of the annotation
*
* @return The type
*/
public Class<T> getType()
{
return annotatedAnnotation.getType();
}


/**
* Gets the meta-annotation that should be present
*
* @return
*/
protected abstract Class<? extends Annotation> getMetaAnnotation();


/**
* Indicates if the annotation is valid
*
* @return True if valid, false otherwise
*/
public boolean isValid()
{
return valid;
}


/**
* Gets the annotated annotation
*
* @return The annotation
*/
protected AnnotatedAnnotation<T> getAnnotatedAnnotation()
{
return annotatedAnnotation;
}


/**
* Gets a string representation of the annotation
*
* @return The string representation
*/
@Override
public String toString()
{
return getClass().getSimpleName() + "[" + getAnnotatedAnnotation().toString() + "]";
StringBuffer buffer = new StringBuffer();
buffer.append("AnnotationModel:\n");
buffer.append("Annotated annotation: " + getAnnotatedAnnotation().toString());
buffer.append("Valid: " + isValid());
return buffer.toString();
}

}
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/


package org.jboss.webbeans.model;

import java.lang.annotation.Annotation;
Expand All @@ -33,27 +32,39 @@
* Model of a binding type
*
* @author Pete Muir
*
*
*/
public class BindingTypeModel<T extends Annotation> extends AnnotationModel<T>
{

// The non-binding types
private Set<AnnotatedMethod<?>> nonBindingTypes;
// The hash code
private Integer hashCode;


/**
* Constructor
*
* @param type The type
*/
public BindingTypeModel(Class<T> type)
{
super(type);
}


/**
* Initializes the non-binding types and validates the members
*/
@Override
protected void init()
{
super.init();
initNonBindingTypes();
checkArrayAndAnnotationValuedMembers();
}


/**
* Validates the members
*/
private void checkArrayAndAnnotationValuedMembers()
{
for (AnnotatedMethod<?> annotatedMethod : getAnnotatedAnnotation().getMembers())
Expand All @@ -63,30 +74,56 @@ private void checkArrayAndAnnotationValuedMembers()
throw new DefinitionException("Member of array type or annotation type must be annotated @NonBinding " + annotatedMethod);
}
}

}

/**
* Gets the meta-annotation type
*
* @return The BindingType class
*/
@Override
protected Class<? extends Annotation> getMetaAnnotation()
{
return BindingType.class;
}


/**
* Indicates if there are non-binding types present
*
* @return True if present, false otherwise
*/
public boolean hasNonBindingTypes()
{
return nonBindingTypes.size() > 0;
}


/**
* Gets the non-binding types
*
* @return A set of non-binding types, or an empty set if there are none
* present
*/
public Set<AnnotatedMethod<?>> getNonBindingTypes()
{
return nonBindingTypes;
}


/**
* Initializes the non-binding types
*/
protected void initNonBindingTypes()
{
nonBindingTypes = getAnnotatedAnnotation().getAnnotatedMembers(NonBinding.class);
}


/**
* Comparator for checking equality
*
* @param instance The instance to check against
* @param other The other binding type
* @return True if equal, false otherwise
*/
public boolean isEqual(Annotation instance, Annotation other)
{
if (instance.annotationType().equals(getType()) && other.annotationType().equals(getType()))
Expand All @@ -107,19 +144,26 @@ public boolean isEqual(Annotation instance, Annotation other)
}
return false;
}


/**
* Gets a string representation of the stereotype
*
* @return The string representation
*/
@Override
public String toString() {
public String toString()
{
StringBuffer buffer = new StringBuffer();
buffer.append("Binding type model\n");
buffer.append("Hash code : " + hashCode() + "\n");
buffer.append("Valid : " + isValid() + "\n");
buffer.append("Non-binding types\n");
for (AnnotatedMethod<?> method : nonBindingTypes) {
method.toString();
buffer.append("BindingTypeModel:\n");
buffer.append(super.toString());
buffer.append("Hash code: " + hashCode);
buffer.append("Non-binding types: " + nonBindingTypes.size());
int i = 0;
for (AnnotatedMethod<?> nonBindingType : getNonBindingTypes())
{
buffer.append(++i + " - " + nonBindingType.toString());
}
buffer.append("Annotated type " + getAnnotatedAnnotation().getName() + "\n");
return buffer.toString();
}

}

0 comments on commit 7ed0252

Please sign in to comment.