001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.serializer.objects;
018:
019: import javolution.xml.XMLFormat;
020: import javolution.xml.stream.XMLStreamException;
021:
022: import org.apache.commons.lang.StringEscapeUtils;
023: import org.apache.jetspeed.profiler.rules.RuleCriterion;
024:
025: public class JSRuleCriterion {
026: // private int refID;
027:
028: private String name;
029:
030: private String type;
031:
032: private String value;
033:
034: private int fallBackOrder;
035:
036: private int fallBackType;
037:
038: public JSRuleCriterion() {
039: // refID = id;
040: }
041:
042: public JSRuleCriterion(RuleCriterion c) {
043: this .name = c.getName();
044: this .type = c.getType();
045: this .value = c.getValue();
046: this .fallBackOrder = c.getFallbackOrder();
047: this .fallBackType = c.getFallbackType();
048: }
049:
050: /***************************************************************************
051: * SERIALIZER
052: */
053: private static final XMLFormat XML = new XMLFormat(
054: JSRuleCriterion.class) {
055: public void write(Object o, OutputElement xml)
056: throws XMLStreamException {
057:
058: try {
059: JSRuleCriterion g = (JSRuleCriterion) o;
060: xml.setAttribute("name", g.name);
061: xml.add(g.type, "type", String.class);
062: xml.add(g.value, "value", String.class);
063: xml.add(new Integer(g.fallBackOrder), "fallBackOrder",
064: Integer.class);
065: xml.add(new Integer(g.fallBackType), "fallBackType",
066: Integer.class);
067:
068: // xml.add(g.groupString);
069:
070: } catch (Exception e) {
071: e.printStackTrace();
072: }
073: }
074:
075: public void read(InputElement xml, Object o) {
076: try {
077: JSRuleCriterion g = (JSRuleCriterion) o;
078: g.name = StringEscapeUtils.unescapeHtml(xml
079: .getAttribute("name", "unknown_name"));
080: Object o1 = xml.get("type", String.class);
081: if (o1 instanceof String)
082: g.type = StringEscapeUtils
083: .unescapeHtml((String) o1);
084: o1 = xml.get("value", String.class);
085: if (o1 instanceof String)
086: g.value = StringEscapeUtils
087: .unescapeHtml((String) o1);
088:
089: o1 = xml.get("fallBackOrder", String.class);
090: if (o1 instanceof String)
091: g.fallBackOrder = Integer.parseInt(((String) o1));
092: o1 = xml.get("fallBackType", String.class);
093: if (o1 instanceof String)
094: g.fallBackType = Integer.parseInt(((String) o1));
095:
096: while (xml.hasNext()) {
097: }
098: } catch (Exception e) {
099: e.printStackTrace();
100: }
101: }
102: };
103:
104: /**
105: * @return Returns the type.
106: */
107: public String getType() {
108: return type;
109: }
110:
111: /**
112: * @param type The type to set.
113: */
114: public void setType(String type) {
115: this .type = type;
116: }
117:
118: /**
119: * @return Returns the fallBackOrder.
120: */
121: public int getFallBackOrder() {
122: return fallBackOrder;
123: }
124:
125: /**
126: * @param fallBackOrder The fallBackOrder to set.
127: */
128: public void setFallBackOrder(int fallBackOrder) {
129: this .fallBackOrder = fallBackOrder;
130: }
131:
132: /**
133: * @return Returns the fallBackType.
134: */
135: public int getFallBackType() {
136: return fallBackType;
137: }
138:
139: /**
140: * @param fallBackTye The fallBackType to set.
141: */
142: public void setFallBackType(int fallBackType) {
143: this .fallBackType = fallBackType;
144: }
145:
146: /**
147: * @return Returns the name.
148: */
149: public String getName() {
150: return name;
151: }
152:
153: /**
154: * @param name The name to set.
155: */
156: public void setName(String name) {
157: this .name = name;
158: }
159:
160: /**
161: * @return Returns the value.
162: */
163: public String getValue() {
164: return value;
165: }
166:
167: /**
168: * @param value The value to set.
169: */
170: public void setValue(String value) {
171: this.value = value;
172: }
173:
174: }
|