001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.crm.report.model;
015:
016: import org.gjt.xpp.XmlPullNode;
017: import org.jetbrains.annotations.NotNull;
018: import org.pentaho.reportdesigner.crm.report.PropertyKeys;
019: import org.pentaho.reportdesigner.lib.common.xml.XMLContext;
020: import org.pentaho.reportdesigner.lib.common.xml.XMLExternalizable;
021: import org.pentaho.reportdesigner.lib.common.xml.XMLWriter;
022:
023: import java.io.IOException;
024: import java.util.ArrayList;
025: import java.util.Collections;
026: import java.util.List;
027:
028: /**
029: * User: Martin
030: * Date: 02.06.2006
031: * Time: 14:39:32
032: */
033: public class StyleExpressions implements XMLExternalizable {
034: @NotNull
035: private ArrayList<StyleExpression> styleExpressions;
036:
037: public StyleExpressions() {
038: styleExpressions = new ArrayList<StyleExpression>();
039: }
040:
041: public StyleExpressions(@NotNull
042: StyleExpressions styleExpressions) {
043: //noinspection ConstantConditions
044: if (styleExpressions == null) {
045: throw new IllegalArgumentException(
046: "styleExpressions must not be null");
047: }
048:
049: this .styleExpressions = new ArrayList<StyleExpression>();
050: this .styleExpressions.addAll(styleExpressions.styleExpressions);
051: }
052:
053: @NotNull
054: public StyleExpressions addStyleExpression(@NotNull
055: StyleExpression styleExpression) {
056: //noinspection ConstantConditions
057: if (styleExpression == null) {
058: throw new IllegalArgumentException(
059: "styleExpression must not be null");
060: }
061:
062: StyleExpressions styleExpressions = new StyleExpressions();
063: styleExpressions.styleExpressions.addAll(this .styleExpressions);
064: styleExpressions.styleExpressions.add(styleExpression);
065: return styleExpressions;
066: }
067:
068: @NotNull
069: public StyleExpressions removeStyleExpression(@NotNull
070: StyleExpression styleExpression) {
071: //noinspection ConstantConditions
072: if (styleExpression == null) {
073: throw new IllegalArgumentException(
074: "styleExpression must not be null");
075: }
076:
077: StyleExpressions styleExpressions = new StyleExpressions();
078: styleExpressions.styleExpressions.addAll(this .styleExpressions);
079: styleExpressions.styleExpressions.remove(styleExpression);
080: return styleExpressions;
081: }
082:
083: @NotNull
084: public List<StyleExpression> getStyleExpressions() {
085: return Collections.unmodifiableList(styleExpressions);
086: }
087:
088: public void externalizeObject(@NotNull
089: XMLWriter xmlWriter, @NotNull
090: XMLContext xmlContext) throws IOException {
091: for (StyleExpression styleExpression : styleExpressions) {
092: xmlWriter.startElement(PropertyKeys.STYLE_EXPRESSION);
093: styleExpression.externalizeObject(xmlWriter, xmlContext);
094: xmlWriter.closeElement(PropertyKeys.STYLE_EXPRESSION);
095: }
096: }
097:
098: public void readObject(@NotNull
099: XmlPullNode node, @NotNull
100: XMLContext xmlContext) throws Exception {
101: while (!node.isFinished()) {
102: Object childNodeList = node.readNextChild();
103: if (childNodeList instanceof XmlPullNode) {
104: XmlPullNode child = (XmlPullNode) childNodeList;
105: if (PropertyKeys.STYLE_EXPRESSION.equals(child
106: .getRawName())) {
107: StyleExpression styleExpression = new StyleExpression(
108: "", "");
109: styleExpression.readObject(child, xmlContext);
110: styleExpressions.add(styleExpression);
111: }
112: }
113: }
114: }
115: }
|