/**
* Copyright 2011 meltmedia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.xchain.framework.util;
import java.util.Iterator;
import java.util.Map;
/**
* A container class for parsed transformer processing instructions. This is generated by ParserUtil.parseTransformer(String).
*
* @author Christian Trimble
*
* @see ParserUtil#parseTransformer(String)
*/
public class ParsedTransformerFactory
{
private Map<String, String> fields = null;
private Map<String, String> attributes = null;
private Map<String, Boolean> features = null;
public void setFields( Map<String, String> fields ) { this.fields = fields; }
public Map<String, String> getFields() { return this.fields; }
/**
* Set the attribute map.
* @param attributes A mapping of attribute names to attribute values.
*/
public void setAttributes( Map<String, String> attributes ) { this.attributes = attributes; }
/**
* @return A mapping of attribute names to attribute values.
*/
public Map<String, String> getAttributes() { return this.attributes; }
public void setFeatures( Map<String, Boolean> features ) { this.features = features; }
public Map<String, Boolean> getFeatures() { return this.features; }
public String toString()
{
StringBuilder builder = new StringBuilder();
appendMap(builder, fields);
if( features.keySet().size() > 0 ) {
builder.append(" features ");
appendMap(builder, features);
}
if( attributes.keySet().size() > 0 ) {
builder.append(" attributes ");
appendMap(builder, attributes);
}
return builder.toString();
}
private void appendMap( StringBuilder builder, Map map )
{
Iterator entryIterator = map.entrySet().iterator();
while( entryIterator.hasNext() ) {
Map.Entry entry = (Map.Entry)entryIterator.next();
builder.append(entry.getKey()).append(" ").append(entry.getValue());
if( entryIterator.hasNext() ) {
builder.append(" ");
}
}
}
}