2 * Copyright 2005-2011 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.xmlrouter.impl;
18 import java.util.ArrayList;
19 import java.util.List;
21 import org.wamblee.xmlrouter.config.Transformation;
24 * Transformation path from a source document to a destination.
26 * @author Erik Brakkee
29 public class TransformationPath {
31 private List<Transformation> transformations;
34 * Constructs empty path.
36 public TransformationPath() {
37 transformations = new ArrayList<Transformation>();
41 * Constructs path with single transformation.
43 * @param aTransformation
44 * Single transformation.
46 public TransformationPath(Transformation aTransformation) {
48 transformations.add(aTransformation);
52 * Constructs path with list of transformations.
54 * @param aTransformations
55 * List of transformations.
57 public TransformationPath(List<Transformation> aTransformations) {
59 transformations.addAll(aTransformations);
63 * Appends a transormation path to the current path.
66 * Transformation sequence to append.
67 * @return Appended transformations equence.
69 * exception if the appended transformation would not be valid.
71 public TransformationPath appendPath(TransformationPath aSequence) {
72 if (transformations.isEmpty()) {
73 return new TransformationPath(aSequence.transformations);
75 if (aSequence.transformations.isEmpty()) {
77 return new TransformationPath(transformations);
80 if (!getToType().equals(aSequence.getFromType())) {
81 throw new RuntimeException(
82 "error concatening sequence, destination of first differs from source of second");
84 List<Transformation> t = new ArrayList<Transformation>(transformations);
85 t.addAll(aSequence.transformations);
86 return new TransformationPath(t);
90 * @return Number of transformations.
93 return transformations.size();
97 * @return From type of the path or null if the sequence is empty.
99 public String getFromType() {
100 if (transformations.isEmpty()) {
103 return transformations.get(0).getFromType();
107 * @return To type of the path or null if the sequence is empty.
109 public String getToType() {
110 if (transformations.isEmpty()) {
113 return transformations.get(transformations.size() - 1).getToType();
117 * @return The transformations.
119 public List<Transformation> getTransformations() {
120 return transformations;
124 public String toString() {
125 StringBuffer buf = new StringBuffer();
126 buf.append("TransformationPath(");
127 for (int i = 0; i < transformations.size(); i++) {
131 buf.append(transformations.get(i).toString());
134 return buf.toString();