001package de.deepamehta.core.service; 002 003import de.deepamehta.core.DeepaMehtaObject; 004import de.deepamehta.core.JSONEnabled; 005 006import org.codehaus.jettison.json.JSONObject; 007 008 009 010public class DirectivesResponse implements JSONEnabled { 011 012 // ---------------------------------------------------------------------------------------------- Instance Variables 013 014 private DeepaMehtaObject object; 015 private Directives directives; 016 017 // ---------------------------------------------------------------------------------------------------- Constructors 018 019 public DirectivesResponse() { 020 this.object = null; 021 initDirectives(); 022 } 023 024 public DirectivesResponse(DeepaMehtaObject object) { 025 this.object = object; 026 initDirectives(); 027 } 028 029 // -------------------------------------------------------------------------------------------------- Public Methods 030 031 public DeepaMehtaObject getObject() { 032 return object; 033 } 034 035 public Directives getDirectives() { 036 return directives; 037 } 038 039 // *** JSONEnabled Implementation *** 040 041 @Override 042 public JSONObject toJSON() { 043 try { 044 JSONObject json = object != null ? object.toJSON() : new JSONObject(); 045 json.put("directives", directives.toJSONArray()); 046 return json; 047 } catch (Exception e) { 048 throw new RuntimeException("Serialization failed (" + this + ")", e); 049 } 050 } 051 052 // ------------------------------------------------------------------------------------------------- Private Methods 053 054 private void initDirectives() { 055 directives = Directives.get(); 056 } 057}