From 787f704735f928bee4ea573f4db75e1cfd3bd874 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Fri, 2 Nov 2012 09:25:26 -0500 Subject: [PATCH] Fix default value handling --- .../main/java/example1/LoggingSubsystemResource.java | 5 ++--- example/src/main/java/example1/PathResource.java | 10 +++++++++- example/src/main/java/example1/SubsystemResource.java | 4 ++++ .../main/java/org/jboss/mgmt/annotation/Attribute.java | 7 ------- .../org/jboss/mgmt/generator/ProcessingContext.java | 6 ++++-- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/example/src/main/java/example1/LoggingSubsystemResource.java b/example/src/main/java/example1/LoggingSubsystemResource.java index 0385d9e..4302c1b 100644 --- a/example/src/main/java/example1/LoggingSubsystemResource.java +++ b/example/src/main/java/example1/LoggingSubsystemResource.java @@ -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; @@ -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 getHandlers(); @SubResource diff --git a/example/src/main/java/example1/PathResource.java b/example/src/main/java/example1/PathResource.java index 8e01bcb..209a1fb 100644 --- a/example/src/main/java/example1/PathResource.java +++ b/example/src/main/java/example1/PathResource.java @@ -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 David M. Lloyd */ public interface PathResource extends Resource { - + @Required @Attribute + String getPath(); + + @Reference(scopeName = "core.paths") @Attribute + ResourceRef getRelativeTo(); } diff --git a/example/src/main/java/example1/SubsystemResource.java b/example/src/main/java/example1/SubsystemResource.java index 354a8a7..4db4b83 100644 --- a/example/src/main/java/example1/SubsystemResource.java +++ b/example/src/main/java/example1/SubsystemResource.java @@ -22,6 +22,7 @@ package example1; +import org.jboss.mgmt.annotation.Attribute; import org.jboss.mgmt.annotation.ResourceType; /** @@ -29,5 +30,8 @@ */ @ResourceType(name = "subsystem") public interface SubsystemResource { + boolean ENABLED_DEFAULT = true; + @Attribute + boolean enabled(); } diff --git a/tool/src/main/java/org/jboss/mgmt/annotation/Attribute.java b/tool/src/main/java/org/jboss/mgmt/annotation/Attribute.java index 28931bb..7831e3b 100644 --- a/tool/src/main/java/org/jboss/mgmt/annotation/Attribute.java +++ b/tool/src/main/java/org/jboss/mgmt/annotation/Attribute.java @@ -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. * diff --git a/tool/src/main/java/org/jboss/mgmt/generator/ProcessingContext.java b/tool/src/main/java/org/jboss/mgmt/generator/ProcessingContext.java index 4dc11eb..1c3c3a7 100644 --- a/tool/src/main/java/org/jboss/mgmt/generator/ProcessingContext.java +++ b/tool/src/main/java/org/jboss/mgmt/generator/ProcessingContext.java @@ -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; @@ -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; }