View Javadoc

1   /*
2    * $Id: BasicGeneratedResourceInformation.java,v 1.4 2010/08/10 14:02:30 oeuillot Exp $
3    */
4   package org.rcfaces.core.internal.contentAccessor;
5   
6   import java.util.Iterator;
7   import java.util.Map;
8   
9   import javax.faces.context.FacesContext;
10  
11  import org.apache.commons.logging.Log;
12  import org.apache.commons.logging.LogFactory;
13  import org.rcfaces.core.lang.IContentFamily;
14  
15  /**
16   * 
17   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
18   * @version $Revision: 1.4 $ $Date: 2010/08/10 14:02:30 $
19   */
20  public class BasicGeneratedResourceInformation extends AbstractInformation
21          implements IGeneratedResourceInformation {
22      private static final String REVISION = "$Revision: 1.4 $";
23  
24      private static final Log LOG = LogFactory
25              .getLog(BasicGeneratedResourceInformation.class);
26  
27      private static final String FILTRED_MODEL_PROPERTY = "org.rcfaces.response.FILTRED_MODEL";
28  
29      private static final String PROCESSED_AT_REQUEST_PROPERTY = "org.rcfaces.response.PROCESSED_AT_REQUEST";
30  
31      private IContentFamily contentFamily;
32  
33      public BasicGeneratedResourceInformation() {
34      }
35  
36      public final String getResponseMimeType() {
37          return (String) getAttribute(RESPONSE_MIME_TYPE_PROPERTY);
38      }
39  
40      public final void setResponseMimeType(String contentType) {
41          setAttribute(RESPONSE_MIME_TYPE_PROPERTY, contentType);
42      }
43  
44      public final String getSourceMimeType() {
45          return (String) getAttribute(SOURCE_MIME_TYPE_PROPERTY);
46      }
47  
48      public final void setSourceMimeType(String contentType) {
49          setAttribute(SOURCE_MIME_TYPE_PROPERTY, contentType);
50      }
51  
52      public boolean isFiltredModel() {
53          Boolean val = (Boolean) getAttribute(FILTRED_MODEL_PROPERTY);
54          if (val == null) {
55              return false;
56          }
57  
58          return val.booleanValue();
59      }
60  
61      public void setProcessingAtRequest(boolean processedAtRequest) {
62          setAttribute(PROCESSED_AT_REQUEST_PROPERTY, Boolean
63                  .valueOf(processedAtRequest));
64      }
65  
66      public boolean isProcessingAtRequestSetted() {
67          return getAttribute(PROCESSED_AT_REQUEST_PROPERTY) != null;
68      }
69  
70      public boolean isProcessingAtRequest() {
71          Boolean val = (Boolean) getAttribute(PROCESSED_AT_REQUEST_PROPERTY);
72          if (val == null) {
73              return false;
74          }
75  
76          return val.booleanValue();
77      }
78  
79      public void setFiltredModel(boolean filtredModel) {
80          setAttribute(FILTRED_MODEL_PROPERTY, Boolean.valueOf(filtredModel));
81      }
82  
83      public IContentFamily getContentFamily() {
84          return contentFamily;
85      }
86  
87      public void setContentFamily(IContentFamily contentFamilly) {
88          this.contentFamily = contentFamilly;
89      }
90  
91      public String getResponseSuffix() {
92          return (String) getAttribute(RESPONSE_URL_SUFFIX_PROPERTY);
93      }
94  
95      public void setResponseSuffix(String suffix) {
96          setAttribute(RESPONSE_URL_SUFFIX_PROPERTY, suffix);
97      }
98  
99      public void restoreState(FacesContext context, Object state) {
100         Object states[] = (Object[]) state;
101 
102         super.restoreState(context, states[0]);
103 
104         if (states[1] != null) {
105             contentFamily = ContentFamilies
106                     .getContentFamillyByOrdinal(((Integer) states[1])
107                             .intValue());
108         }
109     }
110 
111     public Object saveState(FacesContext context) {
112         Object states[] = new Object[2];
113 
114         states[0] = super.saveState(context);
115         if (contentFamily != null) {
116             states[1] = new Integer(contentFamily.getOrdinal());
117         }
118 
119         return states;
120     }
121 
122     public void copyTo(IGeneratedResourceInformation generatedInformation) {
123         Map attributes = getAttributes();
124 
125         for (Iterator it = attributes.entrySet().iterator(); it.hasNext();) {
126             Map.Entry entry = (Map.Entry) it.next();
127 
128             generatedInformation.setAttribute((String) entry.getKey(), entry
129                     .getValue());
130         }
131     }
132 
133 }