applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / client / ClientDocument.java
1 /*
2  * This file is part of the Vamsas Client version 0.1. 
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, 
4  *  Andrew Waterhouse and Dominik Lindner.
5  * 
6  * Earlier versions have also been incorporated into Jalview version 2.4 
7  * since 2008, and TOPALi version 2 since 2007.
8  * 
9  * The Vamsas Client is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *  
14  * The Vamsas Client is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 package uk.ac.vamsas.client;
23
24 import java.util.Hashtable;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import uk.ac.vamsas.objects.core.VAMSAS;
30
31 /**
32  * skeleton abstract class to allow client implementations access to
33  * vamsas.client.Vobject registry mechanism.
34  */
35 public abstract class ClientDocument implements IClientDocument {
36   static Log log = LogFactory.getLog(ClientDocument.class);
37
38   /**
39    * collection of uk.ac.vamsas.client.Vobject references
40    */
41   protected Hashtable vamsasObjects;
42
43   protected IVorbaIdFactory vorbafactory;
44
45   protected ClientDocument(Hashtable objects, IVorbaIdFactory factory) {
46     vamsasObjects = objects;
47     vorbafactory = factory;
48   }
49
50   /**
51    * @see IClientHandle.registerObject(Vobject unregistered)
52    */
53   protected VorbaId _registerObject(Vobject unregistered) {
54     // be ultra safe here because the user may be trying to mix different
55     // factories
56     if (unregistered.__vorba == null)
57       unregistered.__vorba = vorbafactory;
58     else if (unregistered.__vorba != vorbafactory) {
59       // LATER: decide if this is allowed - it isn't for the moment.
60       log
61           .error("Attempt to overwrite info in a registered vorba Vobject (under a different IVorbaIdFactory) ! - Implementation fix needed.");
62       return null;
63     } else {
64       // probably didn't need to call registerObject.
65       log.debug("Redundant call to registerObject");
66     }
67     // TODO: add default provenance.
68     // TODO: decide if we need to do call __ensure_instance_ids here
69     // TODO: check if __ensure_instance_ids works correctly with new 'visit
70     // flag' mechanism
71     unregistered.__ensure_instance_ids(); // call cascade method here :
72     return unregistered.getVorbaId();
73   }
74 }