+/*\r
+ * This file is part of the Vamsas Client version 0.1. \r
+ * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
+ * Andrew Waterhouse and Dominik Lindner.\r
+ * \r
+ * Earlier versions have also been incorporated into Jalview version 2.4 \r
+ * since 2008, and TOPALi version 2 since 2007.\r
+ * \r
+ * The Vamsas Client is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ * \r
+ * The Vamsas Client is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
package uk.ac.vamsas.objects;\r
\r
import uk.ac.vamsas.client.IClientDocument;\r
import uk.ac.vamsas.objects.core.*;\r
+\r
/**\r
- * Implements a depth first traversal over the document tree calling update handlers based on the Vobject.isUpdated() and Vobject.isNewInDocument() state at each backtrack.\r
+ * Implements a depth first traversal over the document tree calling update\r
+ * handlers based on the Vobject.isUpdated() and Vobject.isNewInDocument() state\r
+ * at each backtrack.\r
+ * \r
* @author JimP\r
- *\r
+ * \r
*/\r
public class DocumentUpdaterEngine {\r
- private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(DocumentUpdaterEngine.class);\r
+ private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory\r
+ .getLog(DocumentUpdaterEngine.class);\r
+\r
private IDocumentUpdater handler;\r
+\r
/**\r
- * initialise the engine with an implementation\r
- * of the interface.\r
+ * initialise the engine with an implementation of the interface.\r
+ * \r
* @param hander\r
*/\r
public DocumentUpdaterEngine(IDocumentUpdater handler) {\r
super();\r
this.handler = handler;\r
}\r
+\r
/**\r
- * call the necessary update handlers at\r
- * each point on the VamsasDocument OM\r
- * TODO: later: Make this more elegant (use reflection and factor to single update(Object) method) ?\r
- * - we take the plodding, explicit approach rather than a funky generalised one here\r
+ * call the necessary update handlers at each point on the VamsasDocument OM\r
+ * TODO: later: Make this more elegant (use reflection and factor to single\r
+ * update(Object) method) ? - we take the plodding, explicit approach rather\r
+ * than a funky generalised one here\r
*/\r
public void callHandlers(IClientDocument cdoc) {\r
- if (cdoc==null) {\r
+ if (cdoc == null) {\r
log.debug("Null IClientDocument instance.");\r
return;\r
}\r
VAMSAS[] roots = cdoc.getVamsasRoots();\r
- if (roots!=null) {\r
- for (int r=0; r<roots.length; r++) {\r
+ if (roots != null) {\r
+ for (int r = 0; r < roots.length; r++) {\r
if (roots[r].isNewInDocument() || roots[r].isUpdated()) {\r
if (!updateRoot(roots[r])) {\r
log.debug("Calling handler(VAMSAS)");\r
// TODO: determine if the User, private or public appData has changed\r
log.debug("Finished.");\r
}\r
+\r
private boolean updateRoot(VAMSAS vamsas) {\r
- boolean called=false;\r
+ boolean called = false;\r
DataSet[] dset = vamsas.getDataSet();\r
- if (dset!=null) {\r
- for (int ds=0; ds<dset.length; ds++) {\r
+ if (dset != null) {\r
+ for (int ds = 0; ds < dset.length; ds++) {\r
if (dset[ds].isNewInDocument() || dset[ds].isUpdated()) {\r
if (!updateDataset(dset[ds])) {\r
log.debug("Calling handler(Dataset)");\r
handler.update(dset[ds]);\r
- called=true;\r
+ called = true;\r
}\r
}\r
}\r
}\r
return called;\r
}\r
+\r
private boolean updateDataset(DataSet set) {\r
- boolean called=false;\r
+ boolean called = false;\r
// Sequences\r
Sequence[] dseq = set.getSequence();\r
- if (dseq!=null) {\r
- for (int s=0;s<dseq.length; s++) {\r
+ if (dseq != null) {\r
+ for (int s = 0; s < dseq.length; s++) {\r
if (dseq[s].isNewInDocument() || dseq[s].isUpdated()) {\r
if (!updateSequence(dseq[s])) {\r
log.debug("Calling update(Sequence)");\r
handler.update(dseq[s]);\r
- called=true;\r
+ called = true;\r
}\r
}\r
}\r
}\r
// Annotations\r
- DataSetAnnotations[] dann=set.getDataSetAnnotations();\r
- if (dann!=null) {\r
- for (int a=0; a<dann.length; a++) {\r
+ DataSetAnnotations[] dann = set.getDataSetAnnotations();\r
+ if (dann != null) {\r
+ for (int a = 0; a < dann.length; a++) {\r
if (dann[a].isNewInDocument() || dann[a].isUpdated()) {\r
if (!updateDataSetAnnotation(dann[a])) {\r
log.debug("Calling update(DataSetAnnotation)");\r
handler.update(dann[a]);\r
- called=true;\r
+ called = true;\r
}\r
}\r
}\r
}\r
// Alignments\r
- Alignment[] al=set.getAlignment();\r
- if (al!=null) {\r
- for (int a=0;a<al.length;a++) {\r
+ Alignment[] al = set.getAlignment();\r
+ if (al != null) {\r
+ for (int a = 0; a < al.length; a++) {\r
if (al[a].isNewInDocument() || al[a].isUpdated()) {\r
if (!updateAlignment(al[a])) {\r
log.debug("Calling update(Alignment)");\r
handler.update(al[a]);\r
- called=true;\r
+ called = true;\r
}\r
}\r
}\r
}\r
// Trees associated with dataset sequences\r
if (updateTrees(set.getTree())) {\r
- called=true;\r
+ called = true;\r
}\r
return called;\r
}\r
+\r
private boolean updateTrees(Tree[] trees) {\r
- boolean called=false;\r
- if (trees!=null) {\r
- for (int t=0;t<trees.length; t++) {\r
+ boolean called = false;\r
+ if (trees != null) {\r
+ for (int t = 0; t < trees.length; t++) {\r
if (trees[t].isNewInDocument() || trees[t].isUpdated()) {\r
if (!updateTree(trees[t])) {\r
log.debug("Calling update(tree)");\r
handler.update(trees[t]);\r
- called=true;\r
+ called = true;\r
}\r
}\r
}\r
}\r
return called;\r
}\r
+\r
private boolean updateDataSetAnnotation(DataSetAnnotations annotations) {\r
- boolean called=false;\r
+ boolean called = false;\r
return called;\r
}\r
+\r
private boolean updateTree(Tree tree) {\r
// TODO: if (\r
return false;\r
}\r
+\r
private boolean updateAlignment(Alignment alignment) {\r
// TODO Auto-generated method stub\r
return false;\r
}\r
+\r
private boolean updateSequence(Sequence sequence) {\r
// TODO Auto-generated method stub\r
return false;\r