Class Tools


  • public class Tools
    extends java.lang.Object
    Some utilities, such as for parameter checking. Public for testing.
    Author:
    Holger Eichelberger, SSE
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<de.iip_ecosphere.platform.support.aas.AssetKind,​org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind> ASSETKINDS2BASYX  
      private static java.util.Map<org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind,​de.iip_ecosphere.platform.support.aas.AssetKind> BASYX2ASSETKINDS  
      private static java.util.Map<org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType,​de.iip_ecosphere.platform.support.aas.Type> BASYX2TYPES  
      private static java.util.Map<de.iip_ecosphere.platform.support.aas.Type,​org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType> TYPES2BASYX  
    • Constructor Summary

      Constructors 
      Constructor Description
      Tools()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String checkId​(java.lang.String idShort)
      Checks a given short id for not being empty.
      static java.lang.String checkUrn​(java.lang.String urn)
      Checks a given URN for not being empty.
      private static java.lang.String compose​(java.lang.String prefix, java.lang.String value, boolean stripPrefix)
      Composes a prefix and a value if desired.
      (package private) static void disposeTomcatWorkingDir​(java.io.File baseDir, int port)
      Tries to dispose a Tomcat working directory.
      static <E extends java.lang.Enum<E>>
      E
      getOption​(java.lang.String[] options, E dflt, java.lang.Class<E> cls)
      Tests the values in pptions against the constants in cls and returns a matching constant or dflt.
      static org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType getType​(org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElement elt)
      Returns the value type of a submodel element.
      (package private) static java.lang.String idToUrlPath​(java.lang.String id)
      Turns an id into a URL path.
      private static void mapKind​(de.iip_ecosphere.platform.support.aas.AssetKind kind, org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind basyxKind)
      Maps an implementation-independent asset kind into a BaSyx asset kind.
      private static void mapType​(de.iip_ecosphere.platform.support.aas.Type type, org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType basyxType)
      Maps an implementation-independent type into a BaSyx property-value type.
      static org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind translate​(de.iip_ecosphere.platform.support.aas.AssetKind kind)
      Translates a implementation-independent asset kind to an implementation-specific asset kind.
      static org.eclipse.basyx.submodel.metamodel.map.qualifier.LangString translate​(de.iip_ecosphere.platform.support.aas.LangString ls)
      Translates an AAS to a BaSyx lang string.
      static org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType translate​(de.iip_ecosphere.platform.support.aas.Type type)
      Translates a implementation-independent type to an implementation-specific type.
      static de.iip_ecosphere.platform.support.aas.AssetKind translate​(org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind kind)
      Translates a implementation-specific asset kind to an implementation-independent asset kind.
      static de.iip_ecosphere.platform.support.aas.LangString translate​(org.eclipse.basyx.submodel.metamodel.map.qualifier.LangString ls)
      Translates BaSyx lang string to an AAS lang string.
      static de.iip_ecosphere.platform.support.aas.Type translate​(org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType type)
      Translates a implementation-specific type to an implementation-independent type.
      static org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier translateIdentifier​(java.lang.String id, java.lang.String dfltCustom)
      Translates an identifier.
      static java.lang.String translateIdentifier​(org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier identifier)
      Translates an identifier back into its string notation.
      static org.eclipse.basyx.submodel.metamodel.api.reference.IReference translateReference​(java.lang.String id)
      Translates a reference.
      static java.lang.String translateReference​(org.eclipse.basyx.submodel.metamodel.api.reference.IReference ref, boolean stripPrefix)
      Translates a reference back to its string format.
      static java.lang.Object translateValueFromBaSyx​(java.lang.Object val, org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType type)
      Translates a BaSyx value back.
      static java.lang.Object translateValueToBaSyx​(org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType type, java.lang.Object value)
      Translates a value for a given target type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TYPES2BASYX

        private static final java.util.Map<de.iip_ecosphere.platform.support.aas.Type,​org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType> TYPES2BASYX
      • BASYX2TYPES

        private static final java.util.Map<org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType,​de.iip_ecosphere.platform.support.aas.Type> BASYX2TYPES
      • ASSETKINDS2BASYX

        private static final java.util.Map<de.iip_ecosphere.platform.support.aas.AssetKind,​org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind> ASSETKINDS2BASYX
      • BASYX2ASSETKINDS

        private static final java.util.Map<org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind,​de.iip_ecosphere.platform.support.aas.AssetKind> BASYX2ASSETKINDS
    • Constructor Detail

      • Tools

        public Tools()
    • Method Detail

      • mapType

        private static void mapType​(de.iip_ecosphere.platform.support.aas.Type type,
                                    org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType basyxType)
        Maps an implementation-independent type into a BaSyx property-value type.
        Parameters:
        type - the implementation-independent type
        basyxType - the corresponding BaSyx property-value type
      • mapKind

        private static void mapKind​(de.iip_ecosphere.platform.support.aas.AssetKind kind,
                                    org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind basyxKind)
        Maps an implementation-independent asset kind into a BaSyx asset kind.
        Parameters:
        kind - the implementation-independent asset kind
        basyxKind - the corresponding BaSyx asset kind
      • checkUrn

        public static java.lang.String checkUrn​(java.lang.String urn)
        Checks a given URN for not being empty.
        Parameters:
        urn - the URN
        Returns:
        urn
        Throws:
        java.lang.IllegalArgumentException - if the urn is empty or null
      • checkId

        public static java.lang.String checkId​(java.lang.String idShort)
        Checks a given short id for not being empty.
        Parameters:
        idShort - the short id
        Returns:
        idShort
        Throws:
        java.lang.IllegalArgumentException - if the id is empty or null
      • translate

        public static org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType translate​(de.iip_ecosphere.platform.support.aas.Type type)
        Translates a implementation-independent type to an implementation-specific type.
        Parameters:
        type - the implementation-independent type
        Returns:
        the implementation-specific type
      • translate

        public static de.iip_ecosphere.platform.support.aas.Type translate​(org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType type)
        Translates a implementation-specific type to an implementation-independent type.
        Parameters:
        type - the implementation-specific type
        Returns:
        the implementation-independent type
      • translate

        public static org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind translate​(de.iip_ecosphere.platform.support.aas.AssetKind kind)
        Translates a implementation-independent asset kind to an implementation-specific asset kind.
        Parameters:
        kind - the implementation-independent asset kind
        Returns:
        the implementation-specific asset kind
      • translate

        public static de.iip_ecosphere.platform.support.aas.AssetKind translate​(org.eclipse.basyx.aas.metamodel.api.parts.asset.AssetKind kind)
        Translates a implementation-specific asset kind to an implementation-independent asset kind.
        Parameters:
        kind - the implementation-specific asset kind
        Returns:
        the implementation-independent asset kind
      • idToUrlPath

        static java.lang.String idToUrlPath​(java.lang.String id)
        Turns an id into a URL path.
        Parameters:
        id - the id
        Returns:
        the URL path
      • translateIdentifier

        public static org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier translateIdentifier​(java.lang.String id,
                                                                                                          java.lang.String dfltCustom)
        Translates an identifier. (supports URN and custom ids)
        Parameters:
        id - the id showing some form of type, e.g., prefix "urn:", may be empty or null leading to a custom identifier based on dfltCustom
        dfltCustom - the default value if id cannot be used
        Returns:
        the identifier
      • translateIdentifier

        public static java.lang.String translateIdentifier​(org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier identifier)
        Translates an identifier back into its string notation.
        Parameters:
        identifier - the identifier (may be null, result is also null then)
        Returns:
        the string notation
      • translateReference

        public static org.eclipse.basyx.submodel.metamodel.api.reference.IReference translateReference​(java.lang.String id)
        Translates a reference. (supports IRDI, IRI)
        Parameters:
        id - the for declaring the reference showing some form of type, e.g., prefix "irdi:", may be empty or null leading to null, see IdentifierType
        Returns:
        the reference or null
      • translateReference

        public static java.lang.String translateReference​(org.eclipse.basyx.submodel.metamodel.api.reference.IReference ref,
                                                          boolean stripPrefix)
        Translates a reference back to its string format. (supports IRDI, IRI)
        Parameters:
        ref - the reference to translate back
        stripPrefix - whether the prefix shall be included
        Returns:
        the translated reference or null if ref was null or it cannot be translated
      • compose

        private static java.lang.String compose​(java.lang.String prefix,
                                                java.lang.String value,
                                                boolean stripPrefix)
        Composes a prefix and a value if desired.
        Parameters:
        prefix - the prefix
        value - the value
        stripPrefix - whether the prefix shall be included
        Returns:
        value or prefix + value
      • getOption

        public static <E extends java.lang.Enum<E>> E getOption​(java.lang.String[] options,
                                                                E dflt,
                                                                java.lang.Class<E> cls)
        Tests the values in pptions against the constants in cls and returns a matching constant or dflt.
        Type Parameters:
        E - the enum type
        Parameters:
        options - the options to check
        dflt - the default value
        cls - the enum class providing the constants
        Returns:
        the matching option or dflt
      • disposeTomcatWorkingDir

        static void disposeTomcatWorkingDir​(java.io.File baseDir,
                                            int port)
        Tries to dispose a Tomcat working directory.
        Parameters:
        baseDir - the basic directory where the working directory is located in, may be null for default, i.e., program home directory
        port - the port number of the disposed Tomcat instance
      • translate

        public static org.eclipse.basyx.submodel.metamodel.map.qualifier.LangString translate​(de.iip_ecosphere.platform.support.aas.LangString ls)
        Translates an AAS to a BaSyx lang string.
        Parameters:
        ls - the AAS lang string
        Returns:
        the BaSyx lang string
      • translate

        public static de.iip_ecosphere.platform.support.aas.LangString translate​(org.eclipse.basyx.submodel.metamodel.map.qualifier.LangString ls)
        Translates BaSyx lang string to an AAS lang string.
        Parameters:
        ls - the BaSyx lang string
        Returns:
        the AAS lang string
      • translateValueToBaSyx

        public static java.lang.Object translateValueToBaSyx​(org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType type,
                                                             java.lang.Object value)
        Translates a value for a given target type.
        Parameters:
        type - the BaSyx type
        value - the value to translate
        Returns:
        the translated value
      • translateValueFromBaSyx

        public static java.lang.Object translateValueFromBaSyx​(java.lang.Object val,
                                                               org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType type)
        Translates a BaSyx value back.
        Parameters:
        val - the value to be translated
        type - the expected target type to support the translation, may be null
        Returns:
        the translated value
      • getType

        public static org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.valuetype.ValueType getType​(org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElement elt)
        Returns the value type of a submodel element.
        Parameters:
        elt - the element
        Returns:
        the value type or null if not available