Modified APIUtil

Modified the osgi contexts and reformatted.
feature/appm-store/pbac
nishadi 7 years ago
parent 3cc15d0df0
commit 4c1d8dfa4d

@ -31,8 +31,8 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; import org.wso2.carbon.device.application.mgt.common.services.CategoryManager;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response;
/** /**
* Holds util methods required for Application-Mgt API component. * Holds util methods required for Application-Mgt API component.
@ -41,67 +41,36 @@ public class APIUtil {
private static Log log = LogFactory.getLog(APIUtil.class); private static Log log = LogFactory.getLog(APIUtil.class);
private static ApplicationManager applicationManager;
private static PlatformManager platformManager;
private static LifecycleStateManager lifecycleStateManager;
private static ApplicationReleaseManager applicationReleaseManager;
private static ApplicationStorageManager applicationStorageManager;
private static SubscriptionManager subscriptionManager;
private static PlatformStorageManager platformStorageManager;
private static CategoryManager categoryManager;
private static CommentsManager commentsManager;
public static ApplicationManager getApplicationManager() { public static ApplicationManager getApplicationManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ApplicationManager applicationManager = (ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null);
if (applicationManager == null) { if (applicationManager == null) {
synchronized (APIUtil.class) { String msg = "Application Manager service has not initialized.";
if (applicationManager == null) { log.error(msg);
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); throw new IllegalStateException(msg);
applicationManager =
(ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null);
if (applicationManager == null) {
String msg = "Application Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
} }
return applicationManager; return applicationManager;
} }
public static PlatformManager getPlatformManager() { public static PlatformManager getPlatformManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformManager platformManager = (PlatformManager) ctx.getOSGiService(PlatformManager.class, null);
if (platformManager == null) { if (platformManager == null) {
synchronized (APIUtil.class) { String msg = "Platform Manager service has not initialized.";
if (platformManager == null) { log.error(msg);
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); throw new IllegalStateException(msg);
platformManager =
(PlatformManager) ctx.getOSGiService(PlatformManager.class, null);
if (platformManager == null) {
String msg = "Platform Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
} }
return platformManager; return platformManager;
} }
public static LifecycleStateManager getLifecycleStateManager() { public static LifecycleStateManager getLifecycleStateManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
LifecycleStateManager lifecycleStateManager = (LifecycleStateManager) ctx
.getOSGiService(LifecycleStateManager.class, null);
if (lifecycleStateManager == null) { if (lifecycleStateManager == null) {
synchronized (APIUtil.class) { String msg = "Lifecycle Manager service has not initialized.";
if (lifecycleStateManager == null) { log.error(msg);
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); throw new IllegalStateException(msg);
lifecycleStateManager =
(LifecycleStateManager) ctx.getOSGiService(LifecycleStateManager.class, null);
if (lifecycleStateManager == null) {
String msg = "Lifecycle Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
} }
return lifecycleStateManager; return lifecycleStateManager;
} }
@ -112,41 +81,30 @@ public class APIUtil {
* @return ApplicationRelease Manager instance in the current osgi context. * @return ApplicationRelease Manager instance in the current osgi context.
*/ */
public static ApplicationReleaseManager getApplicationReleaseManager() { public static ApplicationReleaseManager getApplicationReleaseManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ApplicationReleaseManager applicationReleaseManager = (ApplicationReleaseManager) ctx
.getOSGiService(ApplicationReleaseManager.class, null);
if (applicationReleaseManager == null) { if (applicationReleaseManager == null) {
synchronized (APIUtil.class) { String msg = "Application Release Manager service has not initialized.";
if (applicationReleaseManager == null) { log.error(msg);
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); throw new IllegalStateException(msg);
applicationReleaseManager = (ApplicationReleaseManager) ctx
.getOSGiService(ApplicationReleaseManager.class, null);
if (applicationReleaseManager == null) {
String msg = "Application Release Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
} }
return applicationReleaseManager; return applicationReleaseManager;
} }
/** /**
* To get the Application Storage Manager from the osgi context. * To get the Application Storage Manager from the osgi context.
*
* @return ApplicationStoreManager instance in the current osgi context. * @return ApplicationStoreManager instance in the current osgi context.
*/ */
public static ApplicationStorageManager getApplicationStorageManager() { public static ApplicationStorageManager getApplicationStorageManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ApplicationStorageManager applicationStorageManager = (ApplicationStorageManager) ctx
.getOSGiService(ApplicationStorageManager.class, null);
if (applicationStorageManager == null) { if (applicationStorageManager == null) {
synchronized (APIUtil.class) { String msg = "Application Storage Manager service has not initialized.";
if (applicationStorageManager == null) { log.error(msg);
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); throw new IllegalStateException(msg);
applicationStorageManager = (ApplicationStorageManager) ctx
.getOSGiService(ApplicationStorageManager.class, null);
if (applicationStorageManager == null) {
String msg = "Application Storage Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
} }
return applicationStorageManager; return applicationStorageManager;
} }
@ -157,42 +115,29 @@ public class APIUtil {
* @return PlatformStoreManager instance in the current osgi context. * @return PlatformStoreManager instance in the current osgi context.
*/ */
public static PlatformStorageManager getPlatformStorageManager() { public static PlatformStorageManager getPlatformStorageManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PlatformStorageManager platformStorageManager = (PlatformStorageManager) ctx
.getOSGiService(PlatformStorageManager.class, null);
if (platformStorageManager == null) { if (platformStorageManager == null) {
synchronized (APIUtil.class) { String msg = "Platform Storage Manager service has not initialized.";
if (platformStorageManager == null) { log.error(msg);
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); throw new IllegalStateException(msg);
platformStorageManager = (PlatformStorageManager) ctx
.getOSGiService(PlatformStorageManager.class, null);
if (platformStorageManager == null) {
String msg = "Platform Storage Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
} }
return platformStorageManager; return platformStorageManager;
} }
/** /**
* To get the Category Manager from the osgi context. * To get the Category Manager from the osgi context.
* *
* @return CategoryManager instance in the current osgi context. * @return CategoryManager instance in the current osgi context.
*/ */
public static CategoryManager getCategoryManager() { public static CategoryManager getCategoryManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
CategoryManager categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null);
if (categoryManager == null) { if (categoryManager == null) {
synchronized (APIUtil.class) { String msg = "Category Manager service has not initialized.";
if (categoryManager == null) { log.error(msg);
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); throw new IllegalStateException(msg);
categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null);
if (categoryManager == null) {
String msg = "Category Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
} }
return categoryManager; return categoryManager;
} }
@ -213,40 +158,34 @@ public class APIUtil {
/** /**
* To get the Subscription Manager from the osgi context. * To get the Subscription Manager from the osgi context.
*
* @return SubscriptionManager instance in the current osgi context. * @return SubscriptionManager instance in the current osgi context.
*/ */
public static SubscriptionManager getSubscriptionManager() { public static SubscriptionManager getSubscriptionManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
SubscriptionManager subscriptionManager = (SubscriptionManager) ctx
.getOSGiService(SubscriptionManager.class, null);
if (subscriptionManager == null) { if (subscriptionManager == null) {
synchronized (APIUtil.class) { String msg = "Subscription Manager service has not initialized.";
if (subscriptionManager == null) { log.error(msg);
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); throw new IllegalStateException(msg);
subscriptionManager =
(SubscriptionManager) ctx.getOSGiService(SubscriptionManager.class, null);
if (subscriptionManager == null) {
String msg = "Subscription Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
} }
return subscriptionManager; return subscriptionManager;
} }
/**
* To get the Comment Manager from the osgi context.
*
* @return CommentsManager instance in the current osgi context.
*/
public static CommentsManager getCommentsManager() { public static CommentsManager getCommentsManager() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
CommentsManager commentsManager = (CommentsManager) ctx.getOSGiService(CommentsManager.class, null);
if (commentsManager == null) { if (commentsManager == null) {
synchronized (APIUtil.class) { String msg = "Comments Manager service has not initialized.";
if (commentsManager == null) { log.error(msg);
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); throw new IllegalStateException(msg);
commentsManager = (CommentsManager) ctx.getOSGiService(CommentsManager.class, null);
if (commentsManager == null) {
String msg = "Comments Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
} }
return commentsManager; return commentsManager;
} }

Loading…
Cancel
Save