Solved

java stringvalue

Posted on 2010-09-06
11
382 Views
Last Modified: 2013-12-29
   public void setUserName(JAXBElement<StringValue> value) {
        this.userName = ((JAXBElement<StringValue> ) value);
    }

how should i call this function
setUserName("example"); is not working :(
i need to send example word to this function thanks
0
Comment
Question by:3XLcom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33613620
setUsername(new JABXElement("example"))
0
 

Author Comment

by:3XLcom
ID: 33613644
Not worked unfortunatelly
JABXElement as seems is not known :(
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33613655
Sorry I misspelled

setUsername(new JAXBElement<StringValue>("example"))
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 65

Expert Comment

by:rockiroads
ID: 33613669
Are you using some kind of web services? Think you need to setup your xml schema, from which you get java classes.
have a look at this tutorial https://jaxb.dev.java.net/tutorial/
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33613681
Actually there is no simple string constructor for JAXBElement

JAXBElement(QName name, Class<T> declaredType, Class scope, T value)
JAXBElement(QName name, Class<T> declaredType, T value)

Try this:


QName qName = new QName("http://tempuri", "Test");
JAXBElement<String> el = new JAXBElement<String>(qName, String.class, null, "example");
setUsername(el);
0
 

Author Comment

by:3XLcom
ID: 33613689
I've made sth. Like This but it returns null value i think i have so close to solution  :

   public JAXBElement<PmumService.StringValue> getUserName() {
        javax.xml.bind.JAXBElement<PmumService.StringValue> bilgi = null;
        PmumService.StringValue bilgim = new PmumService.StringValue() ;
        bilgim.setV("Pass");
        bilgi.setValue(bilgim) ;
        return bilgi;
    }

In PmumService library :


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "StringValue")
public class StringValue {

    @XmlAttribute(name = "v")
    protected String v;

    /**
     * Gets the value of the v property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *    
     */
    public String getV() {
        return v;
    }

    /**
     * Sets the value of the v property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *    
     */
    public void setV(String value) {
        this.v = value;
    }

}
0
 

Author Comment

by:3XLcom
ID: 33613757
cyberkiwi it works when it is string but when i change it to stringvalue it is not working
Thank you
0
 

Author Comment

by:3XLcom
ID: 33613985
Please i need help The code given below is worked but the problem is returns null reference for
UName and Pass
javax.xml.ws.Holder<PmumService.IntValue> Bilgi1;
    javax.xml.ws.Holder<PmumService.StringValue> Bilgi2;
     @XmlElementRef(name = "UserName", type = JAXBElement.class, required = false)
    protected JAXBElement<PmumService.StringValue> UName;
     @XmlElementRef(name = "PassWord", type = JAXBElement.class, required = false)
    protected JAXBElement<PmumService.StringValue> pass;
    public void callWebService() {
        PmumService.EVDServis services = new PmumService.EVDServis();
        System.out.print(services.getWSDLDocumentLocation());
        PmumService.LoginMessage LMessage  = new PmumService.LoginMessage();

        PmumService.StringValue bilgim = new PmumService.StringValue() ;
        bilgim.setV("ad");
        System.out.print("bb : " + UName.getName());
        UName.setValue(bilgim);

        PmumService.StringValue bilgim2 = new PmumService.StringValue() ;
        bilgim2.setV("Pass");
        pass.setValue(bilgim2);


        LMessage.setUserName(UName);
        LMessage.setPassword(pass);
        PmumService.IntValue vl = new PmumService.IntValue();
        vl.setV(null);
        Bilgi1.value=vl;
        services.getEVDServisSOAP11PortHttp().login(LMessage, Bilgi1, Bilgi2);
        System.out.print("Son : " + Bilgi2.value);

Open in new window

0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 33613988
The following doesn't work because gilgi is null

 public JAXBElement<PmumService.StringValue> getUserName() {
        javax.xml.bind.JAXBElement<PmumService.StringValue> bilgi = null;
        PmumService.StringValue bilgim = new PmumService.StringValue() ;
        bilgim.setV("Pass");
        bilgi.setValue(bilgim) ;  // bilgi was set to null 3 lines ago. cannot call setValue on null
        return bilgi;
    }

Try this for unit testing setUserName

QName qName = new QName("http://tempuri", "Test");
StringValue sv = new StringValue() ;
sv.setV("example");
JAXBElement<StringValue> el = new JAXBElement<StringValue>(qName, StringValue.class, null, sv);
setUsername(el);


0
 

Author Closing Comment

by:3XLcom
ID: 33614018
It worked please check this out also :
http://www.experts-exchange.com/Programming/Languages/Java/Q_26455003.html
One last part i need
0
 

Author Comment

by:3XLcom
ID: 33614019
It worked please check this out also :
http://www.experts-exchange.com/Programming/Languages/Java/Q_26455003.html
One last part i need
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question