upload tizen1.0 source
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Widget / Widget.cpp
index 07cb18b..3bc7341 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <dpl/log/log.h>
 #include <Commons/StringUtils.h>
-
+#include <Commons/WrtAccess/WrtAccess.h>
 #include "Widget.h"
 #include <WidgetDB/IWidgetDB.h>
 #include <WidgetDB/WidgetDBMgr.h>
@@ -35,21 +35,23 @@ namespace Widget {
 using namespace std;
 using namespace WidgetDB::Api;
 
-Widget::Widget(Commons::IWrtWrapperPtr wrapper) :
-    m_wrtWrapper(wrapper)
+Widget::Widget() 
+{
+    using namespace WrtDeviceApis::Commons;
+    m_widgetId = WrtAccessSingleton::Instance().getWidgetId();
+}
+
+Widget::~Widget()
 {
-    if (!wrapper) {
-        LogError("Wrapper is NULL");
-    }
 }
 
 string Widget::getProperty(ConfigAttribute attr) const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     string value;
     Try {
-        IWidgetDBPtr widgetDB = getWidgetDB(m_wrtWrapper->getWidgetId());
+        IWidgetDBPtr widgetDB = getWidgetDB(m_widgetId);
         value = widgetDB->getConfigValue(attr);
     }
     Catch(Commons::InvalidArgumentException){
@@ -62,7 +64,7 @@ string Widget::getProperty(ConfigAttribute attr) const
 
 string Widget::getAuthor() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_author.isValid()) {
         m_author.setValue(getProperty(ConfigAttribute::AUTHOR_NAME));
@@ -72,7 +74,7 @@ string Widget::getAuthor() const
 
 string Widget::getAuthorEmail() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_authorEmail.isValid()) {
         m_authorEmail.setValue(getProperty(ConfigAttribute::AUTHOR_EMAIL));
@@ -82,7 +84,7 @@ string Widget::getAuthorEmail() const
 
 string Widget::getAuthorHref() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_authorHref.isValid()) {
         m_authorHref.setValue(getProperty(ConfigAttribute::AUTHOR_HREF));
@@ -92,7 +94,7 @@ string Widget::getAuthorHref() const
 
 string Widget::getDescription() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_description.isValid()) {
         m_description.setValue(getProperty(ConfigAttribute::DESCRIPTION));
@@ -102,7 +104,7 @@ string Widget::getDescription() const
 
 string Widget::getId() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     LogDebug("entered");
     if (!m_id.isValid()) {
@@ -113,7 +115,7 @@ string Widget::getId() const
 
 string Widget::getName() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_name.isValid()) {
         m_name.setValue(getProperty(ConfigAttribute::NAME));
@@ -123,7 +125,7 @@ string Widget::getName() const
 
 string Widget::getShortName() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_shortName.isValid()) {
         m_shortName.setValue(getProperty(ConfigAttribute::SHORT_NAME));
@@ -133,7 +135,7 @@ string Widget::getShortName() const
 
 string Widget::getVersion() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_version.isValid()) {
         m_version.setValue(getProperty(ConfigAttribute::VERSION));
@@ -143,7 +145,7 @@ string Widget::getVersion() const
 
 unsigned int Widget::getHeight() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_height.isValid()) {
         m_height.setValue(Commons::String::toInt(
@@ -154,7 +156,7 @@ unsigned int Widget::getHeight() const
 
 unsigned int Widget::getWidth() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_width.isValid()) {
         m_width.setValue(Commons::String::toInt(
@@ -163,11 +165,11 @@ unsigned int Widget::getWidth() const
     return m_width.getValue();
 }
 
-void Widget::checkWrapperPointer() const
+void Widget::checkWidgetId() const
 {
-    if (!m_wrtWrapper) {
-        LogError("Null pointer");
-        Throw(Commons::NullPointerException);
+    if (m_widgetId < 0) {
+        LogError("Invalid widget id");
+        Throw(Commons::InvalidArgumentException);
     }
     return;
 }