Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.mina.statemachine;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.mina.statemachine.annotation.OnEntry;
import org.apache.mina.statemachine.annotation.OnExit;
import org.apache.mina.statemachine.annotation.Transition;
import org.apache.mina.statemachine.annotation.TransitionAnnotation;
import org.apache.mina.statemachine.annotation.Transitions;
import org.apache.mina.statemachine.event.Event;
import org.apache.mina.statemachine.transition.MethodSelfTransition;
import org.apache.mina.statemachine.transition.MethodTransition;
import org.apache.mina.statemachine.transition.SelfTransition;
/**
* Creates {@link StateMachine}s by reading {@link org.apache.mina.statemachine.annotation.State},
* {@link Transition} and {@link Transitions} (or equivalent) and {@link SelfTransition} annotations from one or more arbitrary
* objects.
*
*
* @author Apache MINA Project
*/
public class StateMachineFactory {
private final Class extends Annotation> transitionAnnotation;
private final Class extends Annotation> transitionsAnnotation;
private final Class extends Annotation> entrySelfTransitionsAnnotation;
private final Class extends Annotation> exitSelfTransitionsAnnotation;
protected StateMachineFactory(Class extends Annotation> transitionAnnotation,
Class extends Annotation> transitionsAnnotation,
Class extends Annotation> entrySelfTransitionsAnnotation,
Class extends Annotation> exitSelfTransitionsAnnotation) {
this.transitionAnnotation = transitionAnnotation;
this.transitionsAnnotation = transitionsAnnotation;
this.entrySelfTransitionsAnnotation = entrySelfTransitionsAnnotation;
this.exitSelfTransitionsAnnotation = exitSelfTransitionsAnnotation;
}
/**
* Returns a new {@link StateMachineFactory} instance which creates
* {@link StateMachine}s by reading the specified {@link Transition}
* equivalent annotation.
*
* @param transitionAnnotation the {@link Transition} equivalent annotation.
* @return the {@link StateMachineFactory}.
*/
public static StateMachineFactory getInstance(Class extends Annotation> transitionAnnotation) {
TransitionAnnotation a = transitionAnnotation.getAnnotation(TransitionAnnotation.class);
if (a == null) {
throw new IllegalArgumentException("The annotation class " + transitionAnnotation
+ " has not been annotated with the " + TransitionAnnotation.class.getName() + " annotation");
}
return new StateMachineFactory(transitionAnnotation, a.value(), OnEntry.class, OnExit.class);
}
/**
* Creates a new {@link StateMachine} from the specified handler object and
* using a start state with id start.
*
* @param handler the object containing the annotations describing the
* state machine.
* @return the {@link StateMachine} object.
*/
public StateMachine create(Object handler) {
return create(handler, new Object[0]);
}
/**
* Creates a new {@link StateMachine} from the specified handler object and
* using the {@link State} with the specified id as start state.
*
* @param start the id of the start {@link State} to use.
* @param handler the object containing the annotations describing the
* state machine.
* @return the {@link StateMachine} object.
*/
public StateMachine create(String start, Object handler) {
return create(start, handler, new Object[0]);
}
/**
* Creates a new {@link StateMachine} from the specified handler objects and
* using a start state with id start.
*
* @param handler the first object containing the annotations describing the
* state machine.
* @param handlers zero or more additional objects containing the
* annotations describing the state machine.
* @return the {@link StateMachine} object.
*/
public StateMachine create(Object handler, Object... handlers) {
return create("start", handler, handlers);
}
/**
* Creates a new {@link StateMachine} from the specified handler objects and
* using the {@link State} with the specified id as start state.
*
* @param start the id of the start {@link State} to use.
* @param handler the first object containing the annotations describing the
* state machine.
* @param handlers zero or more additional objects containing the
* annotations describing the state machine.
* @return the {@link StateMachine} object.
*/
public StateMachine create(String start, Object handler, Object... handlers) {
Map states = new HashMap();
List