Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
Fix default value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Nov 2, 2012
1 parent 639c595 commit 787f704
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
5 changes: 2 additions & 3 deletions example/src/main/java/example1/LoggingSubsystemResource.java
Expand Up @@ -23,7 +23,6 @@
package example1;

import java.util.Map;
import org.jboss.mgmt.Resource;
import org.jboss.mgmt.annotation.RootResource;
import org.jboss.mgmt.annotation.Provides;
import org.jboss.mgmt.annotation.SubResource;
Expand All @@ -39,9 +38,9 @@
type = "subsystem",
name = "logging"
)
public interface LoggingSubsystemResource extends Resource {
public interface LoggingSubsystemResource extends SubsystemResource {

@SubResource(children = { FileHandlerResource.class })
@SubResource(children = { FileHandlerResource.class }, referenceAs = "core.logging.handlers")
Map<String, HandlerResource> getHandlers();

@SubResource
Expand Down
10 changes: 9 additions & 1 deletion example/src/main/java/example1/PathResource.java
Expand Up @@ -23,10 +23,18 @@
package example1;

import org.jboss.mgmt.Resource;
import org.jboss.mgmt.ResourceRef;
import org.jboss.mgmt.annotation.Attribute;
import org.jboss.mgmt.annotation.Reference;
import org.jboss.mgmt.annotation.Required;

/**
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
*/
public interface PathResource extends Resource {

@Required @Attribute
String getPath();

@Reference(scopeName = "core.paths") @Attribute
ResourceRef<PathResource> getRelativeTo();
}
4 changes: 4 additions & 0 deletions example/src/main/java/example1/SubsystemResource.java
Expand Up @@ -22,12 +22,16 @@

package example1;

import org.jboss.mgmt.annotation.Attribute;
import org.jboss.mgmt.annotation.ResourceType;

/**
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
*/
@ResourceType(name = "subsystem")
public interface SubsystemResource {
boolean ENABLED_DEFAULT = true;

@Attribute
boolean enabled();
}
7 changes: 0 additions & 7 deletions tool/src/main/java/org/jboss/mgmt/annotation/Attribute.java
Expand Up @@ -60,13 +60,6 @@
*/
RunLevel changeRunLevel() default RunLevel.RUNNING;

/**
* The default value, in string form.
*
* @return the default value
*/
String defaultValue() default "";

/**
* Specify whether this attribute my contain an expression.
*
Expand Down
Expand Up @@ -77,6 +77,7 @@
import javax.lang.model.util.Types;

import static javax.tools.Diagnostic.Kind.ERROR;
import static javax.tools.Diagnostic.Kind.NOTE;
import static javax.tools.Diagnostic.Kind.WARNING;
import static org.jboss.mgmt.generator.AnnotationUtils.annotationIs;
import static org.jboss.mgmt.generator.AnnotationUtils.booleanValue;
Expand Down Expand Up @@ -406,8 +407,9 @@ private AttributeValueInfo processNewAttributeValue(String name, ExecutableEleme

for (VariableElement fieldElement : ElementFilter.fieldsIn(env.getElementUtils().getAllMembers(enclosingElement))) {
if (defaultVarName.equals(fieldElement.getSimpleName().toString())) {
if (! isAssignable(fieldElement.asType(), type)) {
messager.printMessage(ERROR, "Cannot assign default property value to property of type " + type, fieldElement);
final TypeMirror fieldType = fieldElement.asType();
if (! isAssignable(fieldType, type)) {
messager.printMessage(ERROR, "Cannot assign default value of type " + fieldType + " to property of type " + type, fieldElement);
} else {
defaultVal = fieldElement;
}
Expand Down

0 comments on commit 787f704

Please sign in to comment.