The MetaData interfaces can be used as straight up Java Beans, with properties and so on.
Simple Properties:
public void referenceDocument( Citation citation ) { System.out.println( citation.getTitle() ); System.out.println( citation.getTitle().toString( Locale.FRENCH) ); }
Collections:
System.out.println( citation.getIdentifiers() ); System.out.println( citation.getAlternateTitles() );
Fun.
Predefined Metadata
The GeoTools library provides predefined constants for the usual suspects, using Citation as an example the usual suspects are among others:
- EPSG
- OGC
- Oracle
All of these organizations have published documentation, or specifications, that you may wish to offer as a citation when describing your own information.
The Citations class rounds up these constants, and a few more, for you to reuse:
referenceDocument( Citations.EPSG ); referenceDocument( Citations.OGC ); referenceDocument( Citations.ORACLE );
These constants however are "frozen" and may not be changed.
Custom Metadata
Create
Create is easy:
CitationImpl citation = new CitationImpl();
No surprises here, a no argument constructor exists, just a regular Java Bean. Some other constructors accept an argument but they are just convenience.
Configure
You can set up using the bean properties using set methods:
citation.setEditionDate( new Date() ); // today
And sometimes a bit of a chore (reading javadocs to see what is needed):
Collection parties = Collections.singleton( ResponsiblePartyImpl.GEOTOOLS ); citation.setCitedResponsibleParties( parties );
The above method set the whole collection, discarting any previous collection for the "cited responsible parties" property. The code below is an alternative that add a responsible party without discarting the previous ones:
citation.getCitedResponsibleParties().add( ResponsiblePartyImpl.GEOTOOLS );
Freeze
The Freeze step "throws a switch" and keeps the object from having any further changes applied.
Citation f = (Citation) c.unmodifiable();
Note that the original code c citation stay modifiable; only the returned one is unmodifiable.
The GeoAPI interfaces are not really set up to be mutable, that is once created a lot of code expects them to never change. Hense the freeze step, it works better then the honour system.