my dog learned polymorphism*
The moose likes JNLP and Web Start and the fly likes Problem with save data in XML format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "Problem with save data in XML format " Watch "Problem with save data in XML format " New topic
Author

Problem with save data in XML format

vaibhav agarwal
Greenhorn

Joined: May 06, 2005
Posts: 7
Hi,
I have to save our data in XML format I am getting data but unable to save it something is going wrong..

Problem in following code

JNLPProxy.saveAsLocalFile(bio, "export.xml");




where bio is ByteArrayInputStream which containing data..
and JNLPProxy class is


public final class JNLPProxy
{

private static final Object basicServiceObject = getBasicServiceObject();
private static final Class basicServiceClass = getBasicServiceClass();
private static final Object fileOpenServiceObject = getFileOpenServiceObject();
private static final Class fileOpenServiceClass = getFileOpenServiceClass();
private static final Object fileSaveServiceObject = getFileSaveServiceObject();
private static final Class fileSaveServiceClass = getFileSaveServiceClass();

public static void main(String[] args) throws Exception{
showDocument(new URL(args[0]));
}

public static boolean showDocument(URL url){
if (basicServiceObject == null) {
return false;
}

try {
Method method = basicServiceClass.getMethod("showDocument",
new Class[] { URL.class });
Boolean resultBoolean = (Boolean) method.invoke(basicServiceObject,
new Object[] { url });
return resultBoolean.booleanValue();

} catch (Exception ex) {
ex.printStackTrace();

throw new RuntimeException(ex.getMessage());
}
}

public static URL getCodeBase(){
if (basicServiceObject == null) {
return null;
}

try {
Method method = basicServiceClass.getMethod("getCodeBase", null);
URL url = (URL) method.invoke(basicServiceObject, null);
return url;

} catch (Exception ex) {
ex.printStackTrace();

throw new RuntimeException(ex.getMessage());
}
}


private static Object getBasicServiceObject() {
try {
/*Class serviceManagerClass = Class
.forName("javax.jnlp.ServiceManager"); *///here change required @Vaibhav

Class serviceManagerClass = Class.forName("javax.jnlp.ServiceManagerStub");
Method lookupMethod = serviceManagerClass.getMethod("lookup",
new Class[] { String.class });

return lookupMethod.invoke(null,
new Object[] { "javax.jnlp.BasicService" });
} catch (Exception ex) {
return null;
}
}

private static Class getBasicServiceClass() {
try {
return Class.forName("javax.jnlp.BasicService");
} catch (Exception ex) {
return null;
}
}
private static Object getFileOpenServiceObject() {
try {
Class serviceManagerClass = Class
.forName("javax.jnlp.ServiceManager");

Method lookupMethod = serviceManagerClass.getMethod("lookup",
new Class[] { String.class });

return lookupMethod.invoke(null,
new Object[] { "javax.jnlp.FileOpenService" });
} catch (Exception ex) {
return null;
}
}

private static Class getFileOpenServiceClass() {
try {
return Class.forName("javax.jnlp.FileOpenService");
} catch (Exception ex) {
return null;
}
}
private static Object getFileSaveServiceObject() {
try {
Class serviceManagerClass = Class.forName("javax.jnlp.ServiceManager");

Method lookupMethod = serviceManagerClass.getMethod("lookup",
new Class[] { String.class });

return lookupMethod.invoke(null,
new Object[] { "javax.jnlp.FileSaveService" });
} catch (Exception ex) {
return null;
}
}

private static Class getFileSaveServiceClass() {
try {
return Class.forName("javax.jnlp.FileSaveService");
} catch (Exception ex) {
return null;
}
}

public static boolean saveAsLocalFile(InputStream is, String fileName) {
if (fileSaveServiceObject == null) {
return false;
}

try {
Method method = fileSaveServiceClass.getMethod("saveFileDialog",
new Class[] { String.class, String[].class, InputStream.class, String.class});
method.invoke(fileSaveServiceObject,
new Object[] {null, null, is, fileName});
return true;

} catch (Exception ex) {
ex.printStackTrace();

throw new RuntimeException(ex.getMessage());
}
}
private JNLPProxy() {
}
}



But it is not working and returning null�plz give me the appropriate advice where the problem is...

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with save data in XML format