@Config(name="B") public static class B { private String name; public B () { } public B (String name) { this.name = name; } public String getName() { return name; } }
private String getSchemaName(Class<?> type) { Config configurable = type.getAnnotation(Config.class); String schemaName = configurable.name(); if (schemaName == null || "".equals(schemaName)) { schemaName = type.getName(); } return schemaName; }
@Override public Schema convert(Class<?> source, Class<? extends Schema> specificType) { ClassIntrospector introspector = new ClassIntrospector(source); Config config = introspector.getAnnotation(Config.class); if (config == null) { throw CFG102_NOT_CONFIGURABLE(source); } SchemaId schemaId = getId(introspector); if (schemaId == null) { // lookup instance does not have @Id annotations so we create // it from the @Config annotation schemaId = SchemaId.create(config.name(), config.desc(), true); } String schemaName = config.name(); if (schemaName == null || "".equals(schemaName)) { schemaName = source.getName(); } Schema schema = Schema.create(schemaId, introspector.getName(), schemaName, config.desc()); Collection<Object> fields = new ArrayList<>(); fields.addAll(introspector.getNonStaticFieldList()); Collection<AbstractSchemaProperty> props = conversion.convert(fields, AbstractSchemaProperty.class); for (AbstractSchemaProperty abstractProp : props) { schema.add(abstractProp); } return schema; }
@Config(name="A") public static class A { private String name; public A () { } public A (String name) { this.name = name; } public String getName() { return name; } }
private BeanId getBeanId(Object bean) { Config config = bean.getClass().getAnnotation(Config.class); if (config == null) { throw CFG102_NOT_CONFIGURABLE(bean.getClass()); } String schemaName = config.name(); if (schemaName == null || "".equals(schemaName.trim())) { schemaName = bean.getClass().getName(); } ClassIntrospector i = new ClassIntrospector(bean.getClass()); List<FieldWrap> ids = i.getFieldList(Id.class); if (ids == null || ids.size() != 1) { // a lookup return BeanId.createSingleton(schemaName); } FieldWrap id = ids.get(0); BeanId targetId; Object idValue = id.getValue(bean); if (idValue == null) { throw Events.CFG107_MISSING_ID(); } targetId = BeanId.create(id.getValue(bean).toString(), schemaName); return targetId; }
@Config(name = SINGLETON_PARENT_SCHEMA_NAME, desc = "") public static class SingletonParent { @Config(desc = "") private Singleton singleton; @Config(desc = "") private String property; public SingletonParent() { } public String getProperty() { return property; } public Singleton getSingleton() { return singleton; } public void setSingleton(Singleton singleton) { this.singleton = singleton; } }
@Override public void register(Class<?>... classes) { for (Class<?> cls : classes) { if (CLASS_TO_SCHEMA.get(cls) != null) { continue; } ClassIntrospector introspector = new ClassIntrospector(cls); Config config = introspector.getAnnotation(Config.class); if (config == null) { throw CFG102_NOT_CONFIGURABLE(cls); } String schemaName = config.name(); if (schemaName == null || "".equals(schemaName)) { schemaName = cls.getName(); } Schema schema = CONVERSION.convert(cls, Schema.class); CLASS_TO_SCHEMA.put(cls, schema); NAME_TO_SCHEMA.put(schemaName, schema); for (Class<?> refCls : schema.getReferenceSchemaTypes()) { if (CLASS_TO_SCHEMA.get(refCls) != null) { register(cls); } } } }
@Config(name = SINGLETON_SCHEMA_NAME, desc = "") public static class Singleton { @Config(desc = "") private String property; @Config(desc="") private Parent parent; public BeanId getBeanId() { return BeanId.createSingleton(SINGLETON_SCHEMA_NAME); } public String getProperty() { return property; } public Parent getParent() { return parent; } public void setProperty(String property) { this.property = property; } }
@Config(name = "person", desc = "desc") public static class Person { @Id(desc = "") private String id; @Config(desc = "") private Person bestFriend; @Config(desc = "") private List<Person> closeFriends = new ArrayList<>(); @Config(desc = "") private Map<String, Person> colleauges = new HashMap<>(); public Person(String id) { this.id = id; } public Person() { } }
@ConfigScope @Config(name = "cluster", desc = "Server cluster configuration. Changes requires server restart.") public class ClusterConfig { @Config(desc="Server that are configured as members of this cluster.") private List<ServerConfig> servers = new ArrayList<>(); public List<ServerConfig> getServers() { return servers; } public void setServers(List<ServerConfig> servers) { this.servers = servers; } public void addServer(ServerConfig server) { servers.add(server); } }
@Config(name = "CdiSingletonConfig", desc = "A cdi enabled lookup configuration") @ConfigScope public class CdiSingletonConfig { @Config(desc = "value") private String value = "value"; public CdiSingletonConfig() { } public CdiSingletonConfig(String value) { this.value = value; } public String getValue() { return value; } }
@Config(name = "web", desc = "Static web configuration. Changes requires server restart.") @ConfigScope public class WebConfig { @Config(desc = "URI where static web content is mounted.") @NotNull private String uri = "/"; public String getUri() { return uri; } public void setUri(String uri) { this.uri = uri; } }
@Config(name = "jobs", desc = "Configuration for a specific job") public class JobConfig { @Id(desc = "id") private String id; @Config(desc = "Cron expression used for job scheduling.") private String cronExpression; public JobConfig() { } public JobConfig(String id) { this.id = id; } public String getId() { return id; } public String getCronExpression() { return cronExpression; } }
@Config(name = "job", desc = "Job scheduler configuration. Changes requires restart.") @ConfigScope public class JobSchedulerConfig { @Config(desc = "See org.quartz.scheduler.instanceName") private String instanceName = "QuartzScheduler"; @Config(desc = "See org.quartz.scheduler.instanceId") private String instanceId = "AUTO"; @Config(desc = "See org.quartz.jobStore.isClustered") private Boolean isClustered = true; @Config(desc = "See org.quartz.scheduler.idleWaitTime") private Long idleTimeWait = 5000L; @Config(desc = "See org.quartz.scheduler.dbFailureRetryInterval") private Long dbFailureRetryInterval = 15000L; @Config(desc = "See org.quartz.jobStore.clusterCheckinInterval") private Long clusterCheckinInterval = 7500L; @Config(desc = "See org.quartz.scheduler.batchTriggerAcquisitionMaxCount") private Integer batchTriggerAcquisitionMaxCount = 10; @Config(desc = "See org.quartz.scheduler.batchTriggerAcquisitionFireAheadTimeWindow") private Long batchTriggerAcquisitionFireAheadTimeWindow = 0L;
@ConfigScope @Config(name = "executor", desc = "Thread pool executor. Changes requires server restart.") public class ExecutorConfig { @Config(desc = "The maximum number of active threads.") @NotNull @Size(min = 1, max = 65535) private Integer corePoolSize = 20; @Config(desc = "The maximum total size of the queued events in bytes. 0 to disable.") @NotNull private Long maxChannelMemorySize = 1048560L; @Config(desc = "The maximum total size of the queued events. 0 to disable.") @NotNull private Long maxTotalMemorySize = 16776960L; @Config(desc = "The amount of time for an inactive thread to shut itself down in seconds.") @NotNull private Integer keepAliveTime = 60;
@Config(name = "binarytree", desc = "A binary tree") @BinaryTreeConstraint public class BinaryTree { private String id; @Config(desc = "value of the current tree") @NotNull private Integer value; @Config(desc = "parent tree") private BinaryTree parent; @Config(desc = "left tree") private BinaryTree left; @Config(desc = "right tree") private BinaryTree right;
@Config(name="jpa") @ConfigScope public class JpaConfig { @Config(name = JPA_UNIT) private String unit = JPA_UNIT_DEFAULT; @Config(name = USER) private String user; @Config(name = PASSWORD) private String password; @Config(name = URL) private String url; @Config(name = DRIVER) private String driver; @Config(name = PROVIDER) private String provider = "org.hibernate.ejb.HibernatePersistence"; @Config(name = TX_TYPE) private String txType = "RESOURCE_LOCAL"; @Config(name = VALIDATION_MODE) private String validationMode; @Config(name = VALIDATION_PRE_PERSIST)