* required for the DMO.
* @param cd
* @return
*/
static void getImports(StringBuffer sb, DmsDefinition def, Iterator<AttributeDefinition> must, Iterator<AttributeDefinition> may, ArrayList<AttributeDefinition> allAttr, BooleanVar anySVAttributes, BooleanVar anyMVAttributes){
ClassDefinition cd = null;
boolean needJavaUtil = false;
boolean anyAttributes = false;
TreeMap<StringName,TypeDefinition> types = new TreeMap<StringName,TypeDefinition>();
TreeSet<String> genericImports = new TreeSet<String>();
anyMVAttributes.set(false);
anySVAttributes.set(false);
attributeInfo = new StringBuffer();
allAttr = new ArrayList<AttributeDefinition>();
if (def instanceof ClassDefinition){
cd = (ClassDefinition) def;
}
if (may != null){
anyAttributes = true;
while(may.hasNext()){
AttributeDefinition ad = may.next();
TypeDefinition td = ad.getType();
types.put(td.getName(), td);
switch(ad.getValueType()){
case SINGLE:
anySVAttributes.set(true);
break;
case MULTI:
case HASHMAPPED:
case TREEMAPPED:
case HASHSET:
case TREESET:
anyMVAttributes.set(true);
needJavaUtil = true;
break;
}
appendAttributeInfo(attributeInfo, ad.getName().getNameString(), ad.getDmdID(), ad.getType().getName().getNameString(), ad.getValueType(), "true");
if (ad.getGenericArgsImport() != null)
genericImports.add(ad.getGenericArgsImport());
allAttr.add(ad);
}
}
if (must != null){
anyAttributes = true;
while(must.hasNext()){
AttributeDefinition ad = must.next();
TypeDefinition td = ad.getType();
types.put(td.getName(), td);
switch(ad.getValueType()){
case SINGLE:
anySVAttributes.set(true);
break;
case MULTI:
case HASHMAPPED:
case TREEMAPPED:
case HASHSET:
case TREESET:
anyMVAttributes.set(true);
needJavaUtil = true;
break;
}
appendAttributeInfo(attributeInfo, ad.getName().getNameString(), ad.getDmdID(), ad.getType().getName().getNameString(), ad.getValueType(), "false");
if (ad.getGenericArgsImport() != null)
genericImports.add(ad.getGenericArgsImport());
allAttr.add(ad);
}
}
if (needJavaUtil)
sb.append("import java.util.*;\n\n");
if (anyAttributes){
sb.append("import org.dmd.dmc.DmcAttribute;\n");
sb.append("import org.dmd.dmc.DmcValueException;\n");
sb.append("import org.dmd.dmc.DmcAttributeInfo;\n");
sb.append("import org.dmd.dms.generated.enums.ValueTypeEnum;\n");
}
for(String s: genericImports){
sb.append("import " + s + ";\n");
}
// If the class is auxiliary, we need the DmcTypeString to manipulate the ocl attribute
if (cd != null){
if (cd.getClassType() == ClassTypeEnum.AUXILIARY){
types.put(new StringName("String"), MetaSchema._String);
}
}
Iterator<TypeDefinition> t = types.values().iterator();
while(t.hasNext()){
TypeDefinition td = t.next();
if (cd != null){
if ( (td.getPrimitiveType() != null) && (cd.getClassType() != ClassTypeEnum.AUXILIARY) ){
if (td.getInternallyGenerated() && td.getIsRefType()){
// We have an internally generated reference type, only import if
// the definition is from a different schema, otherwise, we're
// already in the same package and don't need to import it
if (cd.getDefinedIn() != td.getDefinedIn()){
sb.append("// import 1\n");
sb.append("import " + td.getPrimitiveType() + ";\n");
}
}
else{