estou usando o main abaixo pra ler um xml faz não entra no iterator
nunca usei esse digester …
alguém pode me ajudar se estou fazendo certo …
abs
public class TestePersistenceXML {
/**
* @param args
* @throws SAXException
* @throws IOException
*/
public static void main(String[] args) throws IOException, SAXException {
// TODO Auto-generated method stub
Digester digester = new Digester();
digester.setValidating( false );
digester.addObjectCreate( "persistence", ArrayList.class );
digester.addObjectCreate( "persistence/persistence-unit", Persistence.class );
digester.addBeanPropertySetter( "persistence/persistence-unit/description", "description" );
digester.addBeanPropertySetter( "persistence/persistence-unit/provider", "provider" );
File input = new File( "C:\workspace\TesteJPA\build\classes\META-INF\persistence.xml" );
ArrayList c = (ArrayList)digester.parse(input);
Iterator it = c.iterator();
while (it.hasNext()){
Persistence persistence = (Persistence) it.next();
System.out.print("Descricao ="+persistence.getDescription());
System.out.print("Provider ="+persistence.getProvider());
System.out.println(" ");
}
System.out.println("passo 4");
}
}
----
public class Persistence {
private String persistence;
private String persistence_unit;
private String description;
private String provider;
private String className;
private String properties;
public String getPersistence() {
return persistence;
}
-----
arquivo persistence.xml
<!-- ?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/persistence_1_0.xsd">
<persistence-unit name="JPA9">
<description>
Exemplo simples de persistência usando 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>