private void checkThatCommandIsAccepted(Object cmd) { if( ! AcceptedClientCommands.isAcceptedCommandClass(cmd.getClass()) ) { throw new UnsupportedOperationException(cmd.getClass().getName() + " is not an accepted command." ); } }
protected <T> T executeCommand( Command cmd ) { if( AcceptedClientCommands.isSendObjectParameterCommandClass(cmd.getClass()) ) { List<Object> extraClassInstanceList = new ArrayList<Object>(); preprocessParameterCommand(cmd, extraClassInstanceList); if( !extraClassInstanceList.isEmpty() ) { Set<Class<?>> extraJaxbClasses = new HashSet<Class<?>>(); for( Object jaxbObject : extraClassInstanceList ) { Class<?> jaxbClass = jaxbObject.getClass(); if( jaxbClass.isLocalClass() || jaxbClass.isAnonymousClass() ) { throw new SerializationException( "Only proper classes are allowed as parameters for the remote API: neither local nor anonymous classes are accepted: " + jaxbClass.getName()); } extraJaxbClasses.add(jaxbClass); } if( config.addJaxbClasses(extraJaxbClasses) ) { for( Class<?> extraClass : extraJaxbClasses ) { logger.debug( "Adding {} to the JAXBContext instance in this client instance.", extraClass.getName() ); } config.initializeJaxbSerializationProvider(); } } } preprocessCommand(cmd); if( config.isRest() ) { return executeRestCommand(cmd); } else { return executeJmsCommand(cmd); } }
@Test public void isAcceptableCommandTest() throws Exception { assertTrue( "The .isAcceptedCommandClass method is not functioning correctly: generated classes", AcceptedClientCommands.isAcceptedCommandClass(org.kie.remote.jaxb.gen.AddTaskCommand.class)); assertFalse( "The .isAcceptedCommandClass method is not functioning correctly: original command classes", AcceptedClientCommands.isAcceptedCommandClass(org.jbpm.services.task.commands.AddTaskCommand.class)); }
@Test public void reflectionMappingTest() throws Exception { Set<Class<?>> classes = reflections.getTypesAnnotatedWith(XmlAccessorType.class); assertFalse(classes.isEmpty()); List<Class<?>> classList = new LinkedList<Class<?>>(classes); Collections.sort(classList, new Comparator<Class<?>>() { @Override public int compare( Class<?> o1, Class<?> o2 ) { return o1.getSimpleName().compareTo(o2.getSimpleName()); } }); classes = new LinkedHashSet<Class<?>>(classList); Map<Class, Class> kieCmdGenCmdClassMap = new LinkedHashMap<Class, Class>(); for( Class<?> cmdClass : classes ) { if( ! cmdClass.getSimpleName().endsWith("Command") ) { continue; } if( ! AcceptedClientCommands.isAcceptedCommandClass(cmdClass) ) { continue; } Class genCmdClass = Class.forName("org.kie.remote.jaxb.gen." + cmdClass.getSimpleName()); assertTrue( genCmdClass.getSimpleName() + " is not an accepted command?", AcceptedClientCommands.isAcceptedCommandClass(genCmdClass) ); kieCmdGenCmdClassMap.put(cmdClass, genCmdClass); } assertFalse("No generated command classes could be found to test.", kieCmdGenCmdClassMap.isEmpty()); for( Entry<Class, Class> classEntry : kieCmdGenCmdClassMap.entrySet() ) { compareKieClassInstanceToGenClassInstance(classEntry.getKey(), classEntry.getValue()); } }