/*
 * Copyright (C) 2015 Kalin Maldzhanski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.djodjo.json.jsonld.api;


import org.djodjo.json.JsonObject;

import java.net.URI;
import java.util.Map;

public class JsonLdContext {

    private JsonLdOptions options;
    private JsonObject ctx;
    private JsonObject termDefinitions;
    public JsonObject inverse = null;


    public JsonLdContext() {
        this(new JsonLdOptions());
    }

    public JsonLdContext(JsonLdOptions opts) {
        init(opts);
    }

    public JsonLdContext(Map<String, Object> map, JsonLdOptions opts) {
        ctx = new JsonObject(map);
        init(opts);
    }

    public JsonLdContext(Map<String, Object> map) {
        this(map, new JsonLdOptions());
    }

    public JsonLdContext(URI context, JsonLdOptions opts) {
        throw new RuntimeException("TODO");
        //init(opts);
    }

    private void init(JsonLdOptions options) {
        if(ctx==null) {
            ctx = new JsonObject();
        }
        this.options = options;
        if (options.getBase() != null) {
            ctx.put("@base", options.getBase());
        }
        this.termDefinitions = new JsonObject();
    }

}

@@ -672,16 +672,93 @@
 nObject;
+%0Aimport org.djodjo.json.JsonString;%0Aimport org.djodjo.json.jsonld.JsonLdWrap;
 %0A%0Aimport
@@ -868,31 +868,116 @@
     
-private JsonObject ctx;
+//context json object containing json-ld known terms%0A    private JsonLdWrap ctx;%0A    //only term definitions
 %0A   
@@ -1280,32 +1280,47 @@
       ctx = new 
+JsonLdWrap(new 
 JsonObject(map);
@@ -1318,16 +1318,17 @@
 ect(map)
+)
 ;%0A      
@@ -1660,32 +1660,33 @@
            ctx =
+ 
  new JsonObject(
@@ -1670,38 +1670,38 @@
  ctx =  new Json
-Object
+LdWrap
 ();%0A        %7D%0A  
@@ -1791,21 +1791,31 @@
 ctx.
-put(%22@base%22, 
+setBase(new JsonString(
 opti
@@ -1828,16 +1828,17 @@
 tBase())
+)
 ;%0A      
@@ -1852,46 +1852,121 @@
     
- this.termDefinitions = new JsonObject
+%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return ctx.getJson().merge(termDefinitions).toString
 ();%0A
@@ -1971,11 +1971,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

work on ctx