You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sis.apache.org by Cullen Rombach <cu...@imagemattersllc.com> on 2017/06/01 19:22:36 UTC

How to Extend Codelist

Hello,

I am currently working on implementing a new profile of ISO metadata using
Apache SIS, and I need to extend two codelists to have new values. More
specifically, I need to add new codes to OnLineFunction (CI_OnLineFunctionCode)
and ScopeCode (MD_ScopeCode). I'd also like my new classes to use a
different codelist URL.

For example, a CI_OnLineFunctionCode currently looks like this:

<gmd:CI_OnLineFunctionCode codeList="
http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_OnLineFunctionCode"
codeListValue="download"
codeSpace="eng">Download</gmd:CI_OnLineFunctionCode>

I want mine to look like this (assuming I am now working with a different
code "newValue"):

<gmd:CI_OnLineFunctionCode codeList="
http://www.example.com/codelist.xml#CI_OnLineFunctionCode"
codeListValue="newValue"
codeSpace="eng">newValue</gmd:CI_OnLineFunctionCode>

Since both the codelists I want to extend are final, I'm not sure what the
proper way to add new codes is. I also can't find where the codelist URL is
injected, but I need to override that behavior.

Thank you,
Cullen Rombach

-- 
Cullen Rombach
Image Matters LLC
www.imagemattersllc.com

Re: How to Extend Codelist

Posted by Cullen Rombach <cu...@imagemattersllc.com>.
Martin,

That should do the trick. Thank you for your help. It is much appreciated.

Regards,
Cullen

On Fri, Jun 2, 2017 at 1:36 PM, Martin Desruisseaux <
martin.desruisseaux@geomatys.com> wrote:

> Hello Cullen
>
> Completing my yesterday email with the second question:
>
> Le 01/06/2017 à 21:22, Cullen Rombach a écrit :
>
> > I also can't find where the codelist URL is injected, but I need to
> > override that behavior.
> >
> There is not yet a public API for that, but it is possible to use the
> internal API in the meantime. Everything in "org.apache.sis.internal" is
> undocumented and may change in any future version, but this part has not
> changed for years.
>
> First, the new CodeList type will need a new JAXB adapter. It can be
> done be copying the
> org.apache.sis.internal.jaxb.code.CI_OnLineFunctionCode class (for
> instance) and rename all "OnLineFunction" part by the name of the new
> CodeList.
>
> Next, we can cheat by modifying the 'getElement()' method in the new
> adapter, like below:
>
>     @Override
>     @XmlElement(name = "MyCodeListType")
>     public CodeListUID getElement() {
>         identifier.codeList = "http://myURL#myCodeList";
>         return identifier;
>     }
>
> This will work only for new code list types. If a different URL is
> desired for new code list *elements* in an existing type (like adding
> new OnlineFunctionCode), then we will need a better mechanism. In any
> case we need a better approach than the above; we just didn't had a
> though yet about what could be the public API for the purpose of
> injecting different URLs for different code lists.
>
>     Martin
>
>
>


-- 
Cullen Rombach
Image Matters LLC
www.imagemattersllc.com

Re: How to Extend Codelist

Posted by Martin Desruisseaux <ma...@geomatys.com>.
Hello Cullen

Completing my yesterday email with the second question:

Le 01/06/2017 à 21:22, Cullen Rombach a écrit :

> I also can't find where the codelist URL is injected, but I need to
> override that behavior.
>
There is not yet a public API for that, but it is possible to use the
internal API in the meantime. Everything in "org.apache.sis.internal" is
undocumented and may change in any future version, but this part has not
changed for years.

First, the new CodeList type will need a new JAXB adapter. It can be
done be copying the
org.apache.sis.internal.jaxb.code.CI_OnLineFunctionCode class (for
instance) and rename all "OnLineFunction" part by the name of the new
CodeList.

Next, we can cheat by modifying the 'getElement()' method in the new
adapter, like below:

    @Override
    @XmlElement(name = "MyCodeListType")
    public CodeListUID getElement() {
        identifier.codeList = "http://myURL#myCodeList";
        return identifier;
    }

This will work only for new code list types. If a different URL is
desired for new code list *elements* in an existing type (like adding
new OnlineFunctionCode), then we will need a better mechanism. In any
case we need a better approach than the above; we just didn't had a
though yet about what could be the public API for the purpose of
injecting different URLs for different code lists.

    Martin



Re: How to Extend Codelist

Posted by Martin Desruisseaux <ma...@geomatys.com>.
Hello Cullen

Welcome!

Le 01/06/2017 à 21:22, Cullen Rombach a écrit :

> I am currently working on implementing a new profile of ISO metadata
> using Apache SIS, and I need to extend two codelists to have new
> values. More specifically, I need to add new codes to OnLineFunction
> (CI_OnLineFunctionCode) and ScopeCode (MD_ScopeCode).
>
Just invoking something like the following should work (you do not need
to create a subclass):

    public static final OnlineFunction MY_NEW_CODE =
    OnlineFunction.valueOf("myNewCode");

Contrarily to Enum.valueOf(String), invoking CodeList.valueOf(String)
does not throw an exception; it creates the new code instead. This is
the main difference between CodeList and Enum.


> I'd also like my new classes to use a different codelist URL.
>
I would suggest to copy and paste an existing CodeList, for example [1],
rename it and replace all fields by the new fields for that code list.
But for injecting a different URL at XML marshalling time, I need to
check first and will send another email after.

    Regards,

        Martin

[1] https://github.com/opengeospatial/geoapi/blob/master/geoapi/src/main/java/org/opengis/metadata/citation/OnLineFunction.java