| /******************************************************************************* |
| * Copyright (c) 2011 University of Illinois All rights reserved. This program |
| * and the accompanying materials are made available under the terms of the |
| * Eclipse Public License v1.0 which accompanies this distribution, and is |
| * available at http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Albert L. Rossi - design and implementation |
| ******************************************************************************/ |
| package org.eclipse.ptp.rm.jaxb.core.data.impl; |
| |
| import java.util.List; |
| |
| import org.eclipse.ptp.rm.jaxb.core.data.Append; |
| import org.eclipse.ptp.rm.jaxb.core.data.Entry; |
| |
| public class AppendImpl extends AbstractAssign { |
| |
| private final String separator; |
| private final List<Entry> entries; |
| |
| public AppendImpl(String uuid, Append append) { |
| this.uuid = uuid; |
| this.field = append.getField(); |
| separator = append.getSeparator(); |
| entries = append.getEntry(); |
| } |
| |
| @Override |
| protected Object[] getValue(Object previous, String[] values) throws Throwable { |
| StringBuffer buffer = new StringBuffer(); |
| if (!entries.isEmpty()) { |
| if (previous != null) { |
| buffer.append(previous); |
| if (separator != null) { |
| buffer.append(separator); |
| } |
| } |
| Object v = getValue(entries.get(0), values); |
| if (v != null) { |
| buffer.append(v); |
| } |
| int len = entries.size(); |
| for (int i = 1; i < len; i++) { |
| v = getValue(entries.get(0), values); |
| if (v != null) { |
| if (separator != null) { |
| buffer.append(separator); |
| } |
| buffer.append(v); |
| } |
| } |
| } else { |
| buffer.append(previous); |
| } |
| return new Object[] { buffer.toString() }; |
| } |
| } |