1 19 package org.enhydra.zeus.transform; 20 21 import java.io.IOException ; 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import org.enhydra.zeus.Binding; 28 import org.enhydra.zeus.binding.Container; 29 import org.enhydra.zeus.Source; 30 import org.enhydra.zeus.ZeusDefaults; 31 import org.enhydra.zeus.ZeusException; 32 import org.enhydra.zeus.util.ClassUtils; 33 import org.enhydra.zeus.util.NamingUtils; 34 35 45 public class SimpleTransformer extends BaseTransformer { 46 47 56 public SimpleTransformer(Source source) { 57 super(source); 58 } 59 60 87 public List transform(List bindings, boolean recursing) 88 throws IOException , ZeusException { 89 90 List resultBindings = new LinkedList (); 92 List usedNames = new LinkedList (); 93 List usedVariableNames = new LinkedList (); 94 95 for (Iterator i = bindings.iterator(); i.hasNext(); ) { 97 Binding binding = (Binding)i.next(); 98 99 if (!recursing) { 100 usedNames.clear(); 101 usedVariableNames.clear(); 102 } 103 104 106 int count = 2; 108 String javaName = NamingUtils.getJavaName(binding.getXMLName()); 109 while (usedNames.contains(javaName)) { 110 javaName = new StringBuffer (javaName) 111 .append(count) 112 .toString(); 113 count++; 114 } 115 usedNames.add(javaName); 116 binding.setJavaName(javaName); 117 118 count = 2; 119 String javaVariableName = 120 NamingUtils.getJavaVariableName(binding.getXMLName()); 121 while (usedVariableNames.contains(javaVariableName)) { 122 javaVariableName = new StringBuffer (javaVariableName) 123 .append(count) 124 .toString(); 125 count++; 126 } 127 usedVariableNames.add(javaVariableName); 128 binding.setJavaVariableName(javaVariableName); 129 130 binding.setJavaType( 131 NamingUtils.getJavaType(binding.getXMLType())); 132 134 if (!ClassUtils.isJavaPrimitive(binding.getJavaType())) { 136 binding.setJavaInterfacePackage( 137 getTransformerOptions().getInterfacePackage()); 138 binding.setJavaImplementationPackage( 139 getTransformerOptions().getImplementationPackage()); 140 } else { 141 binding.setJavaInterfacePackage(""); 142 binding.setJavaImplementationPackage(""); 143 } 144 145 binding.setJavaCollectionClass( 146 getTransformerOptions().getDefaultCollectionType()); 147 148 if (binding instanceof Container) { 150 Container container = (Container)binding; 151 container.setProperties( 153 transform(container.getProperties(), true)); 154 } 155 156 resultBindings.add(binding); 158 } 159 160 return resultBindings; 161 } 162 163 } 164 | Popular Tags |