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;
23 public class TransformationPath {
25 private List<Transformation> transformations;
27 public TransformationPath() {
28 transformations = new ArrayList<Transformation>();
31 public TransformationPath(Transformation aTransformation) {
33 transformations.add(aTransformation);
36 public TransformationPath(List<Transformation> aTransformations) {
38 transformations.addAll(aTransformations);
41 public TransformationPath appendPath(TransformationPath aSequence) {
42 if (transformations.isEmpty()) {
43 return new TransformationPath(aSequence.transformations);
45 if (aSequence.transformations.isEmpty()) {
47 return new TransformationPath(transformations);
50 if (!getToType().equals(aSequence.getFromType())) {
51 throw new RuntimeException(
52 "error concatening sequence, destination of first differs from source of second");
54 List<Transformation> t = new ArrayList<Transformation>(transformations);
55 t.addAll(aSequence.transformations);
56 return new TransformationPath(t);
60 return transformations.size();
63 public String getFromType() {
64 if (transformations.isEmpty()) {
67 return transformations.get(0).getFromType();
70 public String getToType() {
71 if (transformations.isEmpty()) {
74 return transformations.get(transformations.size() - 1).getToType();
77 public List<Transformation> getTransformations() {
78 return transformations;
82 public String toString() {
83 StringBuffer buf = new StringBuffer();
84 buf.append("TransformationPath(");
85 for (int i = 0; i < transformations.size(); i++) {
89 buf.append(transformations.get(i).toString());
92 return buf.toString();