WinderStepRegistry implements StepRegistry { @Override public JobMetadata register(Class<? extends Step> e) { JobMetadata metadata = jobs.get(e); if (metadata != null) { return metadata; } if (!Enum.class.isAssignableFrom(e)) { throw new IllegalArgumentException("The class should be enum"); } Class<? extends Enum> clazz = (Class<? extends Enum>)e; EnumSet<?> set = EnumSet.allOf(clazz); WinderJobMetadata jobMetadata = new WinderJobMetadata(e); List<StepMetadata> list = new ArrayList<>(); Step errorStep = null; for (Object step : set) { Step orig = (Step)step; String origName = orig.name(); Class procClass = orig.getClass(); Method[] methods = procClass.getMethods(); Class contextClass; for(Method method :methods) { Class[] paramTypes = method.getParameterTypes(); if (paramTypes.length == 1) { if ("execute".equals(method.getName())) { if (TaskContext.class.isAssignableFrom(paramTypes[0])) { orig = addMoreSteps(orig); Timeline timeline = method.getAnnotation(Timeline.class); if (timeline != null) { orig = timeline(orig, timeline); } contextClass = paramTypes[0]; if (LoggerFactory.getLogger(contextClass).isDebugEnabled()) { orig = new LoggingStep(orig); } } break; } } } WinderStepMetadata stepMetadata = new WinderStepMetadata(origName, orig); try { Field field = e.getField(origName); boolean first = field.isAnnotationPresent(FirstStep.class); stepMetadata.setFirst(first); StatusEnum statusEnum = StatusEnum.UNKNOWN; ErrorStep error = field.getAnnotation(ErrorStep.class); if (error != null) { stepMetadata.setError(error != null); statusEnum = error.value(); stepMetadata.setRepeatable(false); } else { DoneStep doneStep = field.getAnnotation(DoneStep.class); if (doneStep != null) { stepMetadata.setDone(true); statusEnum = doneStep.value(); stepMetadata.setRepeatable(false); } else { Repeatable repeatable = field.getAnnotation(Repeatable.class); stepMetadata.setRepeatable(repeatable == null || repeatable.value()); } } stepMetadata.setFinalStatus(statusEnum); } catch (NoSuchFieldException e1) { throw new IllegalArgumentException("No such field:" + origName); } list.add(stepMetadata); if ("ERROR".equals(origName)) { errorStep = orig; } } jobMetadata.setSteps(list); Job jobDesc = clazz.getAnnotation(Job.class); if (jobDesc != null) { if (jobDesc.type().length() > 0) { jobMetadata.setJobType(jobDesc.type()); } if (jobDesc.group().length() > 0) { jobMetadata.setJobGroup(jobDesc.group()); } } StepMetadata stepMetadata = jobMetadata.getErrorStep(); if (stepMetadata == null && errorStep != null) { jobMetadata.setErrorStep(jobMetadata.getStep(errorStep.code())); } jobs.put(e, jobMetadata); return jobMetadata; }  @Override Step lookup(Class<? extends Step> clazz, final int code); @Override JobMetadata register(Class<? extends Step> e); @Override JobMetadata getMetadata(Class<? extends Step> clazz);  }
@Test public void register() throws Exception { }