View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.serializer.objects;
18  
19  import javolution.xml.XMLFormat;
20  import javolution.xml.stream.XMLStreamException;
21  
22  import org.apache.commons.lang.StringEscapeUtils;
23  
24  /***
25   * Import ProfilingRule
26   * 
27   *   <profilingRule name = j2>
28   *       <description>whatever</description>
29   *       <className>org.apache.jetspeed.profile.RuleImpl</className>
30   *       <criteria>
31   *          ...
32   *       </criteria>
33   *   </profilingRule>
34   *   
35   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
36   * @version $Id: $
37   */
38  public class JSProfilingRule
39  {
40      private String id;
41      private boolean standardRule;
42      private String description;
43      JSRuleCriterions criterions = new JSRuleCriterions();
44      
45      
46      public JSProfilingRule()
47      {        
48      }
49  
50      
51      public boolean isStandardRule()
52      {
53          return standardRule;
54      }
55  
56      
57      public void setStandardRule(boolean standard)
58      {
59          this.standardRule = standard;
60      }
61  
62      
63      public String getDescription()
64      {
65          return description;
66      }
67  
68      
69      public void setDescription(String description)
70      {
71          this.description = description;
72      }
73  
74      
75      public String getId()
76      {
77          return id;
78      }
79  
80      
81      public void setId(String id)
82      {
83          this.id = id;
84      }
85  
86      
87   
88  	/****************************************************************************
89  	 * SERIALIZER
90  	 */
91  	private static final XMLFormat XML = new XMLFormat(JSProfilingRule.class)
92  	{
93  		public void write(Object o, OutputElement xml)
94  				throws XMLStreamException
95  		{
96  
97  			try
98  			{
99  				JSProfilingRule g = (JSProfilingRule) o;
100 				xml.setAttribute("id", g.id);
101 				xml.setAttribute("standardRule", g.standardRule);
102 				xml.add( g.description, "description",String.class);
103 				xml.add(g.criterions);
104 
105 			} catch (Exception e)
106 			{
107 				e.printStackTrace();
108 			}
109 		}
110 
111 		public void read(InputElement xml, Object o)
112 		{
113 			try
114 			{
115 				JSProfilingRule g = (JSProfilingRule) o;
116 				g.id = StringEscapeUtils.unescapeHtml(xml.getAttribute("id","unkwown_id"));
117 				g.standardRule = xml.getAttribute("standardRule",false);
118 	               Object o1 = xml.get("description",String.class);
119 	                if (o1 instanceof String)
120 	                    g.description = (String) o1;
121 	                while (xml.hasNext())
122 	                {
123 	                    o1 = xml.getNext(); // mime
124 
125 	                    if (o1 instanceof JSRuleCriterions)
126 	                        g.criterions = (JSRuleCriterions) o1;
127 	                }
128 	        			} catch (Exception e)
129 			{
130 				e.printStackTrace();
131 			}
132 		}
133 	};
134 
135 
136 	/***
137 	 * @return Returns the criterions.
138 	 */
139 	public JSRuleCriterions getCriterions()
140 	{
141 		return criterions;
142 	}
143 
144 
145 	/***
146 	 * @param criterions The criterions to set.
147 	 */
148 	public void setCriterions(JSRuleCriterions criterions)
149 	{
150 		this.criterions = criterions;
151 	}
152 
153     
154 }