label :: NetworkObject -> NMLReader (Maybe Label)
label n = case n of
            (Single Link _)                 -> q n
            (Single Port _)                 -> q n
            _                               -> return Nothing
    where
        q n = runMaybeT $
                labelGuid n >>= \guid ->
                labelType guid  >>= \type' ->
                labelValue guid >>= \value ->
                maybeZero $ Just $ Label $ (guid, type', value)

        labelGuid :: NetworkObject -> MaybeT NMLReader GUID
        labelGuid n = MaybeT $ liftM listToMaybe $ baseQueryWrap (id,toRDF,id)
            (return . unpackUNode) Object (Just $ toRDF n) (Just "nml:hasLabel" :: Maybe Text) Nothing

        labelType :: GUID -> MaybeT NMLReader LabelType
        labelType = MaybeT . queryAttrib "nml:type" id

        labelValue :: GUID -> MaybeT NMLReader LabelValue
        labelValue = MaybeT . queryAttrib "nml:value" id

-- | utility function to simplify attribute queries
label :: NetworkObject -> NMLReader (Maybe Label)
label n = case n of
            (Single Link _)                 -> q n
            (Single Port _)                 -> q n
            _                               -> return Nothing
    where
        q n = runMaybeT $
                labelGuid n >>= \guid ->
                labelType guid  >>= \type' ->
                labelValue guid >>= \value ->
                maybeZero $ Just $ Label $ (guid, type', value)

        labelGuid :: NetworkObject -> MaybeT NMLReader GUID
        labelGuid n = MaybeT $ liftM listToMaybe $ baseQueryWrap (id,toRDF,id)
            (return . unpackUNode) Object (Just $ toRDF n) (Just "nml:hasLabel" :: Maybe Text) Nothing

        labelType :: GUID -> MaybeT NMLReader LabelType
        labelType = MaybeT . queryAttrib "nml:type" id

        labelValue :: GUID -> MaybeT NMLReader LabelValue
        labelValue = MaybeT . queryAttrib "nml:value" id

-- | utility function to simplify attribute queries
label n = case n of
            (Single Link _)                 -> q n
            (Single Port _)                 -> q n
            _                               -> return Nothing
    where
        q n = runMaybeT $
                labelGuid n >>= \guid ->
                labelType guid  >>= \type' ->
                labelValue guid >>= \value ->
                maybeZero $ Just $ Label $ (guid, type', value)

        labelGuid :: NetworkObject -> MaybeT NMLReader GUID
        labelGuid n = MaybeT $ liftM listToMaybe $ baseQueryWrap (id,toRDF,id)
            (return . unpackUNode) Object (Just $ toRDF n) (Just "nml:hasLabel" :: Maybe Text) Nothing

        labelType :: GUID -> MaybeT NMLReader LabelType
        labelType = MaybeT . queryAttrib "nml:type" id

        labelValue :: GUID -> MaybeT NMLReader LabelValue
        labelValue = MaybeT . queryAttrib "nml:value" id

-- | utility function to simplify attribute queries