MICO Platform
 All Classes Namespaces Functions Variables Friends
AssetAnno4cpp.hpp
1 #ifndef ASSETANNO4CPP_HPP
2 #define ASSETANNO4CPP_HPP 1
3 
4 #include "Asset.hpp"
5 #include "PersistenceService.hpp"
6 #include "URLStream.hpp"
7 #include "Logging.hpp"
8 
9 namespace mico {
10  namespace persistence {
11  namespace model {
12 
13  class AssetAnno4cpp: public Asset
14  {
15  private:
16  PersistenceService& m_persistenceService;
17  jnipp::GlobalRef<jnipp::eu::mico::platform::anno4j::model::AssetMMM> m_assetMMM;
18 
19  std::string m_jnippErrorMessage;
20 
21  public:
22  AssetAnno4cpp(jnipp::Ref<jnipp::eu::mico::platform::anno4j::model::AssetMMM> assetMMM, PersistenceService& persistenceService)
23  : m_persistenceService(persistenceService),
24  m_assetMMM(assetMMM)
25  {}
26 
28  jnipp::Env::Scope scope(PersistenceService::m_sJvm);
29 
30  jnipp::LocalRef<jnipp::org::openrdf::model::impl::URIImpl> juri =
31  jnipp::org::openrdf::model::impl::URIImpl::construct( m_assetMMM->getLocation() );
32 
33  return mico::persistence::model::URI( juri->stringValue()->std_str() );
34  }
35 
37  jnipp::Env::Scope scope(PersistenceService::m_sJvm);
38 
39  jnipp::LocalRef<jnipp::org::openrdf::model::URI> jAssetURI =
40  ((jnipp::Ref<jnipp::org::openrdf::repository::object::RDFObject>)m_assetMMM)->getResource();
41 
42  m_persistenceService.checkJavaExceptionNoThrow(m_jnippErrorMessage);
43  assert((jobject)jAssetURI);
44 
45  return mico::persistence::model::URI(jAssetURI->toString()->std_str());
46  }
47 
48  std::string getFormat() {
49  jnipp::Env::Scope scope(PersistenceService::m_sJvm);
50  return m_assetMMM->getFormat()->std_str();
51  }
52 
53  void setFormat(std::string format) {
54  jnipp::Env::Scope scope(PersistenceService::m_sJvm);
55  jnipp::LocalRef<JavaLangString> jformat = JavaLangString::create(format);
56  m_assetMMM->setFormat(jformat);
57  }
58 
59  std::ostream* getOutputStream() {
60  jnipp::Env::Scope scope(PersistenceService::m_sJvm);
61  LOG_DEBUG("new output stream connection to %s.bin", this->getLocation().stringValue().c_str());
62  return new mico::io::url_ostream( m_persistenceService.unmaskContentLocation(this->getLocation().stringValue()) + ".bin");
63  }
64 
65  std::istream* getInputStream() {
66  jnipp::Env::Scope scope(PersistenceService::m_sJvm);
67  LOG_DEBUG("new input stream connection to %s.bin", this->getLocation().stringValue().c_str());
68  return new mico::io::url_istream( m_persistenceService.unmaskContentLocation(this->getLocation().stringValue()) + ".bin");
69  }
70  };
71  }
72  }
73 }
74 #endif
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
Definition: http_client.cpp:23
mico::persistence::model::URI getURI()
getURI Retrieves the unique identifcation URI for this asset
Definition: AssetAnno4cpp.hpp:36
Main service for accessing the MICO persistence API.
Definition: PersistenceService.hpp:51
Definition: Asset.hpp:14
Definition: AssetAnno4cpp.hpp:13
Main type for opening an output stream to an URL for writing.
Definition: URLStream.hpp:67
std::ostream * getOutputStream()
Return a new output stream for writing to the content.
Definition: AssetAnno4cpp.hpp:59
mico::persistence::model::URI getLocation()
getLocation Retrieves the storage location of this asset (should be suffixed by .bin) ...
Definition: AssetAnno4cpp.hpp:27
std::istream * getInputStream()
Return a new input stream for reading the content.
Definition: AssetAnno4cpp.hpp:65
A URI.
Definition: Uri.hpp:22
Main type for opening an input stream to an URL for reading.
Definition: URLStream.hpp:82