/***
 * Copyright (c) 2009 Caelum - www.caelum.com.br/opensource All rights reserved.
 *
 * 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 br.com.caelum.vraptor.serialization;

import java.util.ResourceBundle;

import javax.enterprise.context.RequestScoped;

import br.com.caelum.vraptor.View;
import br.com.caelum.vraptor.ioc.Container;
import br.com.caelum.vraptor.validator.I18nMessage;

/**
 * Basic i18n messsage json serialization alias.
 *
 * @author Leonardo Wolter
 * @since 3.5
 */
@RequestScoped
public class I18nMessageSerialization implements View {

	private final Container container;
	private final ResourceBundle bundle;
	private I18nMessage i18nMessage;

	/** 
	 * @deprecated CDI eyes only
	 */
	protected I18nMessageSerialization() {
		this(null, null);
	}

	public I18nMessageSerialization(Container container, ResourceBundle bundle) {
		this.container = container;
		this.bundle = bundle;
	}

	public I18nMessageSerialization from(String category, String key, Object...params) {
		i18nMessage = new I18nMessage(category, key, params);
		i18nMessage.setBundle(bundle);
		return this;
	}

	public void as(Class<? extends Serialization> method){
		Serialization serialization = container.instanceFor(method);
		serialization.from(i18nMessage, "message").serialize();
	}
}

@@ -77,24 +77,29 @@
 reserved.%0A *
+ %3Cp/%3E
 %0A * Licensed
@@ -267,16 +267,21 @@
 se at%0A *
+ %3Cp/%3E
 %0A * http
@@ -321,16 +321,21 @@
 E-2.0%0A *
+ %3Cp/%3E
 %0A * Unle
@@ -703,90 +703,8 @@
 n;%0A%0A
-import java.util.ResourceBundle;%0A%0Aimport javax.enterprise.context.RequestScoped;%0A%0A
 impo
@@ -831,16 +831,125 @@
 ssage;%0A%0A
+import javax.enterprise.context.RequestScoped;%0Aimport javax.inject.Inject;%0Aimport java.util.ResourceBundle;%0A%0A
 /**%0A * B
@@ -1113,17 +1113,20 @@
 View %7B%0A%0A
-%09
+    
 private 
@@ -1152,17 +1152,20 @@
 tainer;%0A
-%09
+    
 private 
@@ -1193,17 +1193,20 @@
 bundle;%0A
-%09
+    
 private 
@@ -1235,15 +1235,20 @@
 e;%0A%0A
-%09/** %0A%09
+    /**%0A    
  * @
@@ -1276,14 +1276,20 @@
 nly%0A
-%09 */%0A%09
+     */%0A    
 prot
@@ -1319,26 +1319,32 @@
 ization() %7B%0A
-%09%09
+        
 this(null, n
@@ -1349,21 +1349,39 @@
  null);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    @Inject%0A    
 public I
@@ -1450,18 +1450,24 @@
 ndle) %7B%0A
-%09%09
+        
 this.con
@@ -1486,18 +1486,24 @@
 tainer;%0A
-%09%09
+        
 this.bun
@@ -1516,21 +1516,27 @@
 bundle;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 public I
@@ -1602,16 +1602,17 @@
 bject...
+ 
 params) 
@@ -1613,18 +1613,24 @@
 rams) %7B%0A
-%09%09
+        
 i18nMess
@@ -1675,18 +1675,24 @@
 arams);%0A
-%09%09
+        
 i18nMess
@@ -1714,18 +1714,24 @@
 undle);%0A
-%09%09
+        
 return t
@@ -1739,13 +1739,19 @@
 is;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 publ
@@ -1803,12 +1803,19 @@
 hod)
+ 
 %7B%0A
-%09%09
+        
 Seri
@@ -1875,10 +1875,16 @@
 d);%0A
-%09%09
+        
 seri
@@ -1939,9 +1939,12 @@
 ();%0A
-%09
+    
 %7D%0A%7D%0A

add missing inject