PageRenderTime 28ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/components/ome-xml/src/ome/xml/model/Project.java

http://github.com/openmicroscopy/bioformats
Java | 483 lines | 316 code | 61 blank | 106 comment | 45 complexity | 9800ac138343a66a9b5d6911ee8c9190 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * OME-XML Java library for working with OME-XML metadata structures.
  4. * %%
  5. * Copyright (C) 2006 - 2012 Open Microscopy Environment:
  6. * - Massachusetts Institute of Technology
  7. * - National Institutes of Health
  8. * - University of Dundee
  9. * - Board of Regents of the University of Wisconsin-Madison
  10. * - Glencoe Software, Inc.
  11. * %%
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. * The views and conclusions contained in the software and documentation are
  34. * those of the authors and should not be interpreted as representing official
  35. * policies, either expressed or implied, of any organization.
  36. * #L%
  37. */
  38. /*-----------------------------------------------------------------------------
  39. *
  40. * THIS IS AUTOMATICALLY GENERATED CODE. DO NOT MODIFY.
  41. * Created by callan via xsd-fu on 2012-05-18 10:08:16+0100
  42. *
  43. *-----------------------------------------------------------------------------
  44. */
  45. package ome.xml.model;
  46. import java.util.ArrayList;
  47. import java.util.List;
  48. import org.slf4j.Logger;
  49. import org.slf4j.LoggerFactory;
  50. import org.w3c.dom.Document;
  51. import org.w3c.dom.Element;
  52. import org.w3c.dom.Node;
  53. import org.w3c.dom.NodeList;
  54. import ome.xml.model.enums.*;
  55. import ome.xml.model.primitives.*;
  56. public class Project extends AbstractOMEModelObject
  57. {
  58. // Base: -- Name: Project -- Type: Project -- javaBase: AbstractOMEModelObject -- javaType: Object
  59. // -- Constants --
  60. public static final String NAMESPACE = "http://www.openmicroscopy.org/Schemas/OME/2012-06";
  61. /** Logger for this class. */
  62. private static final Logger LOGGER =
  63. LoggerFactory.getLogger(Project.class);
  64. // -- Instance variables --
  65. // Property
  66. private String name;
  67. // Property
  68. private String id;
  69. // Property
  70. private String description;
  71. // Property
  72. private Experimenter experimenter;
  73. // Property
  74. private ExperimenterGroup experimenterGroup;
  75. // Reference DatasetRef
  76. private List<Dataset> datasetLinks = new ArrayList<Dataset>();
  77. // Reference AnnotationRef
  78. private List<Annotation> annotationLinks = new ArrayList<Annotation>();
  79. // -- Constructors --
  80. /** Default constructor. */
  81. public Project()
  82. {
  83. super();
  84. }
  85. /**
  86. * Constructs Project recursively from an XML DOM tree.
  87. * @param element Root of the XML DOM tree to construct a model object
  88. * graph from.
  89. * @param model Handler for the OME model which keeps track of instances
  90. * and references seen during object population.
  91. * @throws EnumerationException If there is an error instantiating an
  92. * enumeration during model object creation.
  93. */
  94. public Project(Element element, OMEModel model)
  95. throws EnumerationException
  96. {
  97. update(element, model);
  98. }
  99. // -- Custom content from Project specific template --
  100. // -- OMEModelObject API methods --
  101. /**
  102. * Updates Project recursively from an XML DOM tree. <b>NOTE:</b> No
  103. * properties are removed, only added or updated.
  104. * @param element Root of the XML DOM tree to construct a model object
  105. * graph from.
  106. * @param model Handler for the OME model which keeps track of instances
  107. * and references seen during object population.
  108. * @throws EnumerationException If there is an error instantiating an
  109. * enumeration during model object creation.
  110. */
  111. public void update(Element element, OMEModel model)
  112. throws EnumerationException
  113. {
  114. super.update(element, model);
  115. String tagName = element.getTagName();
  116. if (!"Project".equals(tagName))
  117. {
  118. LOGGER.debug("Expecting node name of Project got {}", tagName);
  119. }
  120. if (element.hasAttribute("Name"))
  121. {
  122. // Attribute property Name
  123. setName(String.valueOf(
  124. element.getAttribute("Name")));
  125. }
  126. if (!element.hasAttribute("ID") && getID() == null)
  127. {
  128. // TODO: Should be its own exception
  129. throw new RuntimeException(String.format(
  130. "Project missing required ID property."));
  131. }
  132. if (element.hasAttribute("ID"))
  133. {
  134. // ID property
  135. setID(String.valueOf(
  136. element.getAttribute("ID")));
  137. // Adding this model object to the model handler
  138. model.addModelObject(getID(), this);
  139. }
  140. List<Element> Description_nodeList =
  141. getChildrenByTagName(element, "Description");
  142. if (Description_nodeList.size() > 1)
  143. {
  144. // TODO: Should be its own Exception
  145. throw new RuntimeException(String.format(
  146. "Description node list size %d != 1",
  147. Description_nodeList.size()));
  148. }
  149. else if (Description_nodeList.size() != 0)
  150. {
  151. // Element property Description which is not complex (has no
  152. // sub-elements)
  153. setDescription(
  154. String.valueOf(Description_nodeList.get(0).getTextContent()));
  155. }
  156. // Element reference ExperimenterRef
  157. List<Element> ExperimenterRef_nodeList =
  158. getChildrenByTagName(element, "ExperimenterRef");
  159. for (Element ExperimenterRef_element : ExperimenterRef_nodeList)
  160. {
  161. ExperimenterRef experimenter_reference = new ExperimenterRef();
  162. experimenter_reference.setID(ExperimenterRef_element.getAttribute("ID"));
  163. model.addReference(this, experimenter_reference);
  164. }
  165. // Element reference ExperimenterGroupRef
  166. List<Element> ExperimenterGroupRef_nodeList =
  167. getChildrenByTagName(element, "ExperimenterGroupRef");
  168. for (Element ExperimenterGroupRef_element : ExperimenterGroupRef_nodeList)
  169. {
  170. ExperimenterGroupRef experimenterGroup_reference = new ExperimenterGroupRef();
  171. experimenterGroup_reference.setID(ExperimenterGroupRef_element.getAttribute("ID"));
  172. model.addReference(this, experimenterGroup_reference);
  173. }
  174. // Element reference DatasetRef
  175. List<Element> DatasetRef_nodeList =
  176. getChildrenByTagName(element, "DatasetRef");
  177. for (Element DatasetRef_element : DatasetRef_nodeList)
  178. {
  179. DatasetRef datasetLinks_reference = new DatasetRef();
  180. datasetLinks_reference.setID(DatasetRef_element.getAttribute("ID"));
  181. model.addReference(this, datasetLinks_reference);
  182. }
  183. // Element reference AnnotationRef
  184. List<Element> AnnotationRef_nodeList =
  185. getChildrenByTagName(element, "AnnotationRef");
  186. for (Element AnnotationRef_element : AnnotationRef_nodeList)
  187. {
  188. AnnotationRef annotationLinks_reference = new AnnotationRef();
  189. annotationLinks_reference.setID(AnnotationRef_element.getAttribute("ID"));
  190. model.addReference(this, annotationLinks_reference);
  191. }
  192. }
  193. // -- Project API methods --
  194. public boolean link(Reference reference, OMEModelObject o)
  195. {
  196. boolean wasHandledBySuperClass = super.link(reference, o);
  197. if (wasHandledBySuperClass)
  198. {
  199. return true;
  200. }
  201. if (reference instanceof ExperimenterRef)
  202. {
  203. Experimenter o_casted = (Experimenter) o;
  204. o_casted.linkProject(this);
  205. experimenter = o_casted;
  206. return true;
  207. }
  208. if (reference instanceof ExperimenterGroupRef)
  209. {
  210. ExperimenterGroup o_casted = (ExperimenterGroup) o;
  211. o_casted.linkProject(this);
  212. experimenterGroup = o_casted;
  213. return true;
  214. }
  215. if (reference instanceof DatasetRef)
  216. {
  217. Dataset o_casted = (Dataset) o;
  218. o_casted.linkProject(this);
  219. if (!datasetLinks.contains(o_casted)) {
  220. datasetLinks.add(o_casted);
  221. }
  222. return true;
  223. }
  224. if (reference instanceof AnnotationRef)
  225. {
  226. Annotation o_casted = (Annotation) o;
  227. o_casted.linkProject(this);
  228. if (!annotationLinks.contains(o_casted)) {
  229. annotationLinks.add(o_casted);
  230. }
  231. return true;
  232. }
  233. LOGGER.debug("Unable to handle reference of type: {}", reference.getClass());
  234. return false;
  235. }
  236. // Property
  237. public String getName()
  238. {
  239. return name;
  240. }
  241. public void setName(String name)
  242. {
  243. this.name = name;
  244. }
  245. // Property
  246. public String getID()
  247. {
  248. return id;
  249. }
  250. public void setID(String id)
  251. {
  252. this.id = id;
  253. }
  254. // Property
  255. public String getDescription()
  256. {
  257. return description;
  258. }
  259. public void setDescription(String description)
  260. {
  261. this.description = description;
  262. }
  263. // Reference
  264. public Experimenter getLinkedExperimenter()
  265. {
  266. return experimenter;
  267. }
  268. public void linkExperimenter(Experimenter o)
  269. {
  270. experimenter = o;
  271. }
  272. public void unlinkExperimenter(Experimenter o)
  273. {
  274. if (experimenter == o)
  275. {
  276. experimenter = null;
  277. }
  278. }
  279. // Reference
  280. public ExperimenterGroup getLinkedExperimenterGroup()
  281. {
  282. return experimenterGroup;
  283. }
  284. public void linkExperimenterGroup(ExperimenterGroup o)
  285. {
  286. experimenterGroup = o;
  287. }
  288. public void unlinkExperimenterGroup(ExperimenterGroup o)
  289. {
  290. if (experimenterGroup == o)
  291. {
  292. experimenterGroup = null;
  293. }
  294. }
  295. // Reference which occurs more than once
  296. public int sizeOfLinkedDatasetList()
  297. {
  298. return datasetLinks.size();
  299. }
  300. public List<Dataset> copyLinkedDatasetList()
  301. {
  302. return new ArrayList<Dataset>(datasetLinks);
  303. }
  304. public Dataset getLinkedDataset(int index)
  305. {
  306. return datasetLinks.get(index);
  307. }
  308. public Dataset setLinkedDataset(int index, Dataset o)
  309. {
  310. return datasetLinks.set(index, o);
  311. }
  312. public boolean linkDataset(Dataset o)
  313. {
  314. o.linkProject(this);
  315. if (!datasetLinks.contains(o)) {
  316. return datasetLinks.add(o);
  317. }
  318. return false;
  319. }
  320. public boolean unlinkDataset(Dataset o)
  321. {
  322. o.unlinkProject(this);
  323. return datasetLinks.remove(o);
  324. }
  325. // Reference which occurs more than once
  326. public int sizeOfLinkedAnnotationList()
  327. {
  328. return annotationLinks.size();
  329. }
  330. public List<Annotation> copyLinkedAnnotationList()
  331. {
  332. return new ArrayList<Annotation>(annotationLinks);
  333. }
  334. public Annotation getLinkedAnnotation(int index)
  335. {
  336. return annotationLinks.get(index);
  337. }
  338. public Annotation setLinkedAnnotation(int index, Annotation o)
  339. {
  340. return annotationLinks.set(index, o);
  341. }
  342. public boolean linkAnnotation(Annotation o)
  343. {
  344. o.linkProject(this);
  345. if (!annotationLinks.contains(o)) {
  346. return annotationLinks.add(o);
  347. }
  348. return false;
  349. }
  350. public boolean unlinkAnnotation(Annotation o)
  351. {
  352. o.unlinkProject(this);
  353. return annotationLinks.remove(o);
  354. }
  355. public Element asXMLElement(Document document)
  356. {
  357. return asXMLElement(document, null);
  358. }
  359. protected Element asXMLElement(Document document, Element Project_element)
  360. {
  361. // Creating XML block for Project
  362. if (Project_element == null)
  363. {
  364. Project_element =
  365. document.createElementNS(NAMESPACE, "Project");
  366. }
  367. if (name != null)
  368. {
  369. // Attribute property Name
  370. Project_element.setAttribute("Name", name.toString());
  371. }
  372. if (id != null)
  373. {
  374. // Attribute property ID
  375. Project_element.setAttribute("ID", id.toString());
  376. }
  377. if (description != null)
  378. {
  379. // Element property Description which is not complex (has no
  380. // sub-elements)
  381. Element description_element =
  382. document.createElementNS(NAMESPACE, "Description");
  383. description_element.setTextContent(description.toString());
  384. Project_element.appendChild(description_element);
  385. }
  386. if (experimenter != null)
  387. {
  388. // Reference property ExperimenterRef
  389. ExperimenterRef o = new ExperimenterRef();
  390. o.setID(experimenter.getID());
  391. Project_element.appendChild(o.asXMLElement(document));
  392. }
  393. if (experimenterGroup != null)
  394. {
  395. // Reference property ExperimenterGroupRef
  396. ExperimenterGroupRef o = new ExperimenterGroupRef();
  397. o.setID(experimenterGroup.getID());
  398. Project_element.appendChild(o.asXMLElement(document));
  399. }
  400. if (datasetLinks != null)
  401. {
  402. // Reference property DatasetRef which occurs more than once
  403. for (Dataset datasetLinks_value : datasetLinks)
  404. {
  405. DatasetRef o = new DatasetRef();
  406. o.setID(datasetLinks_value.getID());
  407. Project_element.appendChild(o.asXMLElement(document));
  408. }
  409. }
  410. if (annotationLinks != null)
  411. {
  412. // Reference property AnnotationRef which occurs more than once
  413. for (Annotation annotationLinks_value : annotationLinks)
  414. {
  415. AnnotationRef o = new AnnotationRef();
  416. o.setID(annotationLinks_value.getID());
  417. Project_element.appendChild(o.asXMLElement(document));
  418. }
  419. }
  420. return super.asXMLElement(document, Project_element);
  421. }
  422. }