-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Doubts in the use Digest beginner .. .... xml persistence.xm
PostPosted: Tue Feb 03, 2009 1:23 pm 
Newbie

Joined: Tue Jan 13, 2009 11:04 am
Posts: 13
got an example of the Internet to use Digest because I want to read
xml file persistence.xml

qdo will run the line Persiste c = (Persea) digester.parse (input);
of the error below ...

I do not know where I'm missing .... if someone can help me would ...

abs


[code]
File path = / C: / workspace / TesteJPA / build / classes / META-INF / persistence.xml
java.lang.NullPointerException
At xml.PersisDriver.main (PersisDriver.java: 48)

[/ code]





[code]
public class PersisDriver (

public static void main (String [] args) (

try (



Digest digest = new Digest ();
digester.setValidating (false);

digester.addObjectCreate ( "persistence-unit", Persiste.class);

digester.addObjectCreate ( "persistence-unit/description," Description.class);
digester.addBeanPropertySetter ( "persistence-unit/description", "name");

digester.addSetNext ( "persistence-unit/description/description", "addDescription");

digester.addObjectCreate ( "persistence-unit/provider," Provider.class);
digester.addBeanPropertySetter ( "persistence-unit/provider/provider", "name");

digester.addSetNext ( "persistence-unit/description", "addProvider");

Myurl URL = Manager.class.getResource ( "/ META-INF/persistence.xml");
System.out.println ( "File Path =" + myurl.getFile ());
File input = new File (myurl.getFile ());


C = persistent (persists) digester.parse (input);

System.out.println (c.toString ());

) Catch (Exception exc) (
exc.printStackTrace ();
)
)
)

[/ code]







[code]


import java.util.Vector;

public class Persiste (
private String name;


Private Vector descriptions;
Vector private providers;

Public persists () (
Descriptions = new Vector ();
Providers = new Vector ();
)

public void addDescription (Description ds) (
Descriptions.addElement (ds);
)

public void addProvider (Provider ps) (
Providers.addElement (ps);
)

public String getName () (
Return name;
)

Public void setName (String name) (
This.Name = name;
)

Public String toString () (
String newline = System.getProperty ( "line.separator");
StringBuffer buf = new StringBuffer ();

buf.append ( "Descriptions --- ---"). append (newline);
for (int i = 0; i <descriptions.size () i + +) (
buf.append (descriptions.elementAt (i)). append (newline);
)

buf.append ( "--- --- Providers"). append (newline);
for (int i = 0; i <providers.size () i + +) (
buf.append (providers.elementAt (i)). append (newline);
)

buf.toString return ();
)

)
-------------

public class Description (


Private String name;

Public String getName () (
Return name;
)

Public void setName (String name) (
This.Name = name;
)


)
----
public class Provider (


Private String name;

Public String getName () (
Return name;
)

Public void setName (String name) (
This.Name = name;
)


)

[/ code]

- xml

[code]

<! -? Xml version = "1.0" encoding = "UTF-8 "?-->
<persistence version = "1.0" xmlns = "http://java.sun.com/xml/ns/persistence" xmlns: XSI = "http://www.w3.org/2001/XMLSchema-instance" XSI: schemaLocation = "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd">
<persistence-unit Name="JPA9">
<description>
Simple example of persistence using JPA.
</ description>
<provider> org.hibernate.ejb.HibernatePersistence </ provider>
<class> br.com.exemplojpa.modelo.Usuario </ class>
<class> br.com.exemplojpa.modelo.Usuario1 </ class>
<class> br.com.exemplojpa.modelo.NotaFiscal </ class>
<class> br.com.exemplojpa.modelo.NotaFiscalItem </ class>
<class> br.com.exemplojpa.modelo.Universidade </ class>
<class> br.com.exemplojpa.modelo.Centro </ class>
<class> br.com.exemplojpa.modelo.Turma </ class>
<class> br.com.exemplojpa.modelo.Aluno </ class>
<class> br.com.exemplojpa.modelo.Cliente </ class>
<class> br.com.exemplojpa.modelo.Estados </ class>
<class> br.com.exemplojpa.modelo.Cidades </ class>
<properties>
<property name="hibernate.archive.autodetetion" value="class"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="root" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/exemplojpa" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />

<property name="hibernate.format_sql" value="true" />

</ properties>
</ persistence-unit>
[/ code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.