Skip to content

Instantly share code, notes, and snippets.

@nateyolles
Created May 25, 2017 20:36
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save nateyolles/5b92320d2efff785d4c4c0d066a3bcee to your computer and use it in GitHub Desktop.
Save nateyolles/5b92320d2efff785d4c4c0d066a3bcee to your computer and use it in GitHub Desktop.
OSGi Declarative Services Annotations
package com.nateyolles.aem.osgiannotationdemo.core.services.impl;
import org.apache.commons.lang3.StringUtils;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.AttributeType;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.osgi.service.metatype.annotations.Option;
@ObjectClassDefinition(name = "Annotation Demo Service - OSGi")
public @interface Configuration {
@AttributeDefinition(
name = "Boolean Property",
description = "Sample boolean value",
type = AttributeType.BOOLEAN
)
boolean servicename_propertyname_boolean() default true;
@AttributeDefinition(
name = "String Property",
description = "Sample String property",
type = AttributeType.STRING
)
String servicename_propertyname_string() default "foo";
@AttributeDefinition(
name = "Dropdown property",
description = "Sample dropdown property",
options = {
@Option(label = "DAYS", value = "DAYS"),
@Option(label = "HOURS", value = "HOURS"),
@Option(label = "MILLISECONDS", value = "MILLISECONDS"),
@Option(label = "MINUTES", value = "MINUTES"),
@Option(label = "SECONDS", value = "SECONDS")
}
)
String servicename_propertyname_dropdown() default StringUtils.EMPTY;
@AttributeDefinition(
name = "String Array Property",
description = "Sample String array property",
type = AttributeType.STRING
)
String[] servicename_propertyname_string_array() default {"foo", "bar"};
/*
* To create password field, either set the AttributeType or have the
* property name end with "*.password" (or both).
*/
@AttributeDefinition(
name = "Password Property",
description = "Sample password property",
type = AttributeType.PASSWORD
)
String servicename_propertyname_password() default StringUtils.EMPTY;
@AttributeDefinition(
name = "Long Property",
description = "Sample long property",
type = AttributeType.LONG
)
long servicename_propertyname_long() default 0L;
}
@AquilaVasc
Copy link

Hey, recently I've struggled a configuration using ObjectClassDefinition to show up in my ConfigMgr Console, Is there any specific plugins or dependencies I should be using? the code builds just fine but when I go to the console I can't see the config there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment