Index: src/org/jboss/tools/smooks/configuration/editors/SelectorCreationDialog.java =================================================================== --- src/org/jboss/tools/smooks/configuration/editors/SelectorCreationDialog.java (revision 28090) +++ src/org/jboss/tools/smooks/configuration/editors/SelectorCreationDialog.java (working copy) @@ -11,22 +11,10 @@ package org.jboss.tools.smooks.configuration.editors; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.EnumSet; -import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; -import java.util.Set; -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; @@ -35,8 +23,6 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import org.w3c.dom.Document; - import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.viewers.DoubleClickEvent; @@ -70,8 +56,6 @@ import org.jboss.tools.smooks.configuration.editors.edireader12.EDIDataParser; import org.jboss.tools.smooks.configuration.editors.input.InputParameter; import org.jboss.tools.smooks.configuration.editors.input.InputType; -import org.jboss.tools.smooks.configuration.editors.javabean12.JavaBeanModel; -import org.jboss.tools.smooks.configuration.editors.javabean12.JavaBeanModelFactory; import org.jboss.tools.smooks.configuration.editors.uitls.JsonInputDataParser; import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils; import org.jboss.tools.smooks.configuration.editors.wizard.StructuredDataSelectionWizard; @@ -80,10 +64,12 @@ import org.jboss.tools.smooks.configuration.editors.xml.XMLObjectAnalyzer; import org.jboss.tools.smooks.configuration.editors.xml.XSDObjectAnalyzer; import org.jboss.tools.smooks.editor.ISmooksModelProvider; +import org.jboss.tools.smooks.launch.JavaGraphBuilder; import org.jboss.tools.smooks.model.smooks.DocumentRoot; import org.jboss.tools.smooks.model.smooks.SmooksResourceListType; import org.milyn.Smooks; import org.milyn.payload.JavaSource; +import org.w3c.dom.Document; /** * @author Dart (dpeng@redhat.com) @@ -539,109 +525,6 @@ return super.close(); } - public static class JavaGraphBuilder { - - public T buildGraph(Class messageType) { - try { - return buildObject(messageType); - } catch (Exception e) { - e.printStackTrace(); - throw new IllegalArgumentException("Unable to construct an instance of '" + messageType.getName() + "'", e); - } - } - - @SuppressWarnings("unchecked") - private T buildObject(Class objectType) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { - - if(String.class.isAssignableFrom(objectType)) { - return objectType.cast("x"); - } else if(Number.class.isAssignableFrom(objectType)) { - return objectType.getConstructor(String.class).newInstance("1"); - } else if(objectType.isPrimitive()) { - return (T) primitiveToObjectMap.get(objectType); - } else if(objectType == Object.class) { - // don't construct raw Object types... leave them and just return null... - return null; - } else if(objectType.isEnum()) { - return (T) EnumSet.allOf((Class)objectType).iterator().next(); - } - - T messageInstance = objectType.newInstance(); - - // populate all the fields... - Method[] methods = objectType.getMethods(); - for(Method method : methods) { - if(method.getName().startsWith("set") && method.getParameterTypes().length == 1) { - Class propertyType = method.getParameterTypes()[0]; - Object propertyInstance = null; - - if(Collection.class.isAssignableFrom(propertyType)) { - propertyInstance = buildCollection(method, propertyType); - } else if(propertyType.isArray()) { - propertyInstance = buildArray(method, propertyType); - } else { - propertyInstance = buildObject(propertyType); - } - - if(propertyInstance != null) { - method.invoke(messageInstance, propertyInstance); - } - } - } - - return messageInstance; - } - - private Object buildArray(Method method, Class propertyType) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { - Class arrayType = propertyType.getComponentType(); - Object[] arrayObj = (Object[]) Array.newInstance(arrayType, 1); - - Array.set(arrayObj, 0, buildObject(arrayType)); - - return arrayObj; - } - - private Object buildCollection(Method method, Class propertyType) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { - Type genericType = method.getGenericParameterTypes()[0]; - - if(genericType instanceof ParameterizedType) { - ParameterizedType genericTypeClass = (ParameterizedType) genericType; - Collection collection = null; - - if(!propertyType.isInterface()) { - // It's a concrete Collection type... just create an instance... - collection = (Collection) propertyType.newInstance(); - }else if(List.class.isAssignableFrom(propertyType)) { - collection = new ArrayList(); - } else if(Set.class.isAssignableFrom(propertyType)) { - collection = new LinkedHashSet(); - } - - if(collection != null) { - collection.add(buildObject((Class) genericTypeClass.getActualTypeArguments()[0])); - return collection; - } - } - - return null; - } - - private static final Map primitiveToObjectMap; - - static { - primitiveToObjectMap = new HashMap(); - primitiveToObjectMap.put(int.class, 1); - primitiveToObjectMap.put(long.class, 1L); - primitiveToObjectMap.put(boolean.class, true); - primitiveToObjectMap.put(float.class, 1f); - primitiveToObjectMap.put(double.class, 1d); - primitiveToObjectMap.put(char.class, '1'); - primitiveToObjectMap.put(byte.class, Byte.parseByte("1")); - primitiveToObjectMap.put(short.class, 1); - } - - } - public static Document getModel(Class theModelClass) throws Exception { try { Object objectGraph = graphBuilder.buildGraph(theModelClass); Index: src/org/jboss/tools/smooks/configuration/RuntimeMetadata.java =================================================================== --- src/org/jboss/tools/smooks/configuration/RuntimeMetadata.java (revision 28090) +++ src/org/jboss/tools/smooks/configuration/RuntimeMetadata.java (working copy) @@ -50,7 +50,7 @@ * @author tom.fennelly@jboss.com */ public class RuntimeMetadata { - + private String inputClassName = null; private Smooks metadataExtractor; private boolean isSmooksConfig; private boolean isValidSmooksConfig; @@ -70,7 +70,21 @@ // Build dependency map... RuntimeDependency.addDependencyChecklist(metadataExtractor); } + + + + public String getInputClassName() { + return inputClassName; + } + + + public void setInputClassName(String inputClassName) { + this.inputClassName = inputClassName; + } + + + public boolean isSmooksConfig() { return isSmooksConfig; } @@ -188,18 +202,23 @@ if (inputType != null) { String inputPath = inputParams.getProperty(inputType); if (inputPath != null) { - String resolvedFilePath; + String resolvedFilePath = null; try { resolvedFilePath = SmooksUIUtils.parseFilePath(inputPath.trim()); } catch (Exception e) { // It's not a valid config... inputFile = new File(inputPath.trim()); - return; +// return; } - - inputFile = new File(resolvedFilePath); - if (SmooksModelUtils.INPUT_TYPE_JAVA.equals(inputType) || (inputFile.exists() && inputFile.isFile())) { + if(resolvedFilePath != null){ + inputFile = new File(resolvedFilePath); + } + if (SmooksModelUtils.INPUT_TYPE_JAVA.equals(inputType)){ isValidSmooksConfig = true; + setInputClassName(inputPath); + } + if ((inputFile.exists() && inputFile.isFile())) { + isValidSmooksConfig = true; } } } Index: src/org/jboss/tools/smooks/launch/JavaGraphBuilder.java =================================================================== --- src/org/jboss/tools/smooks/launch/JavaGraphBuilder.java (revision 0) +++ src/org/jboss/tools/smooks/launch/JavaGraphBuilder.java (revision 0) @@ -0,0 +1,131 @@ +package org.jboss.tools.smooks.launch; + +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.milyn.Smooks; +import org.milyn.payload.JavaSource; +import org.w3c.dom.Document; + +public class JavaGraphBuilder { + + public T buildGraph(Class messageType) { + try { + return buildObject(messageType); + } catch (Exception e) { + e.printStackTrace(); + throw new IllegalArgumentException("Unable to construct an instance of '" + messageType.getName() + "'", e); + } + } + + @SuppressWarnings("unchecked") + private T buildObject(Class objectType) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { + + if(String.class.isAssignableFrom(objectType)) { + return objectType.cast("x"); + } else if(Number.class.isAssignableFrom(objectType)) { + return objectType.getConstructor(String.class).newInstance("1"); + } else if(objectType.isPrimitive()) { + return (T) primitiveToObjectMap.get(objectType); + } else if(objectType == Object.class) { + // don't construct raw Object types... leave them and just return null... + return null; + } else if(objectType.isEnum()) { + return (T) EnumSet.allOf((Class)objectType).iterator().next(); + } + + T messageInstance = objectType.newInstance(); + + // populate all the fields... + Method[] methods = objectType.getMethods(); + for(Method method : methods) { + if(method.getName().startsWith("set") && method.getParameterTypes().length == 1) { + Class propertyType = method.getParameterTypes()[0]; + Object propertyInstance = null; + + if(Collection.class.isAssignableFrom(propertyType)) { + propertyInstance = buildCollection(method, propertyType); + } else if(propertyType.isArray()) { + propertyInstance = buildArray(method, propertyType); + } else { + propertyInstance = buildObject(propertyType); + } + + if(propertyInstance != null) { + method.invoke(messageInstance, propertyInstance); + } + } + } + + return messageInstance; + } + + private Object buildArray(Method method, Class propertyType) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { + Class arrayType = propertyType.getComponentType(); + Object[] arrayObj = (Object[]) Array.newInstance(arrayType, 1); + + Array.set(arrayObj, 0, buildObject(arrayType)); + + return arrayObj; + } + + private Object buildCollection(Method method, Class propertyType) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { + Type genericType = method.getGenericParameterTypes()[0]; + + if(genericType instanceof ParameterizedType) { + ParameterizedType genericTypeClass = (ParameterizedType) genericType; + Collection collection = null; + + if(!propertyType.isInterface()) { + // It's a concrete Collection type... just create an instance... + collection = (Collection) propertyType.newInstance(); + }else if(List.class.isAssignableFrom(propertyType)) { + collection = new ArrayList(); + } else if(Set.class.isAssignableFrom(propertyType)) { + collection = new LinkedHashSet(); + } + + if(collection != null) { + collection.add(buildObject((Class) genericTypeClass.getActualTypeArguments()[0])); + return collection; + } + } + + return null; + } + + private static final Map primitiveToObjectMap; + + static { + primitiveToObjectMap = new HashMap(); + primitiveToObjectMap.put(int.class, 1); + primitiveToObjectMap.put(long.class, 1L); + primitiveToObjectMap.put(boolean.class, true); + primitiveToObjectMap.put(float.class, 1f); + primitiveToObjectMap.put(double.class, 1d); + primitiveToObjectMap.put(char.class, '1'); + primitiveToObjectMap.put(byte.class, Byte.parseByte("1")); + primitiveToObjectMap.put(short.class, 1); + } + +} + Index: src/org/jboss/tools/smooks/launch/SmooksLaunchShortcut.java =================================================================== --- src/org/jboss/tools/smooks/launch/SmooksLaunchShortcut.java (revision 28090) +++ src/org/jboss/tools/smooks/launch/SmooksLaunchShortcut.java (working copy) @@ -106,8 +106,8 @@ RuntimeMetadata metadata = new RuntimeMetadata(); metadata.setSmooksConfig(elementToLaunch); if(SmooksInputType.INPUT_TYPE_JAVA.equals(metadata.getInputType())) { - MessageDialog.openError(getShell(), Messages.SmooksLaunchShortcut_Title_Launch_Failed, Messages.SmooksLaunchConfigurationDelegate_Error_Java_Unsupported); - return; +// MessageDialog.openError(getShell(), Messages.SmooksLaunchShortcut_Title_Launch_Failed, Messages.SmooksLaunchConfigurationDelegate_Error_Java_Unsupported); +// return; } else if (!metadata.isValidSmooksConfig()) { MessageDialog.openError(getShell(), Messages.SmooksLaunchShortcut_Title_Launch_Failed, metadata.getErrorMessage()); return; Index: src/org/jboss/tools/smooks/launch/SmooksLaunchConfigurationDelegate.java =================================================================== --- src/org/jboss/tools/smooks/launch/SmooksLaunchConfigurationDelegate.java (revision 28090) +++ src/org/jboss/tools/smooks/launch/SmooksLaunchConfigurationDelegate.java (working copy) @@ -80,8 +80,8 @@ launchMetadata.setSmooksConfig(project.findMember(smooksConfigName)); if(SmooksInputType.INPUT_TYPE_JAVA.equals(launchMetadata.getInputType())) { - displayError(smooksConfigName, Messages.SmooksLaunchConfigurationDelegate_Error_Java_Unsupported); - return; +// displayError(smooksConfigName, Messages.SmooksLaunchConfigurationDelegate_Error_Java_Unsupported); +// return; } else if(!launchMetadata.isValidSmooksConfig()) { displayError(smooksConfigName, launchMetadata.getErrorMessage()); return; @@ -107,6 +107,9 @@ String inputType = launchMetadata.getInputType(); String inputPath = launchMetadata.getInputFile().getAbsolutePath(); + if(SmooksInputType.INPUT_TYPE_JAVA.equals(launchMetadata.getInputType())) { + inputPath = launchMetadata.getInputClassName(); + } String nodeTypes = launchMetadata.getNodeTypesString(); runConfig.setProgramArguments(new String[] {launchMetadata.getConfigFile().getAbsolutePath(), inputType, inputPath, nodeTypes}); @@ -155,6 +158,7 @@ File wsRootDir = ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toFile(); File wsTempClasses = new File(wsRootDir, "temp/launcher/classes"); //$NON-NLS-1$ + writeClassToFilesys(JavaGraphBuilder.class, wsTempClasses); writeClassToFilesys(SmooksLauncher.class, wsTempClasses); writeClassToFilesys(SmooksInputType.class, wsTempClasses); writeClassToFilesys(ProcessNodeType.class, wsTempClasses); Index: src/org/jboss/tools/smooks/launch/SmooksLauncher.java =================================================================== --- src/org/jboss/tools/smooks/launch/SmooksLauncher.java (revision 28090) +++ src/org/jboss/tools/smooks/launch/SmooksLauncher.java (working copy) @@ -30,6 +30,7 @@ import java.util.Properties; import java.util.Set; +import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import org.jboss.tools.smooks.configuration.ProcessNodeType; @@ -37,6 +38,7 @@ import org.jboss.tools.smooks.launch.serialize.ObjectSerializer; import org.milyn.Smooks; import org.milyn.payload.JavaResult; +import org.milyn.payload.JavaSource; import org.milyn.payload.StringResult; import org.xml.sax.SAXException; @@ -59,54 +61,64 @@ if(args.length != 4) { throw new RuntimeException(localizedMessages.getProperty("SmooksLauncher_Error_Expected_Four_Args")); //$NON-NLS-1$ } - + Source inputSource = null; if(args[1].equals(SmooksInputType.INPUT_TYPE_JAVA)) { - System.out.println(localizedMessages.getProperty("SmooksLauncher_Error_Do_Not_Support_Java_Inputs")); //$NON-NLS-1$ + Class clazz; + try { + clazz = Class.forName(args[2]); + System.out.println(clazz); + JavaGraphBuilder graphBuilder = new JavaGraphBuilder(); + + Object objectGraph = graphBuilder.buildGraph(clazz); + inputSource = new JavaSource(objectGraph); + } catch (ClassNotFoundException e) { + System.out.println("Class not found \n" + e.getLocalizedMessage()); + } } else { - File smooksConfig = new File(args[0]); File input = new File(args[2]); - - assertFile(smooksConfig, "Smooks"); //$NON-NLS-1$ assertFile(input, "Input"); //$NON-NLS-1$ + inputSource = new StreamSource(new FileInputStream(input)); + } + + File smooksConfig = new File(args[0]); + assertFile(smooksConfig, "Smooks"); //$NON-NLS-1$ + Smooks smooks = new Smooks(smooksConfig.toURI().getPath()); + try { + Set processNodeTypes = SmooksLauncher.fromNodeTypeString(args[3]); + JavaResult javaResult = new JavaResult(); + boolean nothingDisplayed = true; - Smooks smooks = new Smooks(smooksConfig.toURI().getPath()); - try { - Set processNodeTypes = SmooksLauncher.fromNodeTypeString(args[3]); - JavaResult javaResult = new JavaResult(); - boolean nothingDisplayed = true; + if(processNodeTypes.contains(ProcessNodeType.TEMPLATING)) { + StringResult stringResult = new StringResult(); - if(processNodeTypes.contains(ProcessNodeType.TEMPLATING)) { - StringResult stringResult = new StringResult(); - - smooks.filterSource(new StreamSource(new FileInputStream(input)), stringResult, javaResult); - System.out.println("[" + localizedMessages.getProperty("SmooksLauncher_Templating_To_StreamResult") + " ...]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - System.out.println(" |--"); //$NON-NLS-1$ - System.out.println(indent(stringResult.toString())); - System.out.println(" |--\n"); //$NON-NLS-1$ - nothingDisplayed = false; - } else { - smooks.filterSource(new StreamSource(new FileInputStream(input)), javaResult); - } - - Collection serializedJavaResults = ObjectSerializer.serialize(javaResult); - if(!serializedJavaResults.isEmpty()) { - System.out.println("[" + localizedMessages.getProperty("SmooksLauncher_Java_Mapping_Results") + "...]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - for(ObjectSerializer serializedJavaResult : serializedJavaResults) { - System.out.println(" |--"); //$NON-NLS-1$ - System.out.println(indent(serializedJavaResult.getSerializedForm())); - System.out.println(" |--"); //$NON-NLS-1$ - } - nothingDisplayed = false; - } + smooks.filterSource(inputSource, stringResult, javaResult); + System.out.println("[" + localizedMessages.getProperty("SmooksLauncher_Templating_To_StreamResult") + " ...]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + System.out.println(" |--"); //$NON-NLS-1$ + System.out.println(indent(stringResult.toString())); + System.out.println(" |--\n"); //$NON-NLS-1$ + nothingDisplayed = false; + } else { + smooks.filterSource(inputSource, javaResult); + } + System.out.println("successfully"); + Collection serializedJavaResults = ObjectSerializer.serialize(javaResult); + if(!serializedJavaResults.isEmpty()) { + System.out.println("[" + localizedMessages.getProperty("SmooksLauncher_Java_Mapping_Results") + "...]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if(nothingDisplayed) { - System.out.println(localizedMessages.getProperty("SmooksLauncher_Nothing_To_Display")); //$NON-NLS-1$ + for(ObjectSerializer serializedJavaResult : serializedJavaResults) { + System.out.println(" |--"); //$NON-NLS-1$ + System.out.println(indent(serializedJavaResult.getSerializedForm())); + System.out.println(" |--"); //$NON-NLS-1$ } - } finally { - smooks.close(); + nothingDisplayed = false; } - } + + if(nothingDisplayed) { + System.out.println(localizedMessages.getProperty("SmooksLauncher_Nothing_To_Display")); //$NON-NLS-1$ + } + } finally { + smooks.close(); + } } private static Properties loadLocalizedMessages() { Index: src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java =================================================================== --- src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java (revision 28090) +++ src/org/jboss/tools/smooks/graphical/editors/SmooksGraphicalEditorPart.java (working copy) @@ -1122,6 +1122,8 @@ } public boolean autoLayout(boolean animation) { + // disable the animation now + animation = false; final GraphAnimation graphAnimation = new GraphAnimation(); HashMap nodeMap = new HashMap(); DirectedGraph directedGraph = collectionGraphInformation(nodeMap);