Announcement Announcement Module
Collapse
No announcement yet.
How to init field in roo Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to init field in roo

    Hi,

    I just want to ask how to initialize field in spring roo.
    For example:
    Code:
    private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(Foo.class);
    I created field in Metadata class like this:
    Code:
    int modifier = 0;
    final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), modifier,
    new ArrayList<AnnotationMetadataBuilder>(), // No annotations for this field
    new JavaSymbolName("LOGGER"), // Field name
    new JavaType("org.slf4j.Logger")); // Field type
    fieldBuilder.build(); // Build a FieldMetadata instance
    But this provides package protection, not private. Modifier is 0.
    Can I use private modifier? And what are key - values pairs?

    And I don't know how to initialize this field. Maybe FieldInitializer?

    Thanks for any advices.

  • #2
    I assumed that modifier could be same as java.lang.reflect.Modifier

    where are listed modifiers

    Code:
    public static final int PRIVATE          = 0x00000002;
    public static final int STATIC           = 0x00000008;
    public static final int FINAL            = 0x00000010;
    But how to combine it?

    Comment


    • #3
      Code:
      int PUBLIC_STATIC_FINAL_MODIFIER = 0x00000012; //19
      or
      Code:
      int PUBLIC_STATIC_FINAL_MODIFIER = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL;
      Initializing fields can be made by

      Code:
      /**
           * Constructor for a builder with the given field values
           * 
           * @param declaredbyMetadataId a MID for a specific instance
           * @param modifier as per {@link java.lang.reflect.Modifier}
           * @param fieldName the field name (required)
           * @param fieldType the field type (required)
           * @param fieldInitializer the Java expression for the field's initial value
           *            (can be <code>null</code> for none)
           */
          public FieldMetadataBuilder(final String declaredbyMetadataId,
                  final int modifier, final JavaSymbolName fieldName,
                  final JavaType fieldType, final String fieldInitializer)
      String fieldInitializer can then be
      Code:
      new LocalServiceTestHelper(new com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig())

      Comment

      Working...
      X