package com.smart.mapping;
import com.smart.config.ActionDefine;
public interface ActionDefineMapper {
public ActionDefine mapping( String actionName );
}
package com.smart.mapping;
import java.util.Map;
import java.util.Set;
import com.smart.config.ActionDefine;
import com.smart.context.SmartContext;
public class DefaultActionDefineMapper implements ActionDefineMapper {
private static final DefaultActionDefineMapper mapper = new DefaultActionDefineMapper();
private DefaultActionDefineMapper(){}
@Override
public ActionDefine mapping(String actionName) {
Map<String,ActionDefine> actions = SmartContext.getContext().getConfigContext()
.getActions();
Set<String> keys = actions.keySet();
for( String key : keys){
ActionDefine ad = (ActionDefine)actions.get(key);
if( actionName.equals(ad.getName())){
return ad;
}
}
return null;
}
public static DefaultActionDefineMapper getMapper() {
return mapper;
}
}
package com.smart.mapping;
public interface ActionMapper {
public Object mapping( String actionName );
}
package com.smart.mapping;
import com.smart.config.ActionDefine;
import com.smart.exception.NoSuchActionDefineException;
import com.smart.exception.ReflectionClassNotFoundException;
import com.smart.exception.ReflectionIllegalAccessException;
import com.smart.exception.ReflectionInstantiationException;
public class DefaultActionMapper implements ActionMapper {
private final static DefaultActionMapper actionMapper = new DefaultActionMapper();
private DefaultActionMapper(){}
@Override
public Object mapping(String actionName) {
ActionDefine actionDefine = DefaultActionDefineMapper.getMapper().mapping(actionName);
if( actionDefine == null )
throw new NoSuchActionDefineException(" no such ActionDefine exits ");
Object obj = null;
try {
obj = Class.forName(actionDefine.getClazz()).newInstance();
} catch (InstantiationException e) {
throw new ReflectionInstantiationException(e);
} catch (IllegalAccessException e) {
throw new ReflectionIllegalAccessException(e);
} catch (ClassNotFoundException e) {
throw new ReflectionClassNotFoundException(e);
}
return obj;
}
public static DefaultActionMapper getActionmapper() {
return actionMapper;
}
}
package com.smart.mapping;
import com.smart.forwarder.Forwarder;
public interface ForwarderMapper {
public Forwarder mapping( String clazz,String name );
}
package com.smart.mapping;
import java.util.List;
import java.util.Map;
import com.smart.config.ActionDefine;
import com.smart.config.ForwarderDefine;
import com.smart.context.SmartContext;
import com.smart.forwarder.DefaultForwarder;
import com.smart.forwarder.Forwarder;
public class DefaultForwarderMapper implements ForwarderMapper {
private final static DefaultForwarderMapper mapper = new DefaultForwarderMapper();
private DefaultForwarderMapper(){}
@Override
public Forwarder mapping(String clazz,String name) {
Map<String,ActionDefine> actions = SmartContext.getContext()
.getConfigContext().getActions();
ActionDefine ad = (ActionDefine)actions.get(clazz);
List<ForwarderDefine> fds = ad.getFdList();
for( ForwarderDefine fd : fds){
if( fd.getName().equals(name)){
return new DefaultForwarder(fd.getPath());
}
}
return null;
}
public static DefaultForwarderMapper getMapper() {
return mapper;
}
}