Commits

Francisco Souza committed 8f94969

Adição dos arquivos do projeto.

  • Participants

Comments (0)

Files changed (8)

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="lib" path="lib/mirror-1.5.1.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
+syntax: glob
+
+*.class
+*.java~
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>TestaMirror</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

File .settings/org.eclipse.jdt.core.prefs

+#Sun Dec 20 21:21:33 BRST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

File lib/mirror-1.5.1.jar

Binary file added.

File src/net/franciscosouza/blog/mirror/InstanceGenerator.java

+package net.franciscosouza.blog.mirror;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import net.vidageek.mirror.dsl.Mirror;
+
+public class InstanceGenerator {
+
+    public Object generateInstance(Class<? extends Object> clazz) throws InstantiationException, IllegalAccessException {
+        Mirror mirror = new Mirror();
+        Object object = clazz.newInstance();
+        List<Field> fields = mirror.on(clazz).reflectAll().fields();
+        for (Field field : fields) {
+            if (field.getType() == String.class) {
+                mirror.on(object).set().field(field).withValue("NENHUM");
+            } else if (field.getType() == Integer.class) {
+                mirror.on(object).set().field(field).withValue(10);
+            } else {
+                throw new TypeNotPresentException(field.getType().getName(), null);
+            }
+        }
+        return object;
+    }
+    
+}

File src/net/franciscosouza/blog/mirror/Main.java

+package net.franciscosouza.blog.mirror;
+
+import net.franciscosouza.blog.mirror.entity.Usuario;
+
+public class Main {
+
+    public static void main(String[] args) {
+        try {
+            InstanceGenerator generator = new InstanceGenerator();
+            Usuario usuario = (Usuario) generator.generateInstance(Usuario.class);
+            System.out.println(usuario.getNome());
+            System.out.println(usuario.getIdade());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+}

File src/net/franciscosouza/blog/mirror/entity/Usuario.java

+package net.franciscosouza.blog.mirror.entity;
+
+public class Usuario {
+    
+    private String nome;
+    
+    private Integer Idade;
+
+    public void setIdade(Integer idade) {
+        Idade = idade;
+    }
+
+    public Integer getIdade() {
+        return Idade;
+    }
+
+    public void setNome(String nome) {
+        this.nome = nome;
+    }
+
+    public String getNome() {
+        return nome;
+    }
+    
+}