use of org.wso2.carbon.registry.core.exceptions.RegistryException in project jaggery by wso2.
the class RegistryHostObject method jsFunction_newCollection.
public static Scriptable jsFunction_newCollection(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
RegistryHostObject rho = (RegistryHostObject) thisObj;
if (arguments.length == 0) {
if (rho.registry != null) {
try {
Collection collection = rho.registry.newCollection();
CollectionHostObject cho = (CollectionHostObject) cx.newObject(rho, "Collection", new Object[] { collection });
return cho;
} catch (RegistryException e) {
throw new ScriptException("Error occurred while creating a new Collection", e);
}
} else {
throw new ScriptException("Registry has not initialized");
}
} else {
throw new ScriptException("newCollection() Method doesn't accept arguments");
}
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException in project jaggery by wso2.
the class RegistryHostObject method jsFunction_getAvgRating.
public static Number jsFunction_getAvgRating(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
String functionName = "getAvgRating";
int argsCount = args.length;
if (argsCount != 1) {
HostObjectUtil.invalidNumberOfArgs(hostObjectName, functionName, argsCount, false);
}
RegistryHostObject registryHostObject = (RegistryHostObject) thisObj;
if (!(args[0] instanceof String)) {
HostObjectUtil.invalidArgsError(hostObjectName, functionName, "1", "string", args[0], false);
}
try {
return registryHostObject.registry.getAverageRating((String) args[0]);
} catch (RegistryException e) {
throw new ScriptException(e);
}
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException in project jaggery by wso2.
the class ResourceHostObject method jsGet_content.
public Object jsGet_content() throws ScriptException {
try {
Object result = this.resource.getContent();
String mediaType = this.resource.getMediaType();
if (result instanceof byte[]) {
// if mediaType is xml related one, we return an e4x xml object
if (mediaType != null) {
if (mediaType.matches(".*[\\/].*[xX][mM][lL].*")) {
return context.newObject(this, "XML", new Object[] { new String((byte[]) result) });
}
}
return new String((byte[]) result);
} else if (result instanceof String[]) {
String[] content = (String[]) result;
return context.newArray(this, Arrays.copyOf(content, content.length, Object[].class));
} else {
return Context.toObject(result, this);
}
} catch (RegistryException e) {
throw new ScriptException("Registry Exception while reading content property", e);
}
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-apimgt by wso2.
the class AbstractAPIManager method isDocumentationExist.
/**
* Checks whether the given document already exists for the given api/product
*
* @param identifier API/Product Identifier
* @param docName Name of the document
* @return true if document already exists for the given api/product
* @throws APIManagementException if failed to check existence of the documentation
*/
public boolean isDocumentationExist(Identifier identifier, String docName) throws APIManagementException {
String docPath = "";
docPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + RegistryConstants.PATH_SEPARATOR + APIConstants.DOC_DIR + RegistryConstants.PATH_SEPARATOR + docName;
try {
return registry.resourceExists(docPath);
} catch (RegistryException e) {
String msg = "Failed to check existence of the document :" + docPath;
throw new APIManagementException(msg, e);
}
}
use of org.wso2.carbon.registry.core.exceptions.RegistryException in project carbon-apimgt by wso2.
the class AbstractAPIManager method getCustomMediationResourceFromUuid.
/**
* Returns the mediation policy registry resource correspond to the given identifier
*
* @param mediationPolicyId uuid of the mediation resource
* @return Registry resource of given identifier or null
* @throws APIManagementException If failed to get the registry resource of given uuid
*/
@Override
public Resource getCustomMediationResourceFromUuid(String mediationPolicyId) throws APIManagementException {
String resourcePath = APIConstants.API_CUSTOM_SEQUENCE_LOCATION;
try {
Resource resource = registry.get(resourcePath);
// resource : customsequences
if (resource instanceof Collection) {
Collection typeCollection = (Collection) resource;
String[] typeArray = typeCollection.getChildren();
for (String type : typeArray) {
Resource typeResource = registry.get(type);
// typeResource: in/ out/ fault
if (typeResource instanceof Collection) {
String[] policyArray = ((Collection) typeResource).getChildren();
if (policyArray.length > 0) {
for (String policy : policyArray) {
Resource mediationResource = registry.get(policy);
// mediationResource: eg .log_in_msg.xml
String resourceId = mediationResource.getUUID();
if (resourceId.equals(mediationPolicyId)) {
// registry resource
return mediationResource;
}
}
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while accessing registry objects";
throw new APIManagementException(msg, e);
}
return null;
}
Aggregations