Package org.apache.sis.xml

Examples of org.apache.sis.xml.ReferenceResolver


            XLink  link = map.getSpecialized(IdentifierSpace.XLINK);
            UUID   uuid = map.getSpecialized(IdentifierSpace.UUID);
            String anyUUID = (uuid != null) ? uuid.toString() : map.get(IdentifierSpace.UUID);
            if (anyUUID != null || link != null) {
                final Context           context  = Context.current();
                final ReferenceResolver resolver = Context.resolver(context);
                final Class<BoundType>  type     = getBoundType();
                if (uuid == null) {
                    uuid = ObjectReference.toUUID(context, anyUUID); // May still null.
                }
                /*
                 * Check if the user gives us the permission to use reference to those identifiers.
                 * If not, forget them. Information will actually not be lost, since the same identifiers
                 * will be provided by private methods in ISOMetadata. If we do nott clear the identifiers
                 * here, they would appear twice in the XML output.
                 */
                if (uuid != null && !resolver.canSubstituteByReference(context, type, metadata, uuid)) {
                    uuid = null;
                }
                if (link != null && !resolver.canSubstituteByReference(context, type, metadata, link)) {
                    link = null;
                }
                if (uuid != null || link != null) {
                    reference = new ObjectReference(uuid, anyUUID, link);
                }
View Full Code Here


    final <T> T resolve(final Context context, final Class<T> type, T metadata) throws IllegalArgumentException {
        if (uuid == null) {
            uuid = toUUID(context, anyUUID);
        }
        if (metadata == null) {
            final ReferenceResolver resolver = Context.resolver(context);
            if ((uuid  == null || (metadata = resolver.resolve(context, type, uuid )) == null) &&
                (xlink == null || (metadata = resolver.resolve(context, type, xlink)) == null))
            {
                // Failed to find an existing metadata instance.
                // Creates an empty instance with the identifiers.
                int count = 0;
                SpecializedIdentifier<?>[] identifiers  = new SpecializedIdentifier<?>[2];
                if (uuid  != null) identifiers[count++] = new SpecializedIdentifier<UUID> (IdentifierSpace.UUID,  uuid);
                if (xlink != null) identifiers[count++] = new SpecializedIdentifier<XLink>(IdentifierSpace.XLINK, xlink);
                identifiers = ArraysExt.resize(identifiers, count);
                metadata = resolver.newIdentifiedObject(context, type, identifiers);
            }
        } else {
            // In principle, the XML should contain a full metadata object OR a uuidref attribute.
            // However if both are present, assign the identifiers to that instance.
            if (metadata instanceof IdentifiedObject) {
View Full Code Here

     * @param  context The current context, or {@code null} if none.
     * @return The current reference resolver (never null).
     */
    public static ReferenceResolver resolver(final Context context) {
        if (context != null) {
            final ReferenceResolver resolver = context.resolver;
            if (resolver != null) {
                return resolver;
            }
        }
        return ReferenceResolver.DEFAULT;
View Full Code Here

            final IdentifierMap map = ((IdentifiedObject) value).getIdentifierMap();
            XLink  link = map.getSpecialized(IdentifierSpace.XLINK);
            UUID   uuid = map.getSpecialized(IdentifierSpace.UUID);
            if (uuid != null || link != null) {
                final Context           context  = Context.current();
                final ReferenceResolver resolver = Context.resolver(context);
                final Class<BoundType>  type     = getBoundType();
                /*
                 * Check if the user gives us the permission to use reference to those identifiers.
                 * If not, forget them in order to avoid marshalling the identifiers twice (see the
                 * example in the above comment).
                 */
                if (uuid != null) {
                    if (resolver.canSubstituteByReference(context, type, value, uuid)) {
                        metadata = null;
                    } else {
                        uuid = null;
                    }
                }
                /*
                 * There is no risk of duplication for 'xlink' because there is no such attribute in ISOMetadata.
                 * So if the user does not allow us to omit the metadata object, we will still keep the xlink for
                 * informative purpose.
                 */
                if (link != null && resolver.canSubstituteByReference(context, type, value, link)) {
                    metadata = null;
                }
                if (uuid != null || link != null) {
                    reference = new ObjectReference(uuid, link);
                }
View Full Code Here

     * @param  metadata  The metadata object, or {@code null}.
     * @return A metadata object for the identifiers, or {@code null}
     */
    final <T> T resolve(final Context context, final Class<T> type, T metadata) {
        if (metadata == null) {
            final ReferenceResolver resolver = Context.resolver(context);
            if ((uuid  == null || (metadata = resolver.resolve(context, type, uuid )) == null) &&
                (xlink == null || (metadata = resolver.resolve(context, type, xlink)) == null))
            {
                // Failed to find an existing metadata instance.
                // Creates an empty instance with the identifiers.
                int count = 0;
                SpecializedIdentifier<?>[] identifiers  = new SpecializedIdentifier<?>[2];
                if (uuid  != null) identifiers[count++] = new SpecializedIdentifier<UUID> (IdentifierSpace.UUID,  uuid);
                if (xlink != null) identifiers[count++] = new SpecializedIdentifier<XLink>(IdentifierSpace.XLINK, xlink);
                identifiers = ArraysExt.resize(identifiers, count);
                metadata = resolver.newIdentifiedObject(context, type, identifiers);
            }
        } else {
            // In principle, the XML should contain a full metadata object OR a uuidref attribute.
            // However if both are present, assign the identifiers to that instance.
            if (metadata instanceof IdentifiedObject) {
View Full Code Here

     * @param  context The current context, or {@code null} if none.
     * @return The current reference resolver (never null).
     */
    public static ReferenceResolver resolver(final Context context) {
        if (context != null) {
            final ReferenceResolver resolver = context.resolver;
            if (resolver != null) {
                return resolver;
            }
        }
        return ReferenceResolver.DEFAULT;
View Full Code Here

TOP

Related Classes of org.apache.sis.xml.ReferenceResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.