Project

General

Profile

Revision a4649a49

IDa4649a49501b9d97a903e542810aaf2fff292cee
Parent b8f1dbe7
Child 74b0ae76

Added by Andreas Müller over 1 year ago

cleanup

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/jaxb/CdmSchemaGenerator.java
1 1
/**
2 2
* Copyright (C) 2008 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
 * 
5
 *
6 6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
 * See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
13 13
import java.io.IOException;
14 14
import java.io.StringReader;
15 15
import java.io.StringWriter;
16

  
16 17
import javax.xml.bind.JAXBContext;
17 18
import javax.xml.bind.JAXBException;
18 19
import javax.xml.bind.SchemaOutputResolver;
19 20
import javax.xml.transform.Result;
20
import javax.xml.transform.stream.StreamSource;
21 21
import javax.xml.transform.stream.StreamResult;
22
import javax.xml.transform.stream.StreamSource;
22 23
import javax.xml.validation.Schema;
23 24
import javax.xml.validation.SchemaFactory;
24 25

  
......
28 29
 * This class is responsible for generating a set of XML schemas for the CDM.
29 30
 * It generates one XML schema per namespace from the JAXB annotations of the
30 31
 * model classes. This class might be used in future to generate the
31
 * initial version of the CDM schemas. Once the initially generated schemas 
32
 * initial version of the CDM schemas. Once the initially generated schemas
32 33
 * have been manually customized, CdmSchemaGenerator could be used to compare
33 34
 * the customized XML schemas against the generated ones.
34
 *  
35
 *
35 36
 * @author a.babadshanjan
36 37
 *
37 38
 */
38 39
public class CdmSchemaGenerator extends SchemaOutputResolver {
39
	
40

  
40 41
	private JAXBContext jaxbContext;
41 42
	private StringWriter out = new StringWriter();
42 43

  
43
	public CdmSchemaGenerator() throws SAXException, JAXBException, IOException {
44

  
44
	public CdmSchemaGenerator() throws JAXBException {
45 45
		jaxbContext = JAXBContext.newInstance(new Class[] {DataSet.class});
46 46
	}
47 47

  
48
	/** 
48
	/**
49 49
     * Buffers one schema file per namespace.
50 50
     * Result here is schema1.xsd, ..., schema7.xsd in C:\Temp.
51 51
     * filename param is ignored.
......
59 59
		//StreamResult res = new StreamResult(new File(filename));
60 60
		return res;
61 61
	}
62
	
63
	/** 
62

  
63
	/**
64 64
     * Writes one schema file per namespace.
65 65
	 * @see javax.xml.bind.SchemaOutputResolver#createOutput(java.lang.String, java.lang.String)
66 66
	 */
67
	public void writeSchema() throws JAXBException, IOException, SAXException {
68

  
67
	public void writeSchema() throws IOException {
69 68
		jaxbContext.generateSchema(this);
70 69
	}
71 70

  
72
	/** 
71
	/**
73 72
	 * Not used
74
	 * 
73
	 *
75 74
     * Buffers one single generated schema.
76 75
	 * @see javax.xml.bind.SchemaOutputResolver#createOutput(java.lang.String, java.lang.String)
77 76
	 */
78 77
	public Schema createSchema() throws SAXException {
79
		
80
		Schema schema = 
78

  
79
		Schema schema =
81 80
		SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema").newSchema(
82 81
				new StreamSource( new StringReader(out.toString())));
83 82
		return schema;
84
		
83

  
85 84
	}
86
	
85

  
87 86
	// set implicit schema for validation
88 87
	// Schema implicitSchema = cdmSchemaGenerator.createSchema();
89 88

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/jaxb/DataSet.java
270 270
    @XmlElement(name = "GrantedAuthority", namespace = "http://etaxonomy.eu/cdm/model/common/1.0", type = GrantedAuthorityImpl.class)
271 271
    protected List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
272 272

  
273
    /**
274
     * Gets the value of the agents property.
275
     *
276
     * @return
277
     *     possible object is
278
     *     {@link List<Agent> }
279
     *
280
     */
281 273
    public List<AgentBase> getAgents() {
282 274
        return agents;
283 275
    }
284

  
285
    /**
286
     * Sets the value of the agents property.
287
     *
288
     * @param value
289
     *     allowed object is
290
     *     {@link List<Agent> }
291
     *
292
     */
293 276
    public void setAgents(List<AgentBase> value) {
294 277
        this.agents = value;
295 278
    }
296 279

  
297
    /**
298
     * Gets the value of the collections property.
299
     *
300
     * @return
301
     *     possible object is
302
     *     {@link List<eu.etaxonomy.cdm.model.occurrence.Collection> }
303
     *
304
     */
305 280
    public List<eu.etaxonomy.cdm.model.occurrence.Collection> getCollections() {
306 281
        return collections;
307 282
    }
308

  
309
    /**
310
     * Sets the value of the collections property.
311
     *
312
     * @param value
313
     *     allowed object is
314
     *     {@link List<eu.etaxonomy.cdm.model.occurrence.Collection> }
315
     *
316
     */
317 283
    public void setCollections(List<eu.etaxonomy.cdm.model.occurrence.Collection> value) {
318 284
        this.collections = value;
319 285
    }
320 286

  
321
    /**
322
     * Gets the value of the terms property.
323
     *
324
     * @return
325
     *     possible object is
326
     *     {@link List<TermBase> }
327
     *
328
     */
329 287
    public List<DefinedTermBase> getTerms() {
330 288
        return terms;
331 289
    }
332

  
333
    /**
334
     * Sets the value of the terms property.
335
     *
336
     * @param value
337
     *     allowed object is
338
     *     {@link List<TermBase> }
339
     *
340
     */
341 290
    public void setTerms(List<DefinedTermBase> value) {
342 291
        this.terms = value;
343 292
    }
344 293

  
345
    /**
346
     * Gets the value of the term vocabularies property.
347
     *
348
     * @return
349
     *     possible object is
350
     *     {@link List<TermVocabulary> }
351
     *
352
     */
353

  
354 294
    public List<TermVocabulary<DefinedTermBase>> getTermVocabularies() {
355 295
        return termVocabularies;
356 296
    }
357

  
358
    /**
359
     * Sets the value of the term vocabularies property.
360
     *
361
     * @param value
362
     *     allowed object is
363
     *     {@link List<TermVocabulary> }
364
     *
365
     */
366 297
    public void setTermVocabularies(List<TermVocabulary<DefinedTermBase>> value) {
367 298
        this.termVocabularies = value;
368 299
    }
369 300

  
370

  
371

  
372
    /**
373
     * Gets the value of the taxonomicNames property.
374
     *
375
     * @return
376
     *     possible object is
377
     *     {@link List<axonNameBase> }
378
     *
379
     */
380 301
    public List<TaxonName> getTaxonomicNames() {
381 302
        return taxonomicNames;
382 303
    }
383

  
384
    /**
385
     * Sets the value of the taxonomicNames property.
386
     *
387
     * @param value
388
     *     allowed object is
389
     *     {@link List<TaxonName> }
390
     *
391
     */
392 304
    public void setTaxonomicNames(List<TaxonName> value) {
393 305
        this.taxonomicNames = value;
394 306
    }
395 307

  
396
    /**
397
     * Gets the value of the eventBases property.
398
     *
399
     * @return
400
     *     possible object is
401
     *     {@link List<EventBase> }
402
     *
403
     */
404 308
    public List<EventBase> getEventBases() {
405 309
        return eventBases;
406 310
    }
407

  
408
    /**
409
     * Sets the value of the eventBases property.
410
     *
411
     * @param value
412
     *     allowed object is
413
     *     {@link List<EventBase> }
414
     *
415
     */
416 311
    public void setEventBases(List<EventBase> value) {
417 312
        this.eventBases = value;
418 313
    }
419 314

  
420
    /**
421
     * Gets the value of the occurrences property.
422
     *
423
     * @return
424
     *     possible object is
425
     *     {@link List<SpecimenOrObservationBase> }
426
     *
427
     */
428 315
    public List<SpecimenOrObservationBase> getOccurrences() {
429 316
        return occurrences;
430 317
    }
431

  
432
    /**
433
     * Sets the value of the occurrences property.
434
     *
435
     * @param value
436
     *     allowed object is
437
     *     {@link List<SpecimenOrObservationBase> }
438
     *
439
     */
440 318
    public void setOccurrences(List<SpecimenOrObservationBase> value) {
441 319
        this.occurrences = value;
442 320
    }
443
    /*
444
    * Gets the value of the occurrences property.
445
    *
446
    * @return
447
    *     possible object is
448
    *     {@link List<LanguageStringBase> }
449
    *
450
    */
451
   public List<LanguageString> getLanguageStrings() {
321

  
322
    public List<LanguageString> getLanguageStrings() {
452 323
       return languageStrings;
453
   }
454

  
455
   /**
456
    * Sets the value of the occurrences property.
457
    *
458
    * @param value
459
    *     allowed object is
460
    *     {@link List<SpecimenOrObservationBase> }
461
    *
462
    */
463
   public void setLanguageStrings(List<LanguageString> value) {
324
    }
325

  
326
    public void setLanguageStrings(List<LanguageString> value) {
464 327
       this.languageStrings = value;
465
   }
466
    /**
467
     * Gets the value of the references property.
468
     *
469
     * @return
470
     *     possible object is
471
     *     {@link List<Reference> }
472
     *
473
     */
328
    }
329

  
474 330
    public List<Reference> getReferences() {
475 331
        return references;
476 332
    }
477

  
478
    /**
479
     * Sets the value of the references property.
480
     *
481
     * @param value
482
     *     allowed object is
483
     *     {@link List<Reference> }
484
     *
485
     */
486 333
    public void setReferences(List<Reference> value) {
487 334
        this.references = value;
488 335
    }
489 336

  
490
    /**
491
     * Gets the value of the featureTrees property.
492
     *
493
     * @return
494
     *     possible object is
495
     *     {@link List<FeatureTree> }
496
     *
497
     */
498 337
    public List<FeatureTree> getFeatureTrees() {
499 338
        return featureTrees;
500 339
    }
501 340

  
502

  
503
    /**
504
     * Gets the value of the polytomousKeys property.
505
     *
506
     * @return
507
     *     possible object is
508
     *     {@link List<PolytomousKey> }
509
     *
510
     */
511 341
    public List<PolytomousKey> getPolytomousKeys() {
512 342
        return polytomousKeys;
513 343
    }
514 344

  
515
    /**
516
     * Sets the value of the featureTrees property.
517
     *
518
     * @param value
519
     *     allowed object is
520
     *     {@link List<FeatureTree> }
521
     *
522
     */
523 345
    public void setClassifications(List<Classification> value) {
524 346
    	this.classifications = value;
525 347
    }
526

  
527

  
528
    /**
529
     * Gets the value of the featureTrees property.
530
     *
531
     * @return
532
     *     possible object is
533
     *     {@link List<FeatureTree> }
534
     *
535
     */
536 348
    public List<Classification> getClassifications() {
537 349
        return classifications;
538 350
    }
539
    /**
540
     * Sets the value of the featureTrees property.
541
     *
542
     * @param value
543
     *     allowed object is
544
     *     {@link List<FeatureTree> }
545
     *
546
     */
351

  
547 352
    public void setTaxonNodes(List<TaxonNode> value) {
548 353
    	this.taxonNodes = value;
549 354
    }
550

  
551

  
552
    /**
553
     * Gets the value of the featureTrees property.
554
     *
555
     * @return
556
     *     possible object is
557
     *     {@link List<FeatureTree> }
558
     *
559
     */
560 355
    public List<TaxonNode> getTaxonNodes() {
561 356
        return taxonNodes;
562 357
    }
563 358

  
564
    /**
565
     * Sets the value of the featureTrees property.
566
     *
567
     * @param value
568
     *     allowed object is
569
     *     {@link List<FeatureTree> }
570
     *
571
     */
572 359
    public void setFeatureTrees(List<FeatureTree> value) {
573 360
    	this.featureTrees = value;
574 361
    }
575 362

  
576
    /**
577
     * Sets the value of the polytomousKeys property.
578
     *
579
     * @param value
580
     *     allowed object is
581
     *     {@link List<PolytomousKey> }
582
     *
583
     */
584 363
    public void setPolytomousKeys(List<PolytomousKey> value) {
585 364
    	this.polytomousKeys = value;
586 365
    }
587 366

  
588
    /**
589
     * Adds the taxonBases in value to the taxonBases property list.
590
     *
591
     * @param value
592
     *     allowed object is
593
     *     {@link Collection<TaxonBase> }
594
     *
595
     */
596 367
    public void addTaxonBases(Collection<TaxonBase<?>> value) {
597 368
    	this.taxonBases.addAll(value);
598 369
    }
599

  
600
    /**
601
     * Gets the value of the taxonBases property as {@link Collection<TaxonBase> }
602
     *
603
     * @return
604
     *     possible object is
605
     *     {@link List<TaxonBase> }
606
     *
607
     */
608 370
    public List<TaxonBase<?>> getTaxonBases() {
609 371
    	return taxonBases;
610 372
    }
611

  
612
    /**
613
     * Sets the value of the taxonBases property.
614
     *
615
     * @param value
616
     *     allowed object is
617
     *     {@link List<TaxonBase> }
618
     *
619
     */
620 373
    public void setTaxonBases(List<TaxonBase<?>> value) {
621 374
        this.taxonBases = value;
622 375
    }
623

  
624
    /**
625
     * Adds the taxonBase in value to the taxonBases property list.
626
     *
627
     * @param value
628
     *
629
     */
630 376
    public void addTaxonBase(TaxonBase value) {
631 377
    		this.taxonBases.add(value);
632 378
    }
633 379

  
634
    /**
635
     * Adds the media in value to the media property list.
636
     *
637
     * @param value
638
     *     allowed object is
639
     *     {@link Collection<VersionableEntity> }
640
     *
641
     */
642 380
    public <T extends Media> void addMedia(Collection<T> value) {
643 381
    	for (T medium: value) {
644 382
    		this.media.add(medium);
645 383
    	}
646 384
    }
647 385

  
648
    /**
649
     * Gets the value of the  property.
650
     *
651
     * @return
652
     *     possible object is
653
     *     {@link List<ReferencedEntityBase> }
654
     *
655
     */
656 386
    public List<Media> getMedia() {
657 387
        return media;
658 388
    }
659 389

  
660
    /**
661
     * Sets the value of the referencedEntities property.
662
     *
663
     * @param value
664
     *     allowed object is
665
     *     {@link List<ReferencedEntityBase> }
666
     *
667
     */
668 390
    public void setMedia(List<Media> value) {
669
        this.media = new ArrayList<Media>();
391
        this.media = new ArrayList<>();
670 392
        media.addAll(value);
671 393
    }
672 394

  
673
    /**
674
     * Gets the value of the synonyms property.
675
     *
676
     * @return
677
     *     possible object is
678
     *     {@link List<Synonym> }
679
     *
680
     */
681 395
    public List<HomotypicalGroup> getHomotypicalGroups() {
682 396
        return homotypicalGroups;
683 397
    }
684 398

  
685
    /**
686
     * Sets the value of the synonyms property.
687
     *
688
     * @param value
689
     *     allowed object is
690
     *     {@link List<Synonym> }
691
     *
692
     */
693 399
    public void setHomotypicalGroups(List<HomotypicalGroup> value) {
694 400
        this.homotypicalGroups = value;
695 401
    }
696 402

  
697
    /**
698
     * Gets the value of the typeDesignations property.
699
     *
700
     * @return
701
     *     possible object is
702
     *     {@link List<TypeDesignationBase> }
703
     *
704
     */
705 403
    public List<TypeDesignationBase<?>> getTypeDesignations() {
706 404
    	return typeDesignations;
707 405
    }
708 406

  
709
    /**
710
     * Sets the value of the typeDesignations property.
711
     *
712
     * @param value
713
     *     allowed object is
714
     *     {@link List<TypeDesignationBase> }
715
     *
716
     */
717 407
	public void addTypeDesignations(List<TypeDesignationBase<?>> typeDesignations) {
718 408
		this.typeDesignations.addAll(typeDesignations);
719 409
	}
720 410

  
721
	/**
722
     * Gets the value of the users property.
723
     *
724
     * @return
725
     *     possible object is
726
     *     {@link List<User> }
727
     *
728
     */
729 411
	public List<User> getUsers() {
730 412
		return users;
731 413
	}
732

  
733
	/**
734
     * Sets the value of the users property.
735
     *
736
     * @param value
737
     *     allowed object is
738
     *     {@link List<User> }
739
     *
740
     */
741 414
	public void setUsers(List<User> users) {
742 415
		this.users = users;
743 416
	}
417
	public void addUser(User deproxy) {
418
        this.users.add(deproxy);
419
    }
744 420

  
745
	/**
746
     * Gets the value of the groups property.
747
     *
748
     * @return
749
     *     possible object is
750
     *     {@link List<Group> }
751
     *
752
     */
753 421
	public List<Group> getGroups() {
754 422
		return groups;
755 423
	}
756

  
757
	/**
758
     * Sets the value of the groups property.
759
     *
760
     * @param value
761
     *     allowed object is
762
     *     {@link List<Group> }
763
     *
764
     */
765 424
	public void setGroups(List<Group> groups) {
766 425
		this.groups = groups;
767 426
	}
768 427

  
769
	/**
770
     * Gets the value of the grantedAuthorities property.
771
     *
772
     * @return
773
     *     possible object is
774
     *     {@link List<GrantedAuthority> }
775
     *
776
     */
777 428
	public List<GrantedAuthority> getGrantedAuthorities() {
778 429
		return grantedAuthorities;
779 430
	}
780

  
781
	/**
782
     * Sets the value of the grantedAuthorities property.
783
     *
784
     * @param value
785
     *     allowed object is
786
     *     {@link List<GrantedAuthority> }
787
     *
788
     */
789 431
	public void setGrantedAuthorities(List<GrantedAuthority> grantedAuthorities) {
790 432
		this.grantedAuthorities = grantedAuthorities;
791 433
	}
792 434

  
793
	public void addUser(User deproxy) {
794
		this.users.add(deproxy);
795

  
796
	}
797 435
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/jaxb/JaxbExportConfigurator.java
38 38

  
39 39
	private boolean doUsers = true;
40 40
	private boolean doAgentData = true;
41
	private boolean doAuthors = true;
41 42
	private boolean doLanguageData = true;
42 43
	private boolean doFeatureData = true;
43 44
	private boolean doDescriptions = true;
44 45
	private boolean doMedia = true;
45 46
	private boolean doOccurrence = true;
46
//	private boolean doReferences = true;
47
	private DO_REFERENCES doReferences = DO_REFERENCES.ALL;
47 48
	private boolean doReferencedEntities = true;
48 49
//	private boolean doRelationships = true;
49 50
	private boolean doSynonyms = true;
50
//	private boolean doTaxonNames = true;
51
//	private boolean doTaxa = true;
51
	private boolean doTaxonNames = true;
52
	private boolean doTaxa = true;
52 53
	private boolean doTerms = true;
53 54
	private boolean doTermVocabularies = true;
54 55
	private boolean doHomotypicalGroups = true;
......
56 57
	private boolean doTypeDesignations = true;
57 58
	private boolean doClassificationData = true;
58 59

  
60

  
61

  
59 62
	//TODO
60 63
	private static IExportTransformer defaultTransformer = null;
61 64

  
......
67 70
        this.setResultType(ExportResultType.BYTE_ARRAY);
68 71
    }
69 72

  
70
	/* (non-Javadoc)
71
	 * @see eu.etaxonomy.cdm.io.common.IExportConfigurator#getNewState()
72
	 */
73 73
	@Override
74 74
    public JaxbExportState getNewState() {
75 75
		return new JaxbExportState(this);
......
192 192
	}
193 193

  
194 194

  
195
//	@SuppressWarnings("unchecked")
195
	@SuppressWarnings("unchecked")
196 196
	@Override
197 197
    protected void makeIoClassList() {
198 198
		ioClassList = new Class[] {
......
251 251
		this.doOccurrence = doOccurrence;
252 252
	}
253 253

  
254
	private boolean doAuthors = true;
255
	//references
256
	private DO_REFERENCES doReferences = DO_REFERENCES.ALL;
257
	//names
258
	private boolean doTaxonNames = true;
259
	//taxa
260
	private boolean doTaxa = true;
254

  
261 255

  
262 256
	public boolean isDoAuthors() {
263 257
		return doAuthors;
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/jaxb/FeatureTest.java
33 33
	        URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
34 34
	        DataSet dataSet = cdmDocumentBuilder.unmarshal(DataSet.class, new InputStreamReader(this.getClass().getResourceAsStream(resource)),uri.toString());
35 35

  
36
			FeatureTree featureTree = dataSet.getFeatureTrees().get(0);
36
			FeatureTree<Feature> featureTree = dataSet.getFeatureTrees().get(0);
37 37
			Feature feature = (Feature)dataSet.getTerms().get(1);
38 38

  
39
			assertNotNull("FeatureTree must not be null",featureTree);
40
			assertNotNull("Feature must not be null",feature);
39
			assertNotNull("FeatureTree must not be null", featureTree);
40
			assertNotNull("Feature must not be null", feature);
41 41

  
42
			assertNotNull("FeatureTree.root must not be null",featureTree.getRoot());
43
			FeatureNode featureNode = featureTree.getRoot();
44
			assertNotNull("FeatureNode.feature must not be null",featureNode.getTerm());
45
			assertEquals("FeatureNode.feature must equal Feature",feature,featureNode.getTerm());
42
			assertNotNull("FeatureTree.root must not be null", featureTree.getRoot());
43
			FeatureNode<Feature> root = featureTree.getRoot();
44
			assertNotNull("FeatureNode.feature must not be null", root.getTerm());
45
			assertEquals("FeatureNode.feature must equal Feature", feature, root.getTerm());
46 46

  
47
			assertNotNull("FeatureNode.children must not be null",featureNode.getChildNodes());
48
			assertFalse("FeatureNode.children must not be empty",featureNode.getChildNodes().isEmpty());
49
			assertEquals("FeatureNode.children must have 4 child nodes",4,featureNode.getChildNodes().size());
47
			assertNotNull("FeatureNode.children must not be null", root.getChildNodes());
48
			assertFalse("FeatureNode.children must not be empty", root.getChildNodes().isEmpty());
49
			assertEquals("FeatureNode.children must have 4 child nodes", 4, root.getChildNodes().size());
50 50

  
51 51
	    }
52 52
}
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/jaxb/TestCdmSchemaGenerator.java
26 26
		cdmSchemaGenerator.writeSchema();
27 27
	}
28 28

  
29
    /* (non-Javadoc)
30
     * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
31
     */
32 29
    @Override
33
    public void createTestDataSet() throws FileNotFoundException {
34
        // TODO Auto-generated method stub
35
        
36
    }
30
    public void createTestDataSet() throws FileNotFoundException {}
37 31

  
38 32
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/FeatureNode.java
83 83
@Table(name="FeatureNode", indexes = { @Index(name = "featureNodeTreeIndex", columnList = "treeIndex") })
84 84
public class FeatureNode <T extends DefinedTermBase> extends VersionableEntity
85 85
            implements ITreeNode<FeatureNode<T>>, IHasTermType, Cloneable {
86
	private static final Logger logger = Logger.getLogger(FeatureNode.class);
86

  
87
    private static final Logger logger = Logger.getLogger(FeatureNode.class);
87 88

  
88 89
    //This is the main key a node belongs to. Although other keys may also reference
89 90
	//<code>this</code> node, a node usually belongs to a given key.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)