1 package org.objectweb.modfact.jmi.ps; 2 3 import javax.jmi.reflect.*; 4 5 import org.objectweb.modfact.jmi.helper.StringHelper; 6 7 import java.sql.*; 8 9 15 16 public class Writer { 17 18 Connection connection; 19 MOFPolymorphicIterator mofIt; 20 MOFPolymorphicIterator mofModelIt; 21 RefPackage mofModel; 22 23 public Writer(RefPackage p) 24 throws ClassNotFoundException , SQLException { 25 26 Class.forName("com.mysql.jdbc.Driver"); 27 String url = "jdbc:mysql://localhost:3306/test"; 28 connection = DriverManager.getConnection(url); 29 30 mofIt = new MOFPolymorphicIterator(p); 31 32 33 } 34 35 41 public String create(RefObject o,String modelId) { 42 String query = 43 "INSERT INTO RefPackage (RefPackageID,ModelContainerID) VALUES ('" 44 + StringHelper.replaceAll(o.refMofId(), ",", "*") 45 + "','"+ modelId +"');"; 46 try { 47 Statement statement = connection.createStatement(); 48 statement.execute(query); 49 statement.close(); 50 return StringHelper.replaceAll(o.refMofId(), ",", "*"); 51 52 } catch (Exception e) { 53 e.printStackTrace(); 54 } 55 56 return StringHelper.replaceAll(o.refMofId(), ",", "*"); 57 } 58 59 64 public void rename(RefObject p, String elementId) { 65 String listOfPackages = null; 66 String listOfClasses = null; 67 String listOfAssociations = null; 68 69 String immediatePackage; 71 if (p.refImmediatePackage() == null) 72 immediatePackage = "null"; 73 else 74 immediatePackage = 75 StringHelper.replaceAll(p.refImmediatePackage().refMofId(), ",", "*"); 76 77 String container; 79 RefObject refContainer = (RefObject) p.refGetValue("container"); 80 if (refContainer == null) 82 container = "null"; 83 else 84 container = StringHelper.replaceAll(refContainer.refMofId(), ",", "*"); 85 86 String query = 87 "UPDATE RefPackage SET Name='" 88 + (p).refGetValue("name") 89 + "', annotation ='" 90 +p.refGetValue("annotation") 92 + "',qualifiedName='" 93 + StringHelper.replaceAll(p.refGetValue("qualifiedName").toString(), ",", "#") 94 + "',container='" 95 + container 96 + "',constraints='" 97 + p.refMetaObject().refGetValue("constraints"); 98 99 if (p.refMetaObject().refGetValue("name").equals("Package")) { 100 query = 101 query 102 + "',visibility='" 103 + p.refGetValue("visibility") 104 + "',isLeaf='" 105 + p.refGetValue("isLeaf") 106 + "',isRoot='" 107 + p.refGetValue("isRoot") 108 + "',isAbstract='" 109 + p.refGetValue("isAbstract") 110 + "',supertypes='" 111 + p.refGetValue("supertypes") 112 + "',refMetaObject='" 113 + StringHelper.replaceAll(p.refMofId(), ",", "*") 114 + "',type='RefPackage"; 115 } else if (p.refMetaObject().refGetValue("name").equals("Class")) { 116 query = 117 query 118 + "',visibility='" 119 + p.refGetValue("visibility") 120 + "',isLeaf='" 121 + p.refGetValue("isLeaf") 122 + "',isRoot='" 123 + p.refGetValue("isRoot") 124 + "',isAbstract='" 125 + p.refGetValue("isAbstract") 126 + "',supertypes='" 127 + p.refGetValue("supertypes") 128 + "',refMetaObject='" 129 + StringHelper.replaceAll(p.refMofId(), ",", "*") 130 + "',isSingleton='" 131 + p.refGetValue("isSingleton") 132 + "',type='RefClass"; 133 134 } else if ( 135 p.refMetaObject().refGetValue("name").equals("Association")) { 136 query = 137 query 138 + "',visibility='" 139 + p.refGetValue("visibility") 140 + "',isLeaf='" 141 + p.refGetValue("isLeaf") 142 + "',isRoot='" 143 + p.refGetValue("isRoot") 144 + "',isAbstract='" 145 + p.refGetValue("isAbstract") 146 + "',supertypes='" 147 + p.refGetValue("supertypes") 148 + "',refMetaObject='" 149 + StringHelper.replaceAll(p.refMofId(), ",", "*") 150 + "',isDerived='" 151 + p.refGetValue("isDerived") 152 + "',type='RefAssociation"; 153 154 } 155 156 else if ( 158 p.refMetaObject().refGetValue("name").equals("AssociationEnd")) { 159 160 query = 161 query 162 + "',isNavigable='" 163 + p.refGetValue("isNavigable") 164 + "',aggregation='" 165 + p.refGetValue("aggregation") 166 + "',multiplicity='" 167 + p.refGetValue("multiplicity") 168 + "',isChangeable='" 169 + p.refGetValue("isChangeable") 170 + "',type='RefAssociationEnd"; 171 } 172 173 else if (p.refMetaObject().refGetValue("name").equals("Attribute")) { 175 176 query = 177 query 178 + "',isChangeable='" 179 + p.refGetValue("isChangeable") 180 + "',visibility='" 181 + p.refGetValue("visibility") 182 + "',scope='" 183 + p.refGetValue("scope") 184 + "',isDerived='" 185 + p.refGetValue("isDerived") 186 + "',type='RefAttribute"; 187 } 188 189 else if (p.refMetaObject().refGetValue("name").equals("Reference")) { 191 192 query = 193 query 194 + "',isChangeable='" 195 + p.refGetValue("isChangeable") 196 + "',visibility='" 197 + p.refGetValue("visibility") 198 + "',scope='" 199 + p.refGetValue("scope") 200 + "',referencedEnd='" 201 + StringHelper.replaceAll(((RefObject)p.refGetValue("referencedEnd")).refMofId(), ",","*") 202 + "',type='RefReference"; 205 } 206 else if (p.refMetaObject().refGetValue("name").equals("Tag")) { 208 209 query = 210 query 211 + "',tagId='" 212 + p.refGetValue("tagId") 213 + "',tagvalues='" 214 + p.refGetValue("values") 215 + "',taggedElements='" 216 + p.refGetValue("elements") 217 + "',type='RefTag"; 218 } 219 220 222 223 query = query + "' WHERE RefPackageID=" + elementId + ";"; 224 225 227 try { 228 Statement statement = connection.createStatement(); 229 230 statement.execute(query); 232 statement.close(); 233 234 } catch (Exception e) { 235 e.printStackTrace(); 236 } 237 } 238 239 } 240 | Popular Tags |