org.simpleframework.xml.core.Collector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simple-xml Show documentation
Show all versions of simple-xml Show documentation
Simple is a high performance XML serialization and configuration framework for Java
The newest version!
/*
* Collector.java December 2007
*
* Copyright (C) 2007, Niall Gallagher
*
* 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.simpleframework.xml.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
/**
* The Collector
object is used to store variables for
* a deserialized object. Each variable contains the label and value
* for a field or method. The Composite
object uses
* this to store deserialized values before committing them to the
* objects methods and fields.
*
* @author Niall Gallagher
*
* @see org.simpleframework.xml.core.Composite
*/
class Collector implements Criteria {
/**
* This is the registry containing all the variables collected.
*/
private final Registry registry;
/**
* This is the registry that contains variables mapped to paths.
*/
private final Registry alias;
/**
* Constructor for the Collector
object. This is
* used to store variables for an objects fields and methods.
* Each variable is stored using the name of the label.
*/
public Collector() {
this.registry = new Registry();
this.alias = new Registry();
}
/**
* This is used to get the Variable
that represents
* a deserialized object. The variable contains all the meta
* data for the field or method and the value that is to be set
* on the method or field.
*
* @param key this is the key of the variable to be acquired
*
* @return this returns the keyed variable if it exists
*/
public Variable get(Object key) {
return registry.get(key);
}
/**
* This is used to get the Variable
that represents
* a deserialized object. The variable contains all the meta
* data for the field or method and the value that is to be set
* on the method or field.
*
* @param label this is the label to resolve the variable with
*
* @return this returns the variable associated with the label
*/
public Variable get(Label label) throws Exception {
if(label != null) {
Object key = label.getKey();
return registry.get(key);
}
return null;
}
/**
* This is used to resolve the Variable
by using
* the union names of a label. This will also acquire variables
* based on the actual name of the variable.
*
* @param path this is the path of the variable to be acquired
*
* @return this returns the variable mapped to the path
*/
public Variable resolve(String path) {
return alias.get(path);
}
/**
* This is used to remove the Variable
from this
* criteria object. When removed, the variable will no longer be
* used to set the method or field when the commit
* method is invoked.
*
* @param key this is the key associated with the variable
*
* @return this returns the keyed variable if it exists
*/
public Variable remove(Object key) throws Exception{
return registry.remove(key);
}
/**
* This is used to acquire an iterator over the named variables.
* Providing an Iterator
allows the criteria to be
* used in a for each loop. This is primarily for convenience.
*
* @return this returns an iterator of all the variable names
*/
public Iterator