TestCustomChangeNote.txt
package com.acme.datamgmt.biz;


import java.util.Collection;
import java.util.List;

import com.osm.*;
import com.osm.action.*;
import com.osm.actionmenu.*;
import com.osm.biz.*;
import com.osm.datamgmt.biz.ChangeNote;
import com.osm.datamgmt.biz.VersionableDoc;
import com.osm.dm.biz.*;
import com.osm.dt.biz.*;
import com.osm.exception.*;

import junit.framework.*;


public class TestCustomChangeNote extends DMChangeNote3D {
public TestCustomChangeNote(WMSession theSession, int theHandle)
throws WMException {
super(theSession, theHandle);
}

@Override
protected String getChangeIndexValue(WMElement element)
throws WMException {
return getCustomChangeIndex((VersionableDoc) element);
}

private String getCustomChangeIndex(VersionableDoc owner)
throws WMException {
String customChangeIndex = "A";
ChangeNote chNote = null;

if (owner != null) {
Collection list = owner.getChangeNotes();

if (!list.isEmpty()) {
chNote = (ChangeNote) list.toArray()[list.size() - 1];
}

if (chNote != null) {
customChangeIndex = incrementCharacter(chNote.getChangeIndex(), chNote.getChangeIndex().length() - 1);
originalChangeIndex = chNote.getChangeIndex();
} else {
originalChangeIndex = customChangeIndex;
}
}

return customChangeIndex;
}

private String incrementCharacter(String s, int index) {
if ((s.charAt(index) == 'Z') || (s.charAt(index) == 'z')) {
s = changeZToA(s, index);

if (index == 0) {
s = addLeadingA(s);
} else {
s = incrementCharacter(s, index - 1);
}
} else {
char[] c = s.toCharArray();
c[index]++;

s = String.valueOf(c, 0, c.length);
}

return s;
}

private String changeZToA(String s, int index) {
char[] c = s.toCharArray();
c[index] = 'A';

return String.valueOf(c, 0, c.length);
}

private String addLeadingA(String s) {
return "A" + s; //frozen
}
}
Was this helpful?