Narrow casting vs wide casting

Hello All,
I have small requriemn..
I have a super class A and a sub class B.
In both the classes I have a method XYZ.
So, A has the following methods
ABC
XYZ
B has the following methods
XYZ
Now I have want to access the sub class methods from super class...i.e., in my example...Method XYZ of B class needs to be accessed from method ABC or XYZ or A.
How do I do?
And more over..what is the difference between Narrow Casting and Wide casting?
Kalyan

Hi Priya,
Consider the below Example for accessing the subclass method from Superclass:
CLASS LCL_SUPERCLASS DEFINITION.
   PUBLIC SECTION.
       METHODS: ABC, XYZ.
ENDCLASS.
CLASS LCL_SUPERCLASS IMPLEMENTATION.
  METHOD ABC.
   CALL METHOD ME->XYZ.
  ENDMETHOD.
  METHOD XYZ.
  ENDMETHOD.
ENDCLASS.
CLASS LCL_SUBCLASS DEFINITION
       INHERITING FROM LCL_SUPERCLASS.
   PUBLIC SECTION.
      METHODS XYZ REDEFINITION.
ENDCLASS.
CLASS LCL_SUBCLASS IMPLEMENTATION.
  METHOD XYZ.
  ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: O_SUPER TYPE REF TO LCL_SUPERCLASS,
           O_SUB     TYPE REF TO LCL_SUBCLASS.
CREATE OBJECT: O_SUPER, O_SUB.
CALL METHOD O_SUPER->ABC.
CALL METHOD O_SUB->ABC.
In the above example, When you call the superclass method ABC using CALL METHOD O_SUPER->ABC, as you see in the implementation part of the Method it will inturn call the Superclass method XYZ.
Here ME will point to the instance of the Superclass.
But the CALL METHOD O_SUB->ABC will call the method ABC ( this is inherited from Superclass to Subclass )and inturn it calls the method XYZ of the SUbclass since ME now points to the object O_SUB of the Subclass.
Hope this is clear.
Regards,
Nirupamaa.

Similar Messages

  • Why narrow casting is must before doing wide casting

    Hi everyone,
    I know the concept of wide casting ( assign/pass super class instances to subclass instances). So then why we need to do narrow casting before doing wide casting in our logic. I am just struggling into this concept from last 3 days. I have read many thread and blog but did not get satisfactory answer.
    Regards,
    Seth

    Hello Seth
    You do not need to do narrow casting. But, if you assign an instance of a super class to variable of subclass and try to run a subclass' method on that instance (of superclass) you will get an exception. Because super class does not have a mentioned method.
    Example:
    CLASS lcl_vehicle DEFINITION.
    ENDCLASS.
    CLASS lcl_car DEFINITION INHERITING FROM lcl_vehicle.
      DATA engine TYPE string VALUE 'has_engine'.
    ENDCLASS.
    DATA:
      lo_vehicle TYPE lcl_vehicle,
      lo_car TYPE lcl_car.
    CREATE OBJECT lo_vehicle.
    CREATE OBJECT lo_car.
    WRITE lo_car->engine.
    lo_car ?= lo_vehicle.
    WRITE lo_car->engine.
    regards

  • Narrow cast and wide cast in ABAP OO

    Hi Xperts
    Considering the code below can the concepts of narrowing cast and widening cast be explained ? Kindly help me in getting a clear picture of the usage of it.
    CLASS C1 DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA: COUNT TYPE I.
        CLASS-METHODS: DISP.
    ENDCLASS.                    "defintion  C1
    CLASS C1 IMPLEMENTATION.
      METHOD DISP.
        WRITE :/ COUNT.
      ENDMETHOD.                    "disp
    ENDCLASS.                    "c1 IMPLEMENTATION
    CLASS C2 DEFINITION INHERITING FROM C1.
      PUBLIC SECTION.
        CLASS-METHODS: GET_PROP.
    ENDCLASS.                    "c2  INHERITING C1
    CLASS C2 IMPLEMENTATION.
      METHOD GET_PROP.
        COUNT = 9.
        CALL METHOD DISP.
      ENDMETHOD.                    "get_prop
    ENDCLASS.                    "c2 IMPLEMENTATION
    START-OF-SELECTION.
      DATA: C1_REF TYPE REF TO C1,
            C2_REF TYPE REF TO C2.
    PS: Pls dont post any links as i already gone thru couple of those in SDN but couldnt get a clear info

    Hi
    I got to know abt narrow cast: referecing a super class ref to a subclass ref so that the methods in subclass can be accessed by the super class reference. Below is snippet of the code i'd checked. Hope this is correct to my understanding. If any faults pls correct me. Also if anyone can explain wideing cast in this context will be very helpful
    FOR NARROW CAST
    {size:8}
    CLASS C1 DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA: COUNT TYPE I.
        CLASS-METHODS: DISP_COUNT.
    ENDCLASS.                    "defintion  C1
    CLASS C1 IMPLEMENTATION.
      METHOD DISP_COUNT.
        WRITE :/ 'Class C1', COUNT.
      ENDMETHOD.                    "disp
    ENDCLASS.                    "c1 IMPLEMENTATION
    CLASS C2 DEFINITION INHERITING FROM C1.
      PUBLIC SECTION.
        CLASS-METHODS: GET_PROP,
                       DISP.
    ENDCLASS.                    "c2  INHERITING C1
    CLASS C2 IMPLEMENTATION.
      METHOD GET_PROP.
        COUNT = 9.
        CALL METHOD DISP.
      ENDMETHOD.                    "get_prop
      METHOD DISP.
        WRITE :/ 'Class C2', COUNT.
      ENDMETHOD.                    "DISP
    ENDCLASS.                    "c2 IMPLEMENTATION
    START-OF-SELECTION.
      DATA: C1_REF TYPE REF TO C1,
            C2_REF TYPE REF TO C2.
      CREATE OBJECT: C2_REF TYPE C2.
    *  CREATE OBJECT: C1_REF TYPE C1.
      BREAK-POINT.
      C1_REF = C2_REF.
      CALL METHOD C1_REF->DISP_COUNT.
      CALL METHOD C1_REF->('GET_PROP').
    {size}
    Edited by: Prabhu  S on Mar 17, 2008 3:25 PM

  • Narrowing cast and widening cast

    Hi All,
           I want to know what is the use of a narrowing cast and a widening cast in ABAP objects.
    Can someone please give an example ?
    Regards,
    Ashish

    Hi,
    Check out this link, This will guide you on ABAP Objects
    http://www.sap-press.de/katalog/buecher/htmlleseproben/gp/htmlprobID-28?GalileoSession=22448306A3l7UG82GU8#level3~3
    Both narrow and wide casting are related to inheritance.
    In Narrow casting, you assign a runtime object of subclass to runtime object of superclass. By this assignment , you can access your subclass by using runtime object of your superclass. But here the important point is that, you are assigning subclass reference to super class reference, so you can only access the inherited components of subclass through super class reference.
    Suppose you have a super class lcl_vehicle. it has two subclasses lcl_car and lcl_truck.
    r_vehicle = r_car.
    In Wide casting, you assign a superclass reference to subclass reference . Before this, you do narrow casting,
    Now when you assign a superclass reference to subclass reference. You can access the inherited as well as the specific components of subclass.
    taking the same example,
    r_car ?= r_vehicle.
    '?='  wide cast operator.
    Regards
    Abhijeet

  • Doubts in narrow casting

    I was looking for narrow casting examples to understand concepts better.
    what i have seen everywhere is that
    after narrow casting that i.e assigining/copying child object to parent object we can use parent object to
    call method  which exits in sub class though redefined (of course it also exists in super class).
    Till here its fine.
    But we can't use parent variable to call method in subclass which does not exist in super class.
    it's showing syntax error but a little change in that have made its syntax correct.
    Take a look at this example....
    REPORT  ZNEWOO6.
    *       CLASS vehicle DEFINITION
    class vehicle definition.
       public section.
         methods: m1 ,
         m2.
    endclass.                    "vehicle DEFINITION
    *       CLASS vehicle IMPLEMENTATION
    class vehicle implementation.
       method m1.
         write /'method m1 super class imple.'.
       endmethod.                    "m1
       method m2.
         write /'method m2 super class imple.'.
       endmethod.                    "m1
    endclass.                    "vehicle IMPLEMENTATION
    *       CLASS truck DEFINITION
    class truck definition inheriting from vehicle.
       public section.
         methods:
         m2 redefinition,
         m4.
    endclass.                    "truck DEFINITION
    *       CLASS truck IMPLEMENTATION
    class truck implementation.
       method m2 .
         write /'method m2 redefination sub class imple.'.
       endmethod.                    "m2
       method m4.
    *      method m1.
         write /'method m4 sub class imple.'.
    *  endmethod.
       endmethod.                    "m4
    endclass.                    "truck IMPLEMENTATION
    start-of-selection .
       data : o_super type ref to vehicle,
             o_sub type ref to truck.
       create object :o_super, o_sub.
       call method o_super->m1.
       call method o_sub->m1.
       call method o_super->m2( ).
       o_super = o_sub."up/narrow casting "assigning child to parent
    *o_sub ?= o_super. "down/wide casting
       create object o_super.
       call method o_super->m2.
       call method o_sub->m2.
       "not possible to access those
    *method which are not defined in super class
    call method o_super->m4. "throw a syntax error
    call method o_super->('m4'). "works fine WHY!!!!!! "Even though m4 is not defined in super class

    Hello Abaper,
    when u assign subclass obj to super class its narrow casting,
    but when u create a new object create object o_super.
    it call the old reffernce so o_super call its own m2 instead of subclass m2
    modified code
    *& Report  ZTESTSWADHIN1
    REPORT ZTESTSWADHIN1.
    *       CLASS vehicle DEFINITION
    class vehicle definition.
       public section.
         methods: m1 ,
         m2.
    endclass.                    "vehicle DEFINITION
    *       CLASS vehicle IMPLEMENTATION
    class vehicle implementation.
       method m1.
         write /'method m1 super class imple.'.
       endmethod.                    "m1
       method m2.
         write /'method m2 super class imple.'.
       endmethod.                    "m1
    endclass.                    "vehicle IMPLEMENTATION
    *       CLASS truck DEFINITION
    class truck definition inheriting from vehicle.
       public section.
         methods:
         m2 redefinition,
         m4.
    endclass.                    "truck DEFINITION
    *       CLASS truck IMPLEMENTATION
    class truck implementation.
       method m2 .
         write /'method m2 redefination sub class imple.'.
       endmethod.                    "m2
       method m4.
    *      method m1.
         write /'method m4 sub class imple.'.
    *  endmethod.
       endmethod.                    "m4
    endclass.                    "truck IMPLEMENTATION
    start-of-selection .
       data : o_super type ref to vehicle,
             o_sub type ref to truck.
       create object :o_super, o_sub.
       call method o_super->m1.
       call method o_sub->m1.
       call method o_super->m2( ).
       o_super = o_sub."up/narrow casting "assigning child to parent
    *o_sub ?= o_super. "down/wide casting
    *   create object o_super.
       call method o_super->m2.
       call method o_sub->m2.
    For Details Have alook
    Check o_sub and o_super value..\
    Hope this help.

  • Regarding Narrow casting

    Hi Experts,
    Here i am giving one program about narrow casting in which i am not able to access the method called 'fasting', but here i am able to access dynamically.
    So, while doing narrow casting may i know that only dynamically we can able to access that method?
    and may i know the clear picture of wide castening & narrow castening with example.
    Please help it out.
    REPORT  Z15704_NARROWING.
    CLASS lcl_animal DEFINITION.
       PUBLIC SECTION.
         METHODS: hungry.
         ENDCLASS.
         CLASS lcl_lion DEFINITION INHERITING FROM lcl_animal.
            PUBLIC SECTION.
             METHODS: hungry REDEFINITION,
                     fasting.
             ENDCLASS.
             CLASS lcl_animal IMPLEMENTATION.
               METHOD hungry.
                   WRITE: / 'An animal is hungry'.
                    ENDMETHOD.
                    endclass.
                      "hungryENDCLASS.
    CLASS lcl_lion IMPLEMENTATION.
      METHOD hungry .
         WRITE: / 'A Lion (King of Jungle) is hungry.'.
          ENDMETHOD.                    "hungry  METHOD fasting.
          METHOD fasting.
           WRITE: / 'Stop running. Lion is on Fasting today.'.
           ENDMETHOD.
           ENDCLASS.
           START-OF-SELECTION.
            DATA: lo_animal TYPE REF TO lcl_animal,
                      lo_lion   TYPE REF TO lcl_lion.
           " ** ANIMAL object without NARROW casting
            WRITE: / 'Animal - without NARROW casting'.
             CREATE OBJECT lo_animal.
               CALL METHOD lo_animal->hungry( ).
              CLEAR lo_animal.
              "** ANIMAL object with NARROW CASTING  SKIP 2.
               WRITE: / 'Animal -  NARROW casting from LION'.
               CREATE OBJECT lo_lion.
                lo_animal = lo_lion.
                CALL METHOD lo_animal->hungry( ).
                CALL METHOD lo_animal->fasting( ).
    when i call  this method dynamically CALL METHOD lo_animal->('fasting'). i am able to access.
    Thanks,
    Radhika

    In Narrow casting, we create a object reference to the Subclass (LO_LION) first and than we assign that object reference to the reference of the Superclass (LO_ANIMAL). Here we have moved from more specific object to less specific object.
    Refer: http://help-abap.blogspot.com/2008/09/abap-objects-narrowing-cast-upcasting.html
    In widening cast, we create a object referece to the superclass (LO_ANIMAL)  first and than we assign the object reference to the Subclass (LO_LION). Here we move from General object to Specific object. As the principal of the inheritance, every Subobject (LO_LION) will have more attributes/properties than the General object (LO_ANIMAL). So, it would not be possilbe to just create LO_ANIMAL and move to LO_LION. So, when we do the Widening cast, we need to first use the narrow casting somewhere in the program to assign proper proerties of subobject (LO_LION) to Superobject (LO_ANIMAL). Than you will successfully move that reference back to Superobject (LO_ANIMAL) to different subobject (LO_LION2).
    Refer: http://help-abap.blogspot.com/2008/09/abap-objects-widening-cast-down-casting.html
    Regards,
    Naimesh Patel

  • Narrow Casting Vs Widening Casting

    Hello,
    Can anybody please explain me the difference with an example between <b><i>Narrow Casting</i></b> and <i><b>Widening</b></i> <i><b>Casting</b></i> in ABAP Objects.
    Regards
    Kalyan

    Hi Kalyan
    In fact, the names imply everything. Let me illustrate a bit. This illustration will deal with one aspect which I think will be enough at least to understand the concept simply. Think of two instances (objects) of two classes one of which is inherited from the other, that is; one is a general class and the other is a specialized class of it.
    <u>e.g.</u>
    Class 1 --> land_vehicle
    Class 2 --> truck
    The class <b>land_vehicle</b> has following attributes:
      max_speed
      number_of_wheels
      number_plate
    The class <b>truck</b> has following attributes:
      max_speed [inherited]
      number_of_wheels [inherited]
      number_plate [inherited]
      <i>load_capacity</i> [special to truck class]
    Now, assume you have instantiated these classes as
    <b>"land_vehicle_obj"</b> and <b>"truck_obj"</b> respectively from these classes.
    Between these two objects, you can assign one to the other and at this point casting occurs.
    i. If you assign <i>truck_obj</i> to <i>land_vehicle_obj</i> you lose the special attribute <i>load_capacity</i> since you go from the specialized on to the general one. Thus, this is a <b>narrowing cast</b>.
    i. If you assign <i>land_vehicle_obj</i> and <i>truck_obj</i> you do not lose any attribute, nevertheless you add a new one. Thus this is a <b>widening cast</b>.
    Regards
    *--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

  • 关于 narrowing cast 的疑问...

    请教大家一个问题。
    在 ABAP Keyword Documentation 中对 MOVE 的说明中有这样一段话:
    Both these statements assign the content of the operand source to the data object destination. The variants with the addition TO or the assignment operator = are valid for all assignments between operands that are not reference variables, and for assignments between reference variables for which the static type of source is more specific than or the same as the static type of destination (narrowing cast).
    但是在 ABAP Glossay 中对narrowing cast的说明是:Also called a narrowing cast, a down cast is an assignment between reference variables in which the typr static type of the target variable more specific than the static type of the source variable. A down cast is only possible in assignments with the casting operator (?=) or MOVE ... ?TO. Compare with up cast.
    这两段对于narrowing cast的描述是相反的,哪个是正确的?谢谢!

    谢谢您的回复。但是不好意思,我还是没有明白。
    正如您所说的:
    第一段说的是操作符 = 或者语法MOVE...TO...的概念,第二段说的是 ?= 或MOVE...?TO..
    但是到底哪个是narrowing cast?
    第一段说 ...(narrowing cast)。=> 它是narrowing cast
    第二段说 Also called a narrowing cast, a down cast ... => 它也是 narrowing cast,又称 down cast
    您说 不满足以上任何一个Narrowing Casting条件的,要使用Widening Casting(Down Casting)  => narrowing cast 和 down cast 是相反的

  • Narrow Cast and Widening cast in OOPs

    hi friends,
    Can u please clear with the above two concepts ..... i have many doubts on this ...
    first of all Y we need the concept of Narrow cast and widenning cast ?
    Expecting your answers ...
    Thanks in advance
    Cheers
    Kripa Rangachari .....

    hi Kripa,
    “Narrowing” cast means that the assignment changes from a more specialized view (with visibility to more components) to a more generalized view (with visibility to fewer components).
    “Narrowing cast” is also referred to as “up cast” . “Up cast” means that the static type of the target variable can only change to higher nodes from the static type of the source variable in the inheritance tree, but not vice versa.
    <b>Reference variable of a class assigned to reference variable of class : object</b>
    class c1 definition.
    endclass.
    class c1 implementation.
    endclass.
    class c2 definition inheriting from c1.
    endclass.
    class c2 implementation.
    endclass.
    start-of-selection.
    data : oref1 type ref to c1,
            oref2 tyep ref to c2.
    oref1 = oref2.
    <b>Widening Cast</b>
    DATA:     o_ref1 TYPE REF TO object,                o_ref2 TYPE REF TO class.
    o_ref2 ?= o_ref1.
    CATH SYSTEM-EXCEPTIONS move_cast_error = 4.
         o_ref2 ?= o_ref1.
    ENDCATCH.
    In some cases, you may wish to make an assignment in which the static type of the target variable is less general than the static type of the source variable. This is known as a widening cast.
    The result of the assignment must still adhere to the rule that the static type of the target variable must be the same or more general than the dynamic type of the source variable.
    However, this can only be checked during runtime. To avoid the check on static type, use the special casting operator “?=“ and catch the potential runtime error move_cast_error
    Regards,
    Richa

  • Diff Between widening Cast & Narrowing Casting

    Hi,
    What are differences between widening Cast & Narrowing Casting ?
    Give some exaples also.
    Thanks

    Hey fren,
    Narrowing Cast is also known as Upcasting...
    Widening Cast is known as Downcasting...
    Let us take an example...
    We define a class lcl_vehicle and other class lcl_truck inherited from lcl_vehicle.
    CLASS lcl_vehicle DEFINITION.
          PUBLIC SECTION.
             METHODS constructor
                       IMPORTING im_make_v  TYPE string.
             METHODS estimate_fuel
                       IMPORTING im_distance   TYPE s_distance
                       RETURNING value(re_fuel) TYPE s_capacity
             METHODS get_make........
             METHODS get_count........
              METHODS display_attributes........
          PROTECTED SECTION.
              DATA r_tank TYPE REF TO lcl_tank.
          PRIVATE SECTION.
              DATA make TYPE string.
    ENDCLASS.
    CLASS lcl_vehicle IMPLEMENTATION.
              METHOD constructor.
                   make = im_make_v.
              ENDMETHOD.
              METHOD get_make.
              ENDMETHOD.
              METHOD get_count.
              ENDMETHOD.
              METHOD display_attributes.
              ENDMETHOD.
    ENDCLASS.
    Now we define a sub class lcl_truck to super class lcl_vehicle.
    CLASS lcl_truck DEFINITION INHERITING FROM lcl_vehicle.
           PUBLIC SECTION.
                METHODS constructor IMPORTING im_make_t TYPE string
                                                             im_cargo_t TYPE s_plan_car
                METHODS estimate_fuel REDEFINITION.
                METHODS get_cargo RETURNING value( re_cargo ) TYPE s_plan_car.
           PRIVATE SECTION.
              DATA max_cargo TYPE s_plan_car.
    ENDCLASS.
    CLASS lcl_truck IMPLEMENTATION.
          METHOD constructor.
               CALL METHOD super->constructor( im_make_v  = im_make_t ).
                max_cargo = im_cargo_t.
          ENDMETHOD.
          METHOD estimete_fuel.
              DATA total_weight TYPE w_weight.
              total_weight = max_cargo + weight.
              re_fuel = total_weight * im_distance * correction_factor.
           ENDMETHOD.                   
    ENDCLASS.
    Now we again define one more subclass lcl_bus to superclass lcl_vehicle.
    CLASS lcl_bus DEFINITION INHERITING FROM lcl_vehicle.
    PUBLIC SECTION.
                METHODS constructor IMPORTING im_make_b TYPE string
                                                             im_load_b TYPE s_plan_car
           PRIVATE SECTION.
              DATA max_load TYPE s_plan_car.
    ENDCLASS. 
    CLASS lcl_bus IMPLEMENTATION.
          METHOD constructor.
               CALL METHOD super->constructor( im_make_v  = im_make_b ).
                max_cargo = im_load_b.
          ENDMETHOD.
          METHOD estimete_fuel.
              DATA total_weight TYPE w_weight.
              total_weight = max_passengers * average_weight + weight.
              re_fuel = total_weight * im_distance * correction_factor.
           ENDMETHOD.                   
    ENDCLASS.
    Variables of the type 'reference to superclass' can also refer to subclass instances at runtime.
    This is called as Narrowing Casting...
    Lets see how it works...
    * Creating references to the classes.........
    DATA:
        r_vehicle TYPE REF TO lcl_vehicle,
        r_truck    TYPE REF TO lcl_truck,
        r_bus      TYPE REF TO lcl_bus.
    *Creating an object of class lcl_truck.........
    CREATE OBJECT r_truck.
    *Narrowing Cast ................
    r_vehicle = r_truck.
    Now reference --> superclass.... r_vehicle will point to only the inherited compenents of lcl_truck.
    If you assign a subclass reference to a superclass reference, this ensures that all components that can be accessed syntactically after the cast assignment are actually available in the instance.
    The subclass always contains at least the same components as the superclass. After all, the name and the signature of redefined methods are identical.
    The user can, therefore, address the subclass instance in the same way as the superclass instance. However, he is restricted to using only the inherited components. In this example, after the assignment, the methods GET_MAKE, GET_COUNT, DISPLAY_ATTRIBUTES and ESTIMATE_FUEL of the instance LCL_TRUCK can only be accessed using the reference R_VEHICLE. If there are any restrictions regarding visibility, they are left unchanged.
    It is not possible to access the specific components from the class LCL_TRUCK of the instance (GET_CARGO in the above example) using the reference R_VEHICLE. The view is thus usually narrowed (or at least unchanged). That is why we describe this type of assignment of reference variables as narrowing cast. There is a switch from a view of several components to a view of a few components. The term upcast is also common.
    A typical use for narrowing cast assignments is to prepare for generic access. A user who is not at all interested in the finer points of the instances of the subclasses but who simply wants to address the shared components could use a superclass reference for this access.
    In the example shown here, assume that a travel agency (LCL_RENTAL) needs to manage all imaginable kinds of vehicles in one list. This leads to the question of what types should be assigned to the internal table for the references to airplane instances. You should also assume that the car rental company needs to be able to calculate only the required amount of fuel for all its vehicles.  Correspondingly, the ESTIMATE_FUEL method is defined in the superclass LCL_VEHICLE and is redefined in all subclasses.
    This is about Narrowing Cast.
    Inspire if this was needful,
    Warm Regards,
    Abhi...

  • Create RSS feed for Narrow casting

    We are using narrow casting and we can stream content to it using an RSS-feed.
    We want to do the following: - Create an rss feed of an exchange (mailbox or calendar) using a script. I think it is just like this link. Or as shown below: 
    ###Code from http://poshcode.org/?show=669
    # Creates an RSS feed
    # Parameter input is for "site": Path, Title, Url, Description
    # Pipeline input is for feed items: hashtable with Title, Link, Author, Description, and pubDate keys
    Function New-RssFeed
    param (
    $Path = "$( throw 'Path is a mandatory parameter.' )",
    $Title = "Site Title",
    $Url = "http://$( $env:computername )",
    $Description = "Description of site"
    Begin {
    # feed metadata
    $encoding = [System.Text.Encoding]::UTF8
    $writer = New-Object System.Xml.XmlTextWriter( $Path, $encoding )
    $writer.WriteStartDocument()
    $writer.WriteStartElement( "rss" )
    $writer.WriteAttributeString( "version", "2.0" )
    $writer.WriteStartElement( "channel" )
    $writer.WriteElementString( "title", $Title )
    $writer.WriteElementString( "link", $Url )
    $writer.WriteElementString( "description", $Description )
    Process {
    # Construct feed items
    $writer.WriteStartElement( "item" )
    $writer.WriteElementString( "title", $_.title )
    $writer.WriteElementString( "link", $_.link )
    $writer.WriteElementString( "author", $_.author )
    $writer.WriteStartElement( "description" )
    $writer.WriteRaw( "<![CDATA[" ) # desc can contain HTML, so its escaped using SGML escape code
    $writer.WriteRaw( $_.description )
    $writer.WriteRaw( "]]>" )
    $writer.WriteEndElement()
    $writer.WriteElementString( "pubDate", $_.pubDate.toString( 'r' ) )
    $writer.WriteElementString( "guid", $homePageUrl + "/" + [guid]::NewGuid() )
    $writer.WriteEndElement()
    End {
    $writer.WriteEndElement()
    $writer.WriteEndElement()
    $writer.WriteEndDocument()
    $writer.Close()
    ### end code from http://poshcode.org/?show=669
    ## Get the Mailbox to Access from the 1st commandline argument
    $MailboxName = $args[0]
    ## Load Managed API dll
    Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"
    ## Set Exchange Version
    $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1
    ## Create Exchange Service Object
    $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
    ## Set Credentials to use two options are availible Option1 to use explict credentials or Option 2 use the Default (logged On) credentials
    #Credentials Option 1 using UPN for the windows Account
    $psCred = Get-Credential
    $creds = New-Object System.Net.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())
    $service.Credentials = $creds
    #Credentials Option 2
    #service.UseDefaultCredentials = $true
    ## Choose to ignore any SSL Warning issues caused by Self Signed Certificates
    ## Code From http://poshcode.org/624
    ## Create a compilation environment
    $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
    $Compiler=$Provider.CreateCompiler()
    $Params=New-Object System.CodeDom.Compiler.CompilerParameters
    $Params.GenerateExecutable=$False
    $Params.GenerateInMemory=$True
    $Params.IncludeDebugInformation=$False
    $Params.ReferencedAssemblies.Add("System.DLL") | Out-Null
    $TASource=@'
    namespace Local.ToolkitExtensions.Net.CertificatePolicy{
    public class TrustAll : System.Net.ICertificatePolicy {
    public TrustAll() {
    public bool CheckValidationResult(System.Net.ServicePoint sp,
    System.Security.Cryptography.X509Certificates.X509Certificate cert,
    System.Net.WebRequest req, int problem) {
    return true;
    $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
    $TAAssembly=$TAResults.CompiledAssembly
    ## We now create an instance of the TrustAll and attach it to the ServicePointManager
    $TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
    [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll
    ## end code from http://poshcode.org/624
    ## Set the URL of the CAS (Client Access Server) to use two options are availbe to use Autodiscover to find the CAS URL or Hardcode the CAS to use
    #CAS URL Option 1 Autodiscover
    $service.AutodiscoverUrl($MailboxName,{$true})
    "Using CAS Server : " + $Service.url
    #CAS URL Option 2 Hardcoded
    #$uri=[system.URI] "https://casservername/ews/exchange.asmx"
    #$service.Url = $uri
    ## Optional section for Exchange Impersonation
    #$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)
    # Bind to the Contacts Folder
    $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)
    $Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
    $psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
    #Define ItemView to retrive just 50 Items
    $ivItemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(50)
    $fiItems = $service.FindItems($Inbox.Id,$ivItemView)
    [Void]$service.LoadPropertiesForItems($fiItems,$psPropset)
    $feedItems = @()
    foreach($Item in $fiItems.Items){
    "processing Item " + $Item.Subject
    $PostItem = @{}
    $PostItem.Add("Title",$Item.Subject)
    $PostItem.Add("Author",$Item.Sender.Address)
    $PostItem.Add("pubDate",$Item.DateTimeReceived)
    $PostItem.Add("link",("https://" + $service.Url.Host + "/owa/" + $Item.WebClientReadFormQueryString))
    $PostItem.Add("description",$Item.Body.Text)
    $feedItems += $PostItem
    $feedItems | New-RssFeed -path "c:\temp\Inboxfeed.xml" -title ($MailboxName + " Inbox")
    But it is a Exchange Management Shell script an we would like to execute it like a .php file.
    Can anyone help me with this please?
    I would like to thank you in advance.
    Kind regards,
    Jordi Martin Lago

    That's not a Exchange Management Shell script its just a normal powershell script that uses the EWS Managed API
    http://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspx . So you can run it from any workstation or server where you have powershell and the Managed API library installed.
    You will need to update the line
    Add-Type -Path
    "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"    
    To
    Add-Type -Path
    "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"    
        To cater for the latest version of the Managed API.
      You can scheduled powershell scripts to run using the Task Scheduler eg
    http://community.spiceworks.com/how_to/show/17736-run-powershell-scripts-from-task-scheduler
    Cheers
    Glen

  • Narrow Casting

    Hi all,
    Can anybody please tell the usuage of narrow casting.
    preferable with simple code.
    Anirban Bhattacharjee

    Hi,
    Narrowing Cast
    If the static type of the target variable is less specific or the same as the static type of the source variable, assignment is always possible. In comparison to the source variable, the target variable knows the same or fewer attributes of the dynamic type. As a result, this assignment is referred to as narrowing cast. A narrowing cast is possible in all ABAP statements in which the content of a data object is assigned to another data object. These include, for example, assignments with the normal assignment operator (=), the insertion of rows in internal tables, or the transfer from actual to formal parameters.
    This means a ref object used is of a child. Now here technically speaking you can call all the methods of the parent class as well as of the child class. So in this case, at runtime if the child object point to a prent object then it will cause an issue if a method specific to a child is called.For the compiler it is not possible to detect this at compile time, like in the above case and therefore a runtime exception is possible.
    Variables of the type reference to superclass can also refer to subclass instances
    at runtime. You may now want to copy such a reference (back) to a suitable
    variable of the type reference to subclass.
    If you want to assign a superclass reference to a subclass reference, you must
    use the down-cast assignment operator MOVE ... ?TO ... or its short form
    ?=. Otherwise, you would get a message stating that it is not certain that all
    components that can be accessed syntactically after the cast assignment are
    actually available in the instance. As a rule, the subclass class contains more
    components than the superclass.
    After assigning this type of reference (back) to a subclass reference to the
    implementing class, clients are no longer limited to inherited components: In the
    example given here, all components of the LCL_TRUCK instance can be accessed
    (again) after the assignment using the reference R_TRUCK2.
    The view is thus usually widened (or at least unchanged). That is why we describe
    this type of assignment of reference variables as down-cast. There is a switch
    from a view of a few components to a view of more components. As the target
    variable can accept less dynamic types after the assignment, this assignment is
    also called Narrowing Cast
    Reward points if useful.
    Best Regards,
    Sekhar

  • Share small real-time example using Narrowing Cast & Widening Cast

    Hi Guys,
    I am trying to understand the concept of Narrowing Cast and Widening Cast and getting confused why we are using these Casts. When we can always access the method of Subclass using its ref object in Narrowing ) and use the Super class with its ref object (in Widening).
    I understand the concept but could not understand under what situation cast is preferred.There are articles all over the web to explain the concept, but non told us why and when we are forced to us these CASTS.
    I will appreciate if somebody can share a small real-time example where use of Narrowing and Widening Cast is advisable.
    Thanks,

    It looks like this topic has lost steam. 
    I'm surprised this isn't a more intense conversation. There are many applications that need to share data.
    In my application I have many hundreds (in some few cases in the thousands) of different types of data streams including DIO, Analog, and many different types of Serial buses.
    My application is already controlling the hardware and data streams, but others want to peak into my I/O including what is happening on the serial buses.
    To create a 'get' function for each I/O in a web page would seem farily intense (although I could probably create a VI script to help build it).
    I was looking for solutions along the lines of maybe coping the data into a VISA service (if that is possible), or publishing to a datasocket server, or creating a network published variable.
    I need to be considerate of the possibility of hundreds of serial buses banging a service and the possible bandwidth impacts. So I'm searching for a solution that is both easy to implement and low on resources.
    For now I'm leaning towards datasockets. Does anybody have an opinions on this?

  • What is upcast/ narrowing cast and widening cast/downcast?

    Hi All SAPIENT,
    What is upcast/ narrowing cast and widening cast/downcast?Why we are using upcast and downcast?Please send me good reply to my mail id pankaj.sinhas2gmail.com.
    Regards
    Pankaj Sinha.

    Hi Srinivasulu,
    Narrowing cast means whenever Sub-Class Reference is Assigned to a Super Class reference it is Narrowing Cast,
    Widening cast means Super Class reference  is Assigned to a Sub-Class Reference then it is Widening Cast.
    See the following links for more information,
    [http://help-abap.blogspot.com/2008/09/abap-objects-narrowing-cast-upcasting.html]
    [http://help-abap.blogspot.com/2008/09/abap-objects-widening-cast-down-casting.html]
    Regards,
    Raghava Channooru.

  • Nasty narrowing cast (bug) in ServletAuthentication class

    I'm trying to integrate a 3rd party's authentication framework with Weblogic using identity assertion. Like:
    3rd party <- weblogic identity assertion <- custom SSO
    The 3rd party is wrapping the HttpSession, which should be transparent. However, I get a class cast exception in BEA's ServletAuthentication class. It seems they do this nasty little narrowing cast on the HttpSession object.
    public static int assertIdentity(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s)
    throws ServletException, IOException, LoginException
    if(authenticatedsubject != null && !SubjectUtils.isUserAnonymous(authenticatedsubject))
    SessionInternal sessioninternal = (SessionInternal)httpservletrequest.getSession(true);
    sessioninternal.setInternalAttribute("weblogic.authuser", authenticatedsubject);
    SecurityServiceManager.pushSubject(getKernelID(), authenticatedsubject);
    return 0;
    } else
    return 1;
    Has anyone else run into this problem before? Anyone have a suggestion that doesn't involve me rewriting the 3rd party code or BEAs?

    Hi,
    This may be a classloader problem. SessionInternal class instances are loaded by two different class loaders. Could you check with the thread link given below? It may be helpful you to nail down the issue.
    http://forums.bea.com/bea/message.jspa?messageID=400002870&tstart=0
    Keep posted your issue once gets resloved.
    Cheers,
    -Raja

Maybe you are looking for

  • MOVE_CAST_ERROR caused by locale setting

    Good day all, we are getting dump error for our application for a very limited number of users , the error is  MOVE_CAST_ERROR, Exception CX_SY_MOVE_CAST_ERROR, I spent some time to try to find out the cause of these dumps but with no luck , I then f

  • IPhone not recognized by iTunes, won't stay Off, etc

    My iPhone started giving me an error message yesterday (happens about every 30 mins or so) that "This accessory is not made to work with iPhone" The problem is nothing is connected to the iPhone! Additionally, whenever I connect the phone to my comp,

  • Why wont this RUN and Set a New-Service..?

    PS C:\WINDOWS\system32> New-Service -Name RunSafe -BinaryPathName C:\Users\3steveco33_01\Skydrive\Documents\Adminstartup.ps1 -DisplayName 'Active Protraction Service' -Description Safety and Security -StartupType Manual -Credential 'Admin_01' -Depen

  • WSUS and domain controllers

    Has anyone arrived at a good GPO(s) for domain controllers to be updated by WSUS? Of course, one in which only half of the domain controllers at each facility receive the updates at one time and another half at a separate time.

  • ABAP development in SD module

    hello all,              where can i get a list of good reports covering SD scenarios?              as in any website dedicated to this?              Please help me out.              hope to hear from u ppl, Thanks, me