CPD Results

The following document contains the results of PMD's CPD 4.2.5.

Duplications

File Line
it/amattioli/applicate/commands/TransactionalCommandContext.java 43
it/amattioli/applicate/context/hibernate/TransactionalCommandContext.java 54
            logger.debug("Committing transaction");
            tx.commit();
            logger.debug("Transaction committed");
            evt = new CommandEvent(invocatedCmd, CommandResult.SUCCESSFUL);
        } catch (StaleObjectStateException e) {
        	tx.rollback();
            logger.debug("Transaction Rolled-back",e);
            evt = new CommandEvent(invocatedCmd, CommandResult.UNSUCCESSFUL, e);
            throw new ConcurrencyException(e);
        } catch (JDBCConnectionException e) {
        	logger.debug("Database connection problems, transaction cannot be committed nor rolled back");
        	evt = new CommandEvent(invocatedCmd, CommandResult.UNSUCCESSFUL, e);
            throw e;
        } catch (ApplicationException e) {
        	tx.rollback();
            logger.debug("Transaction Rolled-back");
            evt = new CommandEvent(invocatedCmd, CommandResult.UNSUCCESSFUL, e);
            throw e;
        } catch (RuntimeException e) {
            tx.rollback();
            logger.debug("Transaction Rolled-back");
            evt = new CommandEvent(invocatedCmd, CommandResult.UNSUCCESSFUL, e);
            throw e;
        } finally {
        	cmdEvtSupport.fireCommandEvent(evt);
        	if (invocatedCmd instanceof Resettable && ((Resettable)invocatedCmd).toBeReset()) {
        		reset();
        	} else {
        		getSessionManager().release();
        	}
        }
    }

    private void cancelCommand(Command invocatedCmd) {
    	try {
    		decorated.cancelCommand();
	    } finally {
			cmdEvtSupport.fireCommandEvent(new CommandEvent(invocatedCmd, CommandResult.CANCELLED));
			if (invocatedCmd instanceof Resettable && ((Resettable)invocatedCmd).toBeReset()) {
        		reset();
        	} else {
        		getSessionManager().release();
        	}
		}
    }

    private void addCommandListener(CommandListener listener) {
    	logger.debug("Registering transactional command listener " + listener);
    	cmdEvtSupport.addListener(listener);
    }

    private void addCommandListener(CommandListener listener, CommandResult... results) {
    	logger.debug("Registering transactional command listener " + listener);
    	cmdEvtSupport.addListener(listener, results);
    }
    
    private void reset() {
    	getSessionManager().reset();
		((Resettable)decorated).reset();
    }
File Line
it/amattioli/applicate/commands/TransactionalCommandContext.java 101
it/amattioli/applicate/context/hibernate/TransactionalCommandContext.java 129
		super.afterMethod(object, method, args, methodProxy);
	}

	public Object perform(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
		if ("doCommand".equals(method.getName())) {
			doCommand((Command) object);
			return null;
		} else if ("cancelCommand".equals(method.getName())) {
			cancelCommand((Command)object);
			return null;
		} else if ("addCommandListener".equals(method.getName())
					&& method.getParameterTypes().length == 2) {  //ADD_SPECIFIC_LSNR_PARMS.equals(method.getParameterTypes())) {
			addCommandListener((CommandListener) args[0], (CommandResult[]) args[1]);
			return null;
		} else if ("addCommandListener".equals(method.getName())
					&& method.getParameterTypes().length == 1) {  //ADD_GENERIC_LSNR_PARMS.equals(method.getParameterTypes())) {
			addCommandListener((CommandListener) args[0]);
			return null;
		} else if ("reset".equals(method.getName()) && object instanceof Resettable) {
			reset();
			return null;
		} else {
			return method.invoke(decorated, args);
		}
	}

}
File Line
it/amattioli/applicate/browsing/ObjectBrowserImpl.java 393
it/amattioli/applicate/commands/BeanEditorImpl.java 243
	}

	private Object customGet(String property) {
		try {
			return getClass().getMethod("get" + StringUtils.capitalize(property)).invoke(this);
		} catch (IllegalArgumentException e) {
			throw new RuntimeException(e);
		} catch (SecurityException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		} catch (InvocationTargetException e) {
			throw new RuntimeException(e);
		} catch (NoSuchMethodException e) {
			throw new RuntimeException(e);
		}
	}

	private Object customGet(String property, int i) {
		Object[] arr = (Object[])customGet(property);
		return arr[i];
	}

	private Object customGet(String property, String key) {
		Map<String, ?> map = (Map<String, ?>)customGet(property);
		return map.get(key);
	}
File Line
it/amattioli/applicate/commands/AbstractBeanEditor.java 64
it/amattioli/applicate/commands/BeanEditorImpl.java 87
	}

	@Override
	public Constraint getPropertyConstraint(String propertyName, String constraintName) {
		if (validator == null) {
			return null;
		}
		return validator.getPropertyConstraint(propertyName, constraintName);
	}

	@Override
	public Collection<Constraint> getPropertyConstraints(String propertyName) {
		if (validator == null) {
			return Collections.emptyList();
		}
		return validator.getPropertyConstraints(propertyName);
	}

	@Override
	public ValidationResult validateBean() {
		if (validator != null) {
			return validator.validateBean();
		}
		return new ValidationResult(VALID, null);
	}

	@Override
	public ValidationResult validateProperty(String propertyName, Object value) {
		if (validator != null) {
			return validator.validateProperty(propertyName, value);
		}
		return new ValidationResult(VALID, null);
	}
File Line
it/amattioli/applicate/browsing/DefaultTreeBrowser.java 90
it/amattioli/applicate/commands/tree/AbstractTreeManager.java 24
	}

	@Override
	public TreePath getPathOf(T target) {
		List<Integer> result = new ArrayList<Integer>();
		T curr = target;
		while (!curr.equals(getRoot())) {
			T parent = getParentOf(curr);
			result.add(0, getChildrenOf(parent).indexOf(curr));
			curr = parent;
		}
		return new TreePath(result);
	}

	@Override
	public T getTargetOf(TreePath path) {
		T result = getRoot();
		for (int i: path.asIntArray()) {
			result = getChildrenOf(result).get(i);
		}
		return result;
	}

	@Override
	public void addPropertyChangeListener(PropertyChangeListener listener) {
File Line
it/amattioli/applicate/commands/TransactionalCommandEnhancer.java 7
it/amattioli/applicate/context/hibernate/TransactionalCommandEnhancer.java 7
public class TransactionalCommandEnhancer {
	private TransactionalCommandContext transactionalCommandContext;

	public <T extends Command> T newTransaction(T command) {
		Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(command.getClass());
        transactionalCommandContext = new TransactionalCommandContext(command);
		enhancer.setCallback(transactionalCommandContext);
        return (T)enhancer.create();
	}

	public <T> T newDependentService(T command) {
		Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(command.getClass());
        enhancer.setCallback(new LongRunningContext(command, transactionalCommandContext.getSessionManager()));
        return (T)enhancer.create();
	}

}
File Line
it/amattioli/applicate/commands/TransactionalCommandContext.java 18
it/amattioli/applicate/context/hibernate/TransactionalCommandContext.java 25
public class TransactionalCommandContext extends LongRunningContext {
	private static final Logger logger = LoggerFactory.getLogger(TransactionalCommandContext.class);
	private Command decorated;
	private CommandEventSupport cmdEvtSupport = new CommandEventSupport();
	
	public static <T extends Command> T newTransaction(T command) {
		Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(command.getClass());
        enhancer.setCallback(new TransactionalCommandContext(command));
        T result = (T)enhancer.create();
        setDependenciesContextOn(command, result);
		return result;
	}

    public TransactionalCommandContext(Command decorated) {
    	super(decorated);
        this.decorated = decorated;