@SuppressWarnings("unused") private static void validatePropertyRefMap(Bean bean) { Schema schema = bean.getSchema(); for (SchemaPropertyRefMap prop : schema.get(SchemaPropertyRefMap.class)) { } }
public boolean isProperty(String property) { return getPropertyNames().contains(property); }
public JaxrsSchema(Schema schema) { this.schemaName = schema.getName(); this.className = schema.getType(); this.desc = schema.getDesc(); this.idName = schema.getId().getName(); this.idDesc = schema.getId().getDesc(); this.singleton = schema.getId().isSingleton(); for (Schema.SchemaProperty prop : schema.get(Schema.SchemaProperty.class)) { property.add(new SchemaProperty(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyList prop : schema.get(Schema.SchemaPropertyList.class)) { propertyList.add(new SchemaPropertyList(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyRef prop : schema.get(Schema.SchemaPropertyRef.class)) { propertyRef.add(new SchemaPropertyRef(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyRefList prop : schema.get(Schema.SchemaPropertyRefList.class)) { propertyRefList.add(new SchemaPropertyRefList(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyRefMap prop : schema.get(Schema.SchemaPropertyRefMap.class)) { propertyRefMap.add(new SchemaPropertyRefMap(prop)); propertyNames.add(prop.getName()); } }
public Bean toBean(Schema schema) { final BeanId id; if (schema.getId().isSingleton()) { id = BeanId.createSingleton(schema.getName()); } else { id = BeanId.create(getId(), getSchemaName()); for (String name : schema.getPropertyNames()) { List<String> values = props.get(name); if (values == null) { for (String name : schema.getReferenceNames()) { List<String> values = props.get(name); if (values == null) { SchemaPropertyRef ref = schema.get(SchemaPropertyRef.class, name); String schemaName = null; if (ref != null) { SchemaPropertyRefList refList = schema.get(SchemaPropertyRefList.class, name); if (refList != null) { schemaName = refList.getSchemaName(); SchemaPropertyRefMap refMap = schema.get(SchemaPropertyRefMap.class, name); if (refMap != null) { schemaName = refMap.getSchemaName();
private void constructBean(Config properties, Schema schema, Bean bean, Map<String, Schema> schemas) { bean.set(schemas.get(bean.getId().getSchemaName())); for (String propertyName : schema.getPropertyNames()) { Object value; try { for (String propertyName : schema.getReferenceNames()) { Object value; try { String schemaName = schema.getReferenceSchemaName(propertyName); if (schemaName == null) { throw new IllegalArgumentException("Schema [" + schema.getName() + "] does not have reference typed property [" + propertyName + "]."); if (refSchema.getId().isSingleton()) { BeanId id = BeanId.createSingleton(refSchema.getName()); Optional<Bean> optional = get(id, schemas); if (!optional.isPresent()) { List<BeanId> beanIds = new ArrayList<>(); for (String id : stringValues) { BeanId beanId = BeanId.create(id, refSchema.getName()); Optional<Bean> ref = get(beanId, schemas); if (!ref.isPresent()) { BeanId id = BeanId.create(value.toString(), refSchema.getName()); Optional<Bean> idBean = get(id, schemas); if (!idBean.isPresent()) {
private void convertPropertyRef(Bean source, Map<String, Object> values, Map<BeanId, Object> instanceCache) { for (SchemaPropertyRef prop : source.getSchema().get(SchemaPropertyRef.class)) { BeanId id = source.getFirstReference(prop.getName()); if (id == null) { continue; } Bean ref = id.getBean(); if (ref == null) { continue; } Schema refSchema = ref.getSchema(); if (refSchema == null) { throw Events.CFG101_SCHEMA_NOT_EXIST(ref.getId().getSchemaName()); } SchemaPropertyRef schemaRef = source.getSchema().get(SchemaPropertyRef.class, prop.getName()); Object beanInstance = instanceCache.get(id); if (beanInstance == null) { try { beanInstance = newInstance(loadClass(refSchema.getType())); } catch (Exception e) { throw new UnsupportedOperationException(e); } beanInstance = convert(ref, beanInstance, new HashMap<String, Object>(), instanceCache); } values.put(schemaRef.getFieldName(), beanInstance); } }
@Inject public JaxrsConfigEndpoint(AdminContext admin) { this.admin = admin; for (Schema s : admin.getSchemas().values()) { schemas.put(s.getName(), s); } }
public List<Bean> list(Schema schema, Map<String, Schema> schemas) { List<Bean> beans = new ArrayList<>(); Config schemaConfig; try { String schemaName = schema.getName().replaceAll("\\$", "\\."); schemaConfig = config.getConfig(schemaName); if (schemaConfig == null) { return beans; } } catch (Exception e) { return beans; } if (schema.getId().isSingleton()) { final Bean bean = Bean.create(BeanId.createSingleton(schema.getName())); beans.add(bean); constructBean(schemaConfig, schema, bean, schemas); } else { for (Object instanceId : schemaConfig.root().keySet()) { Config instance = schemaConfig.getConfig(instanceId.toString()); final Bean bean = Bean.create(BeanId.create(instanceId.toString(), schema.getName())); beans.add(bean); constructBean(instance, schema, bean, schemas); } } return beans; }
public Schema toSchema() { SchemaId id = SchemaId.create(idName, idDesc, singleton); Schema schema = Schema.create(id, className, schemaName, desc); for (SchemaProperty schemaProperty : property) { schema.add(schemaProperty.toSchema()); } for (SchemaPropertyList schemaPropertyList : propertyList) { schema.add(schemaPropertyList.toSchema()); } for (SchemaPropertyRef schemaPropertyRef : propertyRef) { schema.add(schemaPropertyRef.toSchema()); } for (SchemaPropertyRefList schemaPropertyRefList : propertyRefList) { schema.add(schemaPropertyRefList.toSchema()); } for (SchemaPropertyRefMap schemaPropertyRefMap : propertyRefMap) { schema.add(schemaPropertyRefMap.toSchema()); } return schema; }
public boolean isReference(String property) { return getReferenceNames().contains(property); }
public Class<?> getClassMapType() { if(collectionTypeCls != null) { return collectionTypeCls; } collectionTypeCls = getClassTypeFromName(mapType); return collectionTypeCls; }
/** * This is the fully qualified classname of the configurable class that this schema originates from. * * @return Class of this schema. */ public Class<?> getClassType() { try { return Class.forName(getType()); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } }
/** * Creates a new schema. Not to be used by users, schemas are created when a configurable class are * registered in the system. * * @param id that identify this schema. * @param classType classname that fully qualifies the configurable class that this schema originates from. * @param name of this schema as specified in meta data, names must be unique. * @param description purpose and useful information needed in order to manage this schema. * @return A Schema. */ public static Schema create(SchemaId id, final String classType, final String name, final String description) { return new Schema(id, classType, name, description); }
private void convertPropertyRefList(Bean source, Map<String, Object> values, Map<BeanId, Object> instanceCache) { for (SchemaPropertyRefList prop : source.getSchema().get(SchemaPropertyRefList.class)) { List<BeanId> references = source.getReference(prop.getName()); if (references == null) { continue; } Collection<Object> c = newCollection(loadClass(prop.getCollectionType())); for (BeanId beanId : references) { Bean b = beanId.getBean(); if (b != null) { Object beanInstance = instanceCache.get(beanId); if (beanInstance == null) { String type = b.getSchema().getType(); try { beanInstance = newInstance(loadClass(type)); } catch (Exception e) { throw new UnsupportedOperationException(e); } beanInstance = convert(b, beanInstance, new HashMap<String, Object>(), instanceCache); } c.add(beanInstance); } } values.put(prop.getFieldName(), c); } }
private BeanId getSingletonId(Schema s, Class<?> configurable) { return BeanId.createSingleton(s.getName()); }
String schemaName = schema.getName().replaceAll("\\$", "\\."); Config schemaConfig = config.getConfig(schemaName); Bean bean; if (schema.getId().isSingleton()) { bean = Bean.create(BeanId.createSingleton(schema.getName())); constructBean(schemaConfig, schema, bean, schemas); return Optional.of(bean); if (instanceId.equals(beanId.getInstanceId())) { Config instance = schemaConfig.getConfig(instanceId.toString()); bean = Bean.create(BeanId.create(instanceId.toString(), schema.getName())); constructBean(instance, schema, bean, schemas); return Optional.of(bean);
@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; }