• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Problem with save data in XML format

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!