Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * OfficeFloor - http://www.officefloor.net
   * Copyright (C) 2005-2011 Daniel Sagenschneider
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU 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 General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 package net.officefloor.plugin.section.clazz;
 
 import java.util.List;
 
net.officefloor.compile.spi.work.source.WorkSource implementation to provide the net.officefloor.frame.api.execute.Task instances for the ClassSectionSource.

Author(s):
Daniel Sagenschneider
 
 public class SectionClassWorkSource extends ClassWorkSource {
 
 	/*
 	 * =================== ClassWorkSource ==========================
 	 */
 
 	protected void loadParameterManufacturers(
 			List<ParameterManufacturermanufacturers) {
 		manufacturers
 						SectionInterface.class));
 	}
 
 	protected WorkFactory<ClassWorkcreateWorkFactory(Class<?> clazz) {
 		return new SectionWorkFactory();
 	}
 
 			Class<?> clazzMethod methodboolean isStatic,
 			ParameterFactory[] parameters) {
 		return new SectionTaskFactory(methodisStaticparameters);
 	}
 
 	protected TaskTypeBuilder<IndexedIndexedaddTaskType(Class<?> clazz,
 			WorkTypeBuilder<ClassWorkworkTypeBuilderString taskName,
 			TaskFactory<ClassWorkIndexedIndexedtaskFactory,
 			Sequence objectSequenceSequence flowSequence) {
 
 		// Include method as task in type definition
 		TaskTypeBuilder<IndexedIndexedtaskTypeBuilder = workTypeBuilder
 				.addTaskType(taskNametaskFactorynullnull);
 
 		// Add the section object always as first dependency
 		taskTypeBuilder.addObject(clazz).setLabel("OBJECT");
 		objectSequence.nextIndex(); // index for section object
 
 		// Return the task type builder
 		return taskTypeBuilder;
 	}

net.officefloor.frame.api.build.WorkFactory for overriding net.officefloor.plugin.work.clazz.ClassWorkSource behaviour.

The object is a dependency rather than being instantiated.

 
 	private static class SectionWorkFactory extends ClassWork implements
Initiate.
 
		public SectionWorkFactory() {
			super(null);
		}
		public ClassWork createWork() {
			return this;
		}
	}

	public static class SectionTaskFactory implements
		private final Method method;

Indicates if the java.lang.reflect.Method is static.
		private final boolean isStatic;

		private final ParameterFactory[] parameters;

Initiate.

Parameters:
method java.lang.reflect.Method for the net.officefloor.frame.api.execute.Task.
isStatic Indicates if the java.lang.reflect.Method is static.
parameters net.officefloor.plugin.work.clazz.ParameterFactory instances for the parameters of the java.lang.reflect.Method.
		public SectionTaskFactory(Method methodboolean isStatic,
				ParameterFactory[] parameters) {
			this. = method;
			this. = isStatic;
			this. = parameters;
		}

		public Method getMethod() {
			return this.;
		}

			return this.;
		}
		/*
		 * ================= TaskFactory ========================
		 */
			return this;
		}
		/*
		 * ===================== Task ===========================
		 */
				throws Throwable {
			// Obtain the section object
			Object sectionObject = context.getObject(0);
			// Obtain the instance to invoke the method on
			Object instance = (this. ? null : sectionObject);
			// Create the listing of parameters
			Object[] params = new Object[this..length];
			for (int i = 0; i < params.lengthi++) {
				params[i] = this.[i].createParameter(context);
			}
			// Invoke the method as the task
			return ClassTask.invokeMethod(instancethis.params);
		}
	}
New to GrepCode? Check out our FAQ X