use of com.bluenimble.platform.server.FeatureNotFoundException in project serverless by bluenimble.
the class AbstractApiServer method getFeature.
@Override
public Object getFeature(ApiSpace space, Class<?> type, String name) {
Feature aFeature = type.getAnnotation(Feature.class);
JsonObject oFeature = Json.getObject(space.getFeatures(), aFeature.name());
if (oFeature == null || oFeature.isEmpty()) {
throw new FeatureNotFoundException("feature " + aFeature.name() + " not available in space " + space.getNamespace());
}
JsonObject oProvider = Json.getObject(oFeature, name);
if (oProvider == null || oProvider.isEmpty()) {
throw new FeatureNotFoundException("feature provider " + name + " not available in space " + space.getNamespace());
}
String provider = Json.getString(oProvider, ApiSpace.Features.Provider);
if (Lang.isNullOrEmpty(provider)) {
throw new FeatureNotFoundException("provider for feature " + aFeature.name() + Lang.SLASH + name + " is missing");
}
ServerFeature feature = features.get(aFeature.name() + FeatureProtocol + provider);
if (feature == null) {
throw new FeatureNotFoundException("feature " + name + Lang.COLON + aFeature.name() + FeatureProtocol + provider + " not found");
}
return feature.get(space, name);
}
use of com.bluenimble.platform.server.FeatureNotFoundException in project serverless by bluenimble.
the class ApiSpaceImpl method feature.
@SuppressWarnings("unchecked")
@Override
public <T> T feature(Class<T> t, String name, ApiContext context) {
if (context == null) {
throw new FeatureNotFoundException("context not available");
}
if (Lang.isNullOrEmpty(name)) {
throw new FeatureNotFoundException("provider can't be null or empty");
}
Feature aFeature = t.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
throw new FeatureNotFoundException("feature " + t.getSimpleName() + " not registered in this instance");
}
String recyclableKey = contextRecyclableKey(aFeature.name(), name);
Recyclable feature = context.getRecyclable(recyclableKey);
if (feature != null) {
return (T) feature;
}
T f = (T) server.getFeature(this, t, name);
if (f == null) {
throw new FeatureNotFoundException("feature " + name + " not found");
}
if (Recyclable.class.isAssignableFrom(f.getClass())) {
context.addRecyclable(recyclableKey, (Recyclable) f);
}
return f;
}
use of com.bluenimble.platform.server.FeatureNotFoundException in project serverless by bluenimble.
the class AbstractApiServer method addFeature.
@Override
public void addFeature(ServerFeature feature) {
Feature aFeature = feature.type().getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
throw new FeatureNotFoundException("feature " + feature.type().getSimpleName() + " not registered in this instance");
}
features.put(aFeature.name() + FeatureProtocol + feature.provider(), feature);
}
Aggregations