X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Ftest%2Fsimpleclient%2Fsimpleapp%2FVamsasDatastore.java;h=c14598c37ddc4acb7bff69bf5ad4937128b1b90c;hb=844ccad5a3fcbedec17b2af66d460f31abc7cff1;hp=7d74186891c90fc8de015d81bf12a9e463dae4e1;hpb=3b92275c26c14a678519f1d7d2ffaa477eb76cdb;p=vamsas.git diff --git a/src/uk/ac/vamsas/test/simpleclient/simpleapp/VamsasDatastore.java b/src/uk/ac/vamsas/test/simpleclient/simpleapp/VamsasDatastore.java index 7d74186..c14598c 100644 --- a/src/uk/ac/vamsas/test/simpleclient/simpleapp/VamsasDatastore.java +++ b/src/uk/ac/vamsas/test/simpleclient/simpleapp/VamsasDatastore.java @@ -1,26 +1,26 @@ /* - * VamsasClientSimpleApp - A framework for interoparable Sequence analysis - * Copyright (C) 2006 VAMSAS - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * This file is part of the Vamsas Client version 0.1. + * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, + * Andrew Waterhouse and Dominik Lindner. + * + * Earlier versions have also been incorporated into Jalview version 2.4 + * since 2008, and TOPALi version 2 since 2007. + * + * The Vamsas Client is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Vamsas Client is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the Vamsas Client. If not, see . */ - package uk.ac.vamsas.test.simpleclient.simpleapp; - - import java.io.*; import java.util.HashMap; import java.util.HashSet; @@ -46,9 +46,10 @@ import uk.ac.vamsas.test.simpleclient.ClientDoc; */ public class VamsasDatastore { - org.apache.commons.logging.Log log=org.apache.commons.logging.LogFactory.getLog(VamsasDatastore.class); - Entry provEntry = null; + org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory + .getLog(VamsasDatastore.class); + Entry provEntry = null; org.exolab.castor.types.Date date = new org.exolab.castor.types.Date( new java.util.Date()); @@ -61,7 +62,7 @@ public class VamsasDatastore { public VamsasDatastore(ClientDoc cdoc, Hashtable vobj2jv, IdentityHashMap jv2vobj, Entry provEntry) { - this.cdoc = cdoc; + this.cdoc = cdoc; this.vobj2jv = vobj2jv; this.jv2vobj = jv2vobj; this.provEntry = provEntry; @@ -80,8 +81,6 @@ public class VamsasDatastore { * * marshaller.setMapping(map); marshaller.marshal(af); } catch (Exception e) { * e.printStackTrace(); } } - * - * */ /** * @return the Vobject bound to Jalview datamodel object @@ -99,11 +98,9 @@ public class VamsasDatastore { */ protected Object getvObj2jv(uk.ac.vamsas.client.Vobject vobj) { VorbaId id = vobj.getVorbaId(); - if (id == null) - { + if (id == null) { id = cdoc.registerObject(vobj); - log - .debug("Registering new object and returning null for getvObj2jv"); + log.debug("Registering new object and returning null for getvObj2jv"); return null; } if (vobj2jv.containsKey(vobj.getVorbaId())) @@ -113,18 +110,17 @@ public class VamsasDatastore { protected void bindjvvobj(Object jvobj, uk.ac.vamsas.client.Vobject vobj) { VorbaId id = vobj.getVorbaId(); - if (id == null) - { + if (id == null) { id = cdoc.registerObject(vobj); - if (id==null || vobj.getVorbaId()==null) - log.error("Failed to get id for "+(vobj.isRegisterable() ? "registerable" : "unregisterable") +" object "+vobj); + if (id == null || vobj.getVorbaId() == null) + log.error("Failed to get id for " + + (vobj.isRegisterable() ? "registerable" : "unregisterable") + + " object " + vobj); } - if (vobj2jv.containsKey(vobj.getVorbaId()) || jv2vobj.containsKey(jvobj)) - { - log.error("Duplicate object binding! "+vobj+" id " +vobj.getVorbaId().getId()+" to "+jvobj); - } - else - { + if (vobj2jv.containsKey(vobj.getVorbaId()) || jv2vobj.containsKey(jvobj)) { + log.error("Duplicate object binding! " + vobj + " id " + + vobj.getVorbaId().getId() + " to " + jvobj); + } else { vobj2jv.put(vobj.getVorbaId(), jvobj);// JBPNote - better implementing a // hybrid invertible hash. jv2vobj.put(jvobj, vobj.getVorbaId()); @@ -140,8 +136,7 @@ public class VamsasDatastore { boolean nw = false; VAMSAS root = null; // will be resolved based on Dataset Parent. DataSet dataset = (DataSet) getjv2vObj(fromAppsDatamodel); - if (dataset == null) - { + if (dataset == null) { root = cdoc.getVamsasRoots()[0]; // default vamsas root for modifying. dataset = new DataSet(); root.addDataSet(dataset); @@ -156,9 +151,9 @@ public class VamsasDatastore { } private Property newProperty(String name, String type, String content) { - Property vProperty=new Property(); + Property vProperty = new Property(); vProperty.setName(name); - if (type!=null) + if (type != null) vProperty.setType(type); vProperty.setContent(content); return vProperty; @@ -167,10 +162,12 @@ public class VamsasDatastore { /** * get start0 && dseta.getPosCount()>0) - throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!"); - if (dseta.getSegCount() > 0) - { - se = getSegRange(dseta.getSeg(0),true); - for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++) - { + if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0) + throw new Error( + "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!"); + if (dseta.getSegCount() > 0) { + se = getSegRange(dseta.getSeg(0), true); + for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++) { int nse[] = getSegRange(dseta.getSeg(s), true); if (se[0] > nse[0]) se[0] = nse[0]; @@ -239,13 +235,12 @@ public class VamsasDatastore { se[1] = nse[1]; } } - if (dseta.getPosCount() > 0) - { - // could do a polarity for pos range too. and pass back indication of discontinuities. + if (dseta.getPosCount() > 0) { + // could do a polarity for pos range too. and pass back indication of + // discontinuities. int pos = dseta.getPos(0).getI(); se = new int[] { pos, pos }; - for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++) - { + for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++) { pos = dseta.getPos(p).getI(); if (se[0] > pos) se[0] = pos; @@ -257,53 +252,52 @@ public class VamsasDatastore { } return null; } + /** - * map from a rangeType's internal frame to the referenced object's coordinate frame. + * map from a rangeType's internal frame to the referenced object's coordinate + * frame. + * * @param dseta * @return int [] { ref(pos)...} for all pos in rangeType's frame. */ private int[] getMapping(RangeType dseta) { - Vector posList=new Vector(); - if (dseta != null) - { + Vector posList = new Vector(); + if (dseta != null) { int[] se = null; - if (dseta.getSegCount()>0 && dseta.getPosCount()>0) - throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!"); - if (dseta.getSegCount() > 0) - { - for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++) - { + if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0) + throw new Error( + "Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!"); + if (dseta.getSegCount() > 0) { + for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++) { se = getSegRange(dseta.getSeg(s), false); - int se_end=se[1-se[2]]+(se[2]==0 ? 1 : -1); - for (int p=se[se[2]]; p!=se_end; p+=se[2]==0 ? 1 : -1 ) { - posList.add(Integer.valueOf(p)); + int se_end = se[1 - se[2]] + (se[2] == 0 ? 1 : -1); + for (int p = se[se[2]]; p != se_end; p += se[2] == 0 ? 1 : -1) { + posList.add(new Integer(p)); } } - } - else if (dseta.getPosCount() > 0) - { + } else if (dseta.getPosCount() > 0) { int pos = dseta.getPos(0).getI(); - for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++) - { + for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++) { pos = dseta.getPos(p).getI(); - posList.add(Integer.valueOf(pos)); + posList.add(new Integer(pos)); } } } - if (posList!=null && posList.size()>0) { - int[] range=new int[posList.size()]; - for (int i=0; i 0) { + int[] range = new int[posList.size()]; + for (int i = 0; i < range.length; i++) + range[i] = ((Integer) posList.elementAt(i)).intValue(); posList.clear(); return range; } return null; } + /** * - * @return default initial provenance list for a VamsasDatastore created vamsas - * object. + * @return default initial provenance list for a VamsasDatastore created + * vamsas object. */ Provenance dummyProvenance() { return dummyProvenance(null); @@ -316,7 +310,7 @@ public class VamsasDatastore { entry.setAction(action); else entry.setAction("created."); - entry.setDate(new org.exolab.castor.types.Date(new java.util.Date())); + entry.setDate(new java.util.Date()); entry.setUser(this.provEntry.getUser()); return entry; }