private void checkVersionCompatibility(final int version) { if (version < LOWEST_COMPATIBLE_VERSION || version > CURRENT_VERSION) { throw new MorphBuildException("Version " + version + " of definition file not supported by metamorph version " + CURRENT_VERSION); } }
public final void setLanguage(final String language) { if (!SUPPORTED_LANGUAGES.contains(language)) { throw new MorphBuildException("Language '" + language + "' not supported."); } this.outputLocale = new Locale(language); } }
public void setLanguage(final String language) { if (!LANGUAGES.contains(language)) { throw new MorphBuildException("Language " + language + " not supported."); } this.locale = new Locale(language); }
public void setLanguage(final String language) { if (!SUPPORTED_LANGUAGES.contains(language)) { throw new MorphBuildException("Language '" + language + "' not supported."); } this.locale = new Locale(language); }
private static int extractNumberFrom(final String string) { final String[] tokens = string.split(" ", 2); if (tokens.length < 2) { throw new MorphBuildException("Invalid only string: " + string); } return Integer.parseInt(tokens[1]); }
protected final void illegalChild(final Node child) { throw new MorphBuildException("Schema mismatch: illegal tag " + child.getLocalName() + " in node " + child.getParentNode().getLocalName()); }
public void setFile(final String file) { final ScriptEngineManager manager = new ScriptEngineManager(); final ScriptEngine engine = manager.getEngineByName("JavaScript"); try { // TODO: The script file should be loaded relatively to the base URI engine.eval(ResourceUtil.getReader(file)); } catch (final ScriptException e) { throw new MorphBuildException("Error in script", e); } catch (final FileNotFoundException e) { throw new MorphBuildException("Error loading script '" + file + "'", e); } invocable = (Invocable) engine; }
@Override public String process(final String value) { if (FORMAT_TIMESTAMP.equals(format)) { return Long.toString(System.currentTimeMillis() / MS_PER_SECOND); } final DateFormat dateFormat; try { dateFormat = new SimpleDateFormat(format, locale); } catch (final IllegalArgumentException e) { throw new MorphBuildException("The date/time format '" + format + "' is not supported. ", e); } dateFormat.setTimeZone(TimeZone.getTimeZone(timezone)); return dateFormat.format(new Date()); }
private static InputSource getInputSource(final String morphDef) { try { return new InputSource( ResourceUtil.getUrl(morphDef).toExternalForm()); } catch (final MalformedURLException e) { throw new MorphBuildException(COULD_NOT_LOAD_MORPH_FILE, e); } }
@Override public final String process(final String value) { String result; try { final Calendar c = Calendar.getInstance(); final SimpleDateFormat sdf = new SimpleDateFormat(inputFormat); c.setTime(sdf.parse(value)); if (era == Era.BC) { c.set(Calendar.ERA, GregorianCalendar.BC); } else if (era == Era.AD) { c.set(Calendar.ERA, GregorianCalendar.AD); } final SimpleDateFormat sdfp = (SimpleDateFormat) java.text.DateFormat.getDateInstance(outputFormat.getFormatId(), outputLocale); String p = sdfp.toPattern(); if (c.get(Calendar.ERA) == GregorianCalendar.BC) { p = p.replace("yyyy", "yyyy G"); } final SimpleDateFormat sdfo = new SimpleDateFormat(p, outputLocale); result = sdfo.format(c.getTime()); if (removeLeadingZeros) { result = result.replaceAll("([0]{1,})([0-9]{1,})", "$2"); } } catch (final IllegalArgumentException e) { throw new MorphBuildException("The date/time format is not supported.", e); } catch (final Exception e) { result = value; } return result; }
@Override @SuppressWarnings("unchecked") // protected by 'if (Function.class.isAssignableFrom(clazz))' protected void handleFunctionDefinition(final Node functionDefNode) { final Class<?> clazz; final String className = resolvedAttribute(functionDefNode, AttributeName.CLASS); try { clazz = Thread.currentThread().getContextClassLoader().loadClass(className); } catch (final ClassNotFoundException e) { throw new MorphBuildException("Function " + className + NOT_FOUND, e); } if (Function.class.isAssignableFrom(clazz)) { getFunctionFactory().registerClass(resolvedAttribute(functionDefNode, AttributeName.NAME), (Class<Function>) clazz); } else { throw new MorphBuildException(className + " does not implement interface 'Function'"); } }
@Override protected void enterCollect(final Node node) { final Map<String, String> attributes = resolvedAttributeMap(node); // flushWith should not be passed to the headPipe object via a // setter (see newInstance): attributes.remove(AttributeName.FLUSH_WITH.getString()); if (!getCollectFactory().containsKey(node.getLocalName())) { throw new MorphBuildException("Collector " + node.getLocalName() + NOT_FOUND); } final Collect collect; if (ENTITY.equals(node.getLocalName())) { collect = getCollectFactory().newInstance(node.getLocalName(), attributes, metamorph); } else { collect = getCollectFactory().newInstance(node.getLocalName(), attributes); } collect.setSourceLocation(getSourceLocation(node)); stack.push(new StackFrame(collect)); }
@SuppressWarnings("unchecked") @Override protected void handleMapClass(final Node mapNode) { final Map<String, String> attributes = resolvedAttributeMap(mapNode); final String mapName = resolveVars(attributes.remove(AttributeName.NAME.getString())); final Map<String, String> map; if (mapNode.getLocalName().equals(JAVAMAP)) { final String className = resolvedAttribute(mapNode, AttributeName.CLASS); attributes.remove(AttributeName.CLASS.getString()); final ConfigurableClass<? extends Map> mapClass = ReflectionUtil.loadClass(className, Map.class); map = mapClass.newInstance(attributes); } else if (getMapFactory().containsKey(mapNode.getLocalName())) { map = getMapFactory().newInstance(mapNode.getLocalName(), attributes); } else { throw new MorphBuildException("Map " + mapNode.getLocalName() + NOT_FOUND); } metamorph.putMap(mapName, map); }
final Node macroNode = macros.get(macroName); if (macroNode==null){ throw new MorphBuildException("Macro '" + macroName + "' undefined!");
throw new MorphBuildException(functionNode.getLocalName() + NOT_FOUND);