contextframework/cfw/src/basicoperationsplugin/cfelseclause.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CCFElseClause class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "cfelseclause.h"
       
    22 #include "cfscriptaction.h"
       
    23 #include "cfbasicoptrace.h"
       
    24 
       
    25 #include <gmxmlnode.h>
       
    26 
       
    27 // CONSTANTS
       
    28 _LIT( KScriptElseName16,    "else"      );
       
    29 _LIT( KScriptActionsName16, "actions"   );
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CCFElseClause::CCFElseClause
       
    35 // C++ default constructor can NOT contain any code, that might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CCFElseClause::CCFElseClause( MCFOperationServices& aServices,
       
    39     CCFOperationNode* aParent )
       
    40     :   CCFClauseNode( aServices, aParent )
       
    41     {
       
    42     FUNC_LOG;
       
    43 
       
    44     iValue = ECFConditionTrue; // Else clause is always true.
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CCFElseClause::ConstructL
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CCFElseClause::ConstructL()
       
    53     {
       
    54     FUNC_LOG;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CCFElseClause::NewL
       
    59 // Two-phased constructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CCFElseClause* CCFElseClause::NewL( MCFOperationServices& aServices,
       
    63     CCFOperationNode* aParent )
       
    64     {
       
    65     FUNC_LOG;
       
    66 
       
    67     CCFElseClause* self = NewLC( aServices, aParent );
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CCFElseClause::NewLC
       
    74 // Two-phased constructor.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CCFElseClause* CCFElseClause::NewLC( MCFOperationServices& aServices,
       
    78     CCFOperationNode* aParent )
       
    79     {
       
    80     FUNC_LOG;
       
    81 
       
    82     CCFElseClause* self = new( ELeave ) CCFElseClause( aServices, aParent );
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85     return self;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CCFElseClause::ParseL
       
    90 // Construction with parsing from a DOM node.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CCFElseClause* CCFElseClause::ParseL( MCFOperationServices& aServices,
       
    94     CCFOperationNode* aParent,
       
    95     CMDXMLNode& aNode )
       
    96     {
       
    97     FUNC_LOG;
       
    98 
       
    99     if ( aNode.NodeName().CompareF( KScriptElseName16 ) != 0 )
       
   100         {
       
   101         return NULL; // Cannot create else clause from the given node.
       
   102         }
       
   103 
       
   104     CCFElseClause* self = NewLC( aServices, aParent );      // CLEANUP<< self
       
   105 
       
   106     // Parse children.
       
   107     TBool unsupportedNode( EFalse );
       
   108     TBool actionsParsed( EFalse );
       
   109     CMDXMLNode* child = aNode.FirstChild();
       
   110     while ( child )
       
   111         {
       
   112         if ( child->NodeType() == CMDXMLNode::EElementNode )
       
   113             {
       
   114             if ( child->NodeName().CompareF( KScriptActionsName16 ) == 0 )
       
   115                 {
       
   116                 if ( actionsParsed )
       
   117                     {
       
   118                     INFO( "CCFElseClause::ParseL - Redefinition not allowed, actions already parsed" );
       
   119                     unsupportedNode = ETrue;
       
   120                     break;
       
   121                     }
       
   122                 self->ParseActionsL( *child, self->iActions );
       
   123                 actionsParsed = ETrue;
       
   124                 }
       
   125             else
       
   126                 {
       
   127                 TPtrC nodeName( child->NodeName() );
       
   128                 INFO_1( "CCFElseClause::ParseL - Unsupported node [%S]",
       
   129                         &nodeName );
       
   130                 unsupportedNode = ETrue; // Unsupported node.
       
   131                 break;
       
   132                 }
       
   133             }
       
   134         else if ( child->NodeType() != CMDXMLNode::ECommentNode )
       
   135             {
       
   136             TPtrC nodeName( child->NodeName() );
       
   137             INFO_1( "CCFElseClause::ParseL - Unsupported node [%S]",
       
   138                     &nodeName );
       
   139             unsupportedNode = ETrue;
       
   140             break;
       
   141             }
       
   142         child = child->NextSibling();
       
   143         }
       
   144 
       
   145     CleanupStack::Pop( self );                              // CLEANUP>> self
       
   146     if ( unsupportedNode )
       
   147         {
       
   148         delete self; // Discard unsupported else clause.
       
   149         self = NULL;
       
   150         }
       
   151 
       
   152     CREATE_DOM_INFO( self, aNode );
       
   153 
       
   154     return self;
       
   155     }
       
   156 
       
   157 
       
   158 // Destructor
       
   159 CCFElseClause::~CCFElseClause()
       
   160     {
       
   161     iActions.ResetAndDestroy();
       
   162     }
       
   163 
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CCFElseClause::FireActionsL
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CCFElseClause::FireActionsL()
       
   170     {
       
   171     FUNC_LOG;
       
   172 
       
   173     ACTION_INFO_2( "Firing [%d] ELSE-actions for script ID=[%d]",
       
   174             iActions.Count(),
       
   175             iServices.ScriptId() );
       
   176 
       
   177     for ( TInt i = 0; i < iActions.Count(); ++i )
       
   178         {
       
   179         iActions[ i ]->ActL();
       
   180         }
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CCFElseClause::ActivateL
       
   185 // Else clause can have only actions, nothing must be done.
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CCFElseClause::ActivateL()
       
   189     {
       
   190     FUNC_LOG;
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // CCFElseClause::Deactivate
       
   195 // Else clause can have only actions, nothing must be done.
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CCFElseClause::Deactivate()
       
   199     {
       
   200     FUNC_LOG;
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CCFElseClause::CheckSecurity
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 TInt CCFElseClause::CheckSecurity()
       
   208     {
       
   209     FUNC_LOG;
       
   210 
       
   211     // Check security for actions.
       
   212     for ( TInt i = 0; i < iActions.Count(); ++i )
       
   213         {
       
   214         TSecurityPolicy securityPolicy;
       
   215         TInt err = iActions[ i ]->GetSecurityPolicy( securityPolicy );
       
   216         if ( err != KErrNone )
       
   217             {
       
   218             ERROR( err, "CCFElseClause::CheckSecurity - Getting action security policy failed!" );
       
   219             return err;
       
   220             }
       
   221 
       
   222         err = iServices.CheckScriptOwnerAccess( securityPolicy );
       
   223         if ( err != KErrNone )
       
   224             {
       
   225             ERROR( err, "CCFElseClause::CheckSecurity - Checking action security policy failed!" );
       
   226             return err;
       
   227             }
       
   228         }
       
   229 
       
   230     return KErrNone;
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CCFElseClause::Evaluate
       
   235 // Should never get called.
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 void CCFElseClause::Evaluate()
       
   239     {
       
   240     FUNC_LOG;
       
   241 
       
   242     DOM_INFO( "CCFElseClause::Evaluate (ALWAYS TRUE)" );
       
   243 
       
   244     iValue = ECFConditionTrue; // Else clause is always true.
       
   245     }