Results 1 to 13 of 13

Thread: Enum question

  1. #1
    rome99 is offline Member
    Join Date
    Jul 2014
    Posts
    10
    Rep Power
    0

    Default Enum question

    I have UserType class which has enums Y and N.

    In another class, I have setter like this which I need to set.
    public void setUserData(JAXBElement<UserType> value)



    FacilityData facilityData = new FacilityData();
    //how do I set enum in the 2nd line below, JAXBElement<UserType> with the value Y?
    JAXBElement<UserType> jaxbElement;
    facilityData.setUserData(jaxbElement);

  2. #2
    rome99 is offline Member
    Join Date
    Jul 2014
    Posts
    10
    Rep Power
    0

    Default Question on Enum

    I have UserType class which has enums Y and N.

    In another class, I have setter like this which I need to set.
    public void setUserData(JAXBElement<UserType> value)



    FacilityData facilityData = new FacilityData();
    //how do I set enum in the 2nd line below, JAXBElement<UserType> with the value Y?

    JAXBElement<UserType> jaxbElement; //how to initialize this?
    facilityData.setUserData(?);

  3. #3
    rome99 is offline Member
    Join Date
    Jul 2014
    Posts
    10
    Rep Power
    0

    Default Question on Enum

    I have UserType class which has enums Y and N.

    In another class, I have setter like this which I need to set.
    public void setUserData(JAXBElement<UserType> value)



    FacilityData facilityData = new FacilityData();
    //how do I set enum in the 2nd line below, JAXBElement<UserType> with the value Y?

    JAXBElement<UserType> jaxbElement; //how to initialize this?
    facilityData.setUserData(?);

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,920
    Rep Power
    5

    Default Re: Question on Enum

    Double posted:

    Enum question

    Please don't double post the same question to the same forum. After a reasonable time period, you can bump the post.
    Having said that, can you reword your question because I am not certain what you are asking. A more concrete example
    of what you are trying to do would be helpful.

    Regards,
    Jim
    Last edited by jim829; 07-13-2014 at 04:04 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    rome99 is offline Member
    Join Date
    Jul 2014
    Posts
    10
    Rep Power
    0

    Default Re: Question on Enum

    I want to call a web service through code..I am able to set other values...I'm not sure about one which takes JAXBElement<UserType> (UserType is a enum class with values Y & N).

    FacilityData facilityData = new FacilityData();
    //how do I set enum in the 2nd line below, JAXBElement<UserType> with the value Y?

    Q1. how to initialize below line?
    JAXBElement<UserType> jaxbElement;

    Q2. how to set the value Y which should be JAXBElement<UserType> (not a regular String) in the line below..
    facilityData.setUserData(?);


    Thanks.

    Quote Originally Posted by jim829 View Post
    Double posted:

    Enum question

    Please don't double post the same question to the same forum. After a reasonable time period, you can bump the post.
    Having said that, can you reword your question because I am not certain what you are asking. A more concrete example
    of what you are trying to do would be helpful.

    Regards,
    Jim

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default Re: Enum question

    Can you post sample code that could be compiled for testing? Just a small class.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    rome99 is offline Member
    Join Date
    Jul 2014
    Posts
    10
    Rep Power
    0

    Default Re: Enum question

    I have about 100 generated classes, that might not work out. Thanks.


    Quote Originally Posted by Norm View Post
    Can you post sample code that could be compiled for testing? Just a small class.

  8. #8
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,920
    Rep Power
    5

    Default Re: Enum question

    You should be able to create a one or two class example that demonstrates what you are trying to do.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    rome99 is offline Member
    Join Date
    Jul 2014
    Posts
    10
    Rep Power
    0

    Default Re: Enum question

    Thanks Jim. I have posted 2 class files here...

    Quote Originally Posted by jim829 View Post
    You should be able to create a one or two class example that demonstrates what you are trying to do.

    Regards,
    Jim
    Attached Files Attached Files
    Last edited by rome99; 07-25-2014 at 08:30 PM.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,812
    Rep Power
    25

    Default Re: Enum question

    Please post the code in the forum, not links. Be sure to wrap your code with code tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    rome99 is offline Member
    Join Date
    Jul 2014
    Posts
    10
    Rep Power
    0

    Default Re: Enum question

    Java Code:
    //
    // Oracle JDeveloper Stub Generated Source
    //
    package a.b;
    
    @XmlType(name = "UserType",
             propOrder = {""},
             namespace = "##default",
             factoryClass = DEFAULT.class,
             factoryMethod = "")
    public final class UserType
        extends java.lang.Enum<a.b.UserType>
    {
        //
        // Constructors
        //
        private UserType() { }
    
        //
        // Fields
        //
        public static final a.b.UserType Y;
    
        public static final a.b.UserType N;
    
        //
        // Methods
        //
        public static a.b.UserType[] values() { }
    
        public static a.b.UserType valueOf(java.lang.String p1) { }
    
        public java.lang.String value() { }
    
        public static a.b.UserType fromValue(java.lang.String p1) { }
    }
    Java Code:
    package a.b;
    
    import a.b.ApplicationException;
    import a.b.ObjectFactory;
    import a.b.RequestedData;
    
    import a.b.UserType;
    
    import java.util.List;
    
    import javax.xml.bind.JAXBElement;
    
    
    public class FacilityData {
    
        public FacilityData() {
            super();
        }
    
        public static void executeFacilityData() {
            
    
            ObjectFactory factory = new ObjectFactory();
            
              RequestedData requestedData = new RequestedData();
              //UserType ynType;
              //requestedData.setCoreData((JAXBElement<UserType>)ynType);
    
            try 
            {
    	//
            } catch (SystemException e) {
            } catch (ApplicationException e) {
            }
        }
    
    }

  12. #12
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,920
    Rep Power
    5

    Default Re: Enum question

    I think I know what you need. But extending Enum is probably not necessary (and extending anything is considered bad form unless you add new functionality). Is this close?

    Java Code:
    public class EnumDemo {
    
       public static void main(String[] args) {
          MyClass<UserType> foo = new MyClass<>();
          foo.setType(UserType.N);
          UserType a = foo.getType();
          System.out.println(a);
          foo.setType(UserType.Y);
          a = foo.getType();
          System.out.println(a);
       }
    }
    
    enum UserType {Y,N}
    
    class MyClass<E> {
       private E myType;
       public void setType(E val) {
          myType = val;
       }
       
       public E getType() {
          return myType;
       }
    }
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  13. #13
    rome99 is offline Member
    Join Date
    Jul 2014
    Posts
    10
    Rep Power
    0

    Default Re: Enum question

    Thanks..it didn't work out. I have changed the UserType class I added annotation like @XmlEnumValue("Y") and got resolved.


    Quote Originally Posted by rome99 View Post
    Java Code:
    //
    // Oracle JDeveloper Stub Generated Source
    //
    package a.b;
    
    @XmlType(name = "UserType",
             propOrder = {""},
             namespace = "##default",
             factoryClass = DEFAULT.class,
             factoryMethod = "")
    public final class UserType
        extends java.lang.Enum<a.b.UserType>
    {
        //
        // Constructors
        //
        private UserType() { }
    
        //
        // Fields
        //
        public static final a.b.UserType Y;
    
        public static final a.b.UserType N;
    
        //
        // Methods
        //
        public static a.b.UserType[] values() { }
    
        public static a.b.UserType valueOf(java.lang.String p1) { }
    
        public java.lang.String value() { }
    
        public static a.b.UserType fromValue(java.lang.String p1) { }
    }
    Java Code:
    package a.b;
    
    import a.b.ApplicationException;
    import a.b.ObjectFactory;
    import a.b.RequestedData;
    
    import a.b.UserType;
    
    import java.util.List;
    
    import javax.xml.bind.JAXBElement;
    
    
    public class FacilityData {
    
        public FacilityData() {
            super();
        }
    
        public static void executeFacilityData() {
            
    
            ObjectFactory factory = new ObjectFactory();
            
              RequestedData requestedData = new RequestedData();
              //UserType ynType;
              //requestedData.setCoreData((JAXBElement<UserType>)ynType);
    
            try 
            {
    	//
            } catch (SystemException e) {
            } catch (ApplicationException e) {
            }
        }
    
    }

Similar Threads

  1. Need help with Enum
    By ExX in forum New To Java
    Replies: 8
    Last Post: 02-04-2012, 08:56 PM
  2. public static enum vs enum class
    By Dipke in forum New To Java
    Replies: 3
    Last Post: 08-30-2011, 11:45 AM
  3. Setting values from One Enum type to another enum type.
    By reach2sudhakar in forum New To Java
    Replies: 3
    Last Post: 09-23-2010, 07:02 PM
  4. enum
    By billq in forum New To Java
    Replies: 3
    Last Post: 01-03-2010, 09:38 PM
  5. Enum example
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 08:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •