All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.officefloor.woof.template.impl.AbstractWoofTemplateExtensionSource Maven / Gradle / Ivy

There is a newer version: 3.40.0
Show newest version
/*
 * OfficeFloor - http://www.officefloor.net
 * Copyright (C) 2005-2018 Daniel Sagenschneider
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */
package net.officefloor.woof.template.impl;

import java.util.LinkedList;
import java.util.List;

import net.officefloor.model.change.Change;
import net.officefloor.woof.template.WoofTemplateExtensionChangeContext;
import net.officefloor.woof.template.WoofTemplateExtensionSource;
import net.officefloor.woof.template.WoofTemplateExtensionSourceProperty;
import net.officefloor.woof.template.WoofTemplateExtensionSourceSpecification;

/**
 * Abstract {@link WoofTemplateExtensionSource}.
 * 
 * @author Daniel Sagenschneider
 */
public abstract class AbstractWoofTemplateExtensionSource implements
		WoofTemplateExtensionSource {

	/*
	 * =================== WoofTemplateExtensionSource =================
	 */

	@Override
	public WoofTemplateExtensionSourceSpecification getSpecification() {
		// Create and load the specification
		Specification specification = new Specification();
		this.loadSpecification(specification);

		// Return the loaded specification
		return specification;
	}

	/**
	 * Overridden to load specifications.
	 * 
	 * @param context
	 *            Specifications.
	 */
	protected abstract void loadSpecification(SpecificationContext context);

	/**
	 * Context for the {@link WoofTemplateExtensionSource#getSpecification()}.
	 */
	public static interface SpecificationContext {

		/**
		 * Adds a property.
		 * 
		 * @param name
		 *            Name of property that is also used as the label.
		 */
		void addProperty(String name);

		/**
		 * Adds a property.
		 * 
		 * @param name
		 *            Name of property.
		 * @param label
		 *            Label for the property.
		 */
		void addProperty(String name, String label);

		/**
		 * Adds a property.
		 * 
		 * @param property
		 *            {@link WoofTemplateExtensionSourceProperty}.
		 */
		void addProperty(WoofTemplateExtensionSourceProperty property);
	}

	/**
	 * Specification for this {@link WoofTemplateExtensionSource}.
	 */
	private class Specification implements SpecificationContext,
			WoofTemplateExtensionSourceSpecification {

		/**
		 * Properties for the specification.
		 */
		private final List properties = new LinkedList();

		/*
		 * ========== SpecificationContext ========================
		 */

		@Override
		public void addProperty(String name) {
			this.properties.add(new WoofTemplateExtensionSourcePropertyImpl(
					name, name));
		}

		@Override
		public void addProperty(String name, String label) {
			this.properties.add(new WoofTemplateExtensionSourcePropertyImpl(
					name, label));
		}

		@Override
		public void addProperty(WoofTemplateExtensionSourceProperty property) {
			this.properties.add(property);
		}

		/*
		 * ========== WoofTemplateExtensionSourceSpecification ===========
		 */

		@Override
		public WoofTemplateExtensionSourceProperty[] getProperties() {
			return this.properties
					.toArray(new WoofTemplateExtensionSourceProperty[0]);
		}
	}

	@Override
	public Change createConfigurationChange(
			WoofTemplateExtensionChangeContext context) {
		// By default no change is necessary
		return null;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy