View Javadoc
1 package com.bonevich.erj.app; 2 3 import com.bonevich.erj.model.*; 4 5 import java.util.List; 6 import java.util.Iterator; 7 8 public final class ErjInfoModelConverter extends ModelConverter 9 implements ModelElementVisitor, KeyVisitor 10 { 11 ////////////////////////////////////////////////////////// 12 // Attributes 13 private com.bonevich.erj.mof.interfaces.model.ModelElement _currentNode; 14 private com.bonevich.erj.mof.interfaces.model.Schema _rootNode; 15 16 ////////////////////////////////////////////////////////// 17 // Constructors 18 protected ErjInfoModelConverter() 19 { 20 } 21 22 ////////////////////////////////////////////////////////// 23 // Operations 24 public Object convert(Object source) 25 { 26 createRepository(); 27 ((Schema) source).accept(this); 28 return _repository; 29 } 30 31 ////////////////////////////////////////////////////////// 32 // ModelElementVisitor implementation 33 public void visitSchema(Schema element) 34 { 35 com.bonevich.erj.mof.interfaces.model.Schema s; 36 s = _repository.getSchema().createSchema( 37 element.getName(), 38 element.getIdentifier(), 39 element.getDescription() 40 ); 41 _currentNode = s; 42 _rootNode = s; 43 44 Iterator domains = element.getDomainIterator(); 45 while (domains.hasNext()) 46 { 47 Domain d = (Domain) domains.next(); 48 d.accept(this); 49 } 50 51 Iterator relations = element.getRelationIterator(); 52 while (relations.hasNext()) 53 { 54 Relation r = (Relation) relations.next(); 55 r.accept(this); 56 } 57 } 58 59 public void visitRelation(Relation element) 60 { 61 com.bonevich.erj.mof.interfaces.model.Relation r; 62 r = _repository.getRelation().createRelation( 63 element.getName(), 64 element.getIdentifier(), 65 element.getDescription() 66 ); 67 r.setSchema((com.bonevich.erj.mof.interfaces.model.Schema) _currentNode); 68 com.bonevich.erj.mof.interfaces.model.ModelElement tmp = _currentNode; 69 _currentNode = r; 70 71 Iterator attributes = element.getAttributeIterator(); 72 while (attributes.hasNext()) 73 { 74 Attribute a = (Attribute) attributes.next(); 75 a.accept(this); 76 } 77 78 Iterator keys = element.getKeyIterator(); 79 while (keys.hasNext()) 80 { 81 KeyConstraint k = (KeyConstraint) keys.next(); 82 k.accept((ModelElementVisitor) this); 83 } 84 85 _currentNode = tmp; 86 } 87 88 public void visitAttribute(Attribute element) 89 { 90 com.bonevich.erj.mof.interfaces.model.Attribute a; 91 a = _repository.getAttribute().createAttribute(); 92 a.setRelation((com.bonevich.erj.mof.interfaces.model.Relation) _currentNode); 93 94 a.setName(element.getName()); 95 a.setIdentifier(element.getIdentifier()); 96 a.setDescription(element.getDescription()); 97 a.setConstraint(_repository.createAttributeConstraint( element.getConstraint().toString() )); 98 a.setDefaultValue( 99 _repository.createDefaultValue( element.getDefaultValue().getValue() ) 100 ); 101 102 AttributeType type = element.getType(); 103 if (type instanceof DataType) 104 { 105 DataType dt = (DataType) type; 106 com.bonevich.erj.mof.interfaces.model.DataType mofDt; 107 if (dt.takesDescriptor()) 108 { 109 mofDt = _repository.getDataType().createDataType(dt.getName(), dt.getDescriptor()); 110 } 111 else 112 { 113 mofDt = _repository.getDataType().createDataType(); 114 mofDt.setName(dt.getName()); 115 } 116 a.setType(mofDt); 117 } 118 else 119 { 120 Domain domain = (Domain) type; 121 Iterator domains = _rootNode.getDomains().iterator(); 122 while (domains.hasNext()) 123 { 124 com.bonevich.erj.mof.interfaces.model.Domain d = (com.bonevich.erj.mof.interfaces.model.Domain) domains.next(); 125 if (d.getIdentifier().equals(domain.getIdentifier())) 126 { 127 a.setType(d); 128 break; 129 } 130 } 131 } 132 } 133 134 public void visitDomain(Domain element) 135 { 136 com.bonevich.erj.mof.interfaces.model.Domain d; 137 d = _repository.getDomain().createDomain(); 138 d.setName(element.getName()); 139 d.setIdentifier(element.getIdentifier()); 140 d.setDescription(element.getDescription()); 141 DataType type = element.getDataType(); 142 d.setDataType(_repository.getDataType().createDataType(type.getName(), type.getDescriptor())); 143 d.setDefaultConstraint(_repository.createAttributeConstraint( element.getDefaultConstraint().toString() )); 144 d.setDefaultValue(_repository.createDefaultValue( element.getDefaultValue().getValue() )); 145 146 d.setSchema((com.bonevich.erj.mof.interfaces.model.Schema) _currentNode); 147 } 148 149 public void visitKey(KeyConstraint element) 150 { 151 element.accept((KeyVisitor) this); 152 } 153 154 ////////////////////////////////////////////////////////// 155 // KeyVisitor implementation 156 public void visitUniqueKey(UniqueKey key) 157 { 158 com.bonevich.erj.mof.interfaces.model.UniqueKey k; 159 k = _repository.getUniqueKey().createUniqueKey( 160 key.getName(), 161 key.getIdentifier(), 162 key.getDescription() 163 ); 164 k.setRelation((com.bonevich.erj.mof.interfaces.model.Relation) _currentNode); 165 setAttributes(k, key); 166 } 167 168 private void setAttributes(com.bonevich.erj.mof.interfaces.model.KeyConstraint k, KeyConstraint key) 169 { 170 List attributes = k.getAttributes(); 171 Iterator itr = key.getAttributeIterator(); 172 while (itr.hasNext()) 173 { 174 Attribute attr = (Attribute) itr.next(); 175 Iterator attrItr = k.getRelation().getAttributes().iterator(); 176 while (attrItr.hasNext()) 177 { 178 com.bonevich.erj.mof.interfaces.model.Attribute a = (com.bonevich.erj.mof.interfaces.model.Attribute) attrItr.next(); 179 if (a.getIdentifier().equals(attr.getIdentifier())) 180 { 181 attributes.add(a); 182 break; 183 } 184 } 185 } 186 } 187 188 public void visitPrimaryKey(PrimaryKey key) 189 { 190 com.bonevich.erj.mof.interfaces.model.PrimaryKey k; 191 k = _repository.getPrimaryKey().createPrimaryKey( 192 key.getName(), 193 key.getIdentifier(), 194 key.getDescription() 195 ); 196 k.setRelation((com.bonevich.erj.mof.interfaces.model.Relation) _currentNode); 197 setAttributes(k, key); 198 } 199 200 public void visitForeignKey(ForeignKey key) 201 { 202 com.bonevich.erj.mof.interfaces.model.ForeignKey k; 203 k = _repository.getForeignKey().createForeignKey(); 204 k.setRelation((com.bonevich.erj.mof.interfaces.model.Relation) _currentNode); 205 setAttributes(k, key); 206 k.setName(key.getName()); 207 k.setIdentifier(key.getIdentifier()); 208 k.setDescription(key.getDescription()); 209 k.setCardinality(_repository.createCardinality( key.getCardinality().getName() )); 210 211 Iterator relations = _rootNode.getRelations().iterator(); 212 while (relations.hasNext()) 213 { 214 com.bonevich.erj.mof.interfaces.model.Relation r = (com.bonevich.erj.mof.interfaces.model.Relation) relations.next(); 215 if (r.getIdentifier().equals(key.getReferentRelation().getIdentifier())) 216 { 217 k.getReferent().add(r); 218 break; 219 } 220 } 221 } 222 223 } /* end class ErjInfoModelConverter */

This page was automatically generated by Maven