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:
024: /**
025: * Import ProfilingRule
026: *
027: * <profilingRule name = j2>
028: * <description>whatever</description>
029: * <className>org.apache.jetspeed.profile.RuleImpl</className>
030: * <criteria>
031: * ...
032: * </criteria>
033: * </profilingRule>
034: *
035: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
036: * @version $Id: $
037: */
038: public class JSProfilingRule {
039: private String id;
040: private boolean standardRule;
041: private String description;
042: JSRuleCriterions criterions = new JSRuleCriterions();
043:
044: public JSProfilingRule() {
045: }
046:
047: public boolean isStandardRule() {
048: return standardRule;
049: }
050:
051: public void setStandardRule(boolean standard) {
052: this .standardRule = standard;
053: }
054:
055: public String getDescription() {
056: return description;
057: }
058:
059: public void setDescription(String description) {
060: this .description = description;
061: }
062:
063: public String getId() {
064: return id;
065: }
066:
067: public void setId(String id) {
068: this .id = id;
069: }
070:
071: /***************************************************************************
072: * SERIALIZER
073: */
074: private static final XMLFormat XML = new XMLFormat(
075: JSProfilingRule.class) {
076: public void write(Object o, OutputElement xml)
077: throws XMLStreamException {
078:
079: try {
080: JSProfilingRule g = (JSProfilingRule) o;
081: xml.setAttribute("id", g.id);
082: xml.setAttribute("standardRule", g.standardRule);
083: xml.add(g.description, "description", String.class);
084: xml.add(g.criterions);
085:
086: } catch (Exception e) {
087: e.printStackTrace();
088: }
089: }
090:
091: public void read(InputElement xml, Object o) {
092: try {
093: JSProfilingRule g = (JSProfilingRule) o;
094: g.id = StringEscapeUtils.unescapeHtml(xml.getAttribute(
095: "id", "unkwown_id"));
096: g.standardRule = xml
097: .getAttribute("standardRule", false);
098: Object o1 = xml.get("description", String.class);
099: if (o1 instanceof String)
100: g.description = (String) o1;
101: while (xml.hasNext()) {
102: o1 = xml.getNext(); // mime
103:
104: if (o1 instanceof JSRuleCriterions)
105: g.criterions = (JSRuleCriterions) o1;
106: }
107: } catch (Exception e) {
108: e.printStackTrace();
109: }
110: }
111: };
112:
113: /**
114: * @return Returns the criterions.
115: */
116: public JSRuleCriterions getCriterions() {
117: return criterions;
118: }
119:
120: /**
121: * @param criterions The criterions to set.
122: */
123: public void setCriterions(JSRuleCriterions criterions) {
124: this.criterions = criterions;
125: }
126:
127: }
|