/** * Construct from given paxml entity registry. * * @param reg * the registry * @param processId * the processId */ public Paxml(final EntityFactoryRegistry reg, long processId) { parser = new Parser(this, reg, new ResourceLocator()); this.processId = processId; }
/** * Add tag library. * * @param classes * tag library classes. * @return this */ public Paxml addTagLibrary(Class<? extends ITagLibrary>... classes) { for (Class<? extends ITagLibrary> clazz : classes) { ITagLibrary lib = ReflectUtils.createObject(clazz); parser.addTagLibrary(lib, true); } return this; }
public ResourceLocator getResourceLocator() { return parser.getResourceLocator(); }
private void loadTextProperties(Properties props, String text) { Properties loaded = new Properties(); try { Parser.loadProperties(loaded, true, new ByteArrayInputStream(text.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new PaxmlRuntimeException(e); } loaded = Parser.trimProperties(loaded); props.putAll(loaded); }
private static Class<? extends ITag> getTagImplFromTabLibs(ParserContext context, String ns, String tagName) { // search from tag libs Parser parser = context.getParser(); for (ITagLibrary lib : parser.getTagLibraries()) { if (ns != null && !ns.equals(lib.getNamespaceUri())) { continue; } Class<? extends ITag> clazz = lib.getTagImpl(tagName); if (clazz != null) { return clazz; } } return null; }
/** * Get entity from cache, if not found, call parser to construct the entity. * * @param name * the name of the resource. * @param context * the parser context, set to null if not known. * @return the entity, null if not found or unknown how to parse. */ public IEntity getEntity(String name, IParserContext context) { PaxmlResource res = getResource(name); if (res == null) { throw new PaxmlRuntimeException("No resource found for paxml: " + name); } return parser.parse(res, false, context); }
private Plan processPlan(OMElement root, Properties props) { final Paxml paxml = new Paxml(0); paxml.addStaticConfig(model.getConfig()); // add the plan tag lib temporarily paxml.getParser().addTagLibrary(new PlanTagLibrary(), false); final PaxmlResource planFileResource; try { planFileResource = PaxmlResource.createFromPath(planFile.getURI().toString()); } catch (IOException e) { throw new PaxmlRuntimeException(e); } // add resource for execution paxml.addResources(planFileResource); IEntity entity = paxml.getParser().parseXml(root, planFileResource, null); if (entity == null) { throw new PaxmlRuntimeException("Internal error: should not be null!"); } props.put(LaunchModel.class, model); paxml.execute(entity, System.getProperties(), props); Plan plan = (Plan) entity; return plan; }
IEntity entity = null; if (context != null) { entity = detectCircle(context.getParserStack(), resource); if (entity != null) { return entity; OMElement root = AxiomUtils.getRootElement(in); try { entity = parseXml(root, resource, context); } finally { root.close(false);
Paxml paxml = new Paxml(LaunchModel.generateNextPid(), execId); paxml.addStaticConfig(config); paxml.getParser().addTagLibrary(new PlanTagLibrary(), false); context.setConsts(params, null, false); IEntity entity = paxml.getParser().parse(r, true, null); if (entity instanceof Plan) {
Resource res = Parser.getResource(file, getEntity().getResource().getSpringResource()); Parser.loadProperties(props, res, null);
public Resource getSpringResource() { return Parser.getResource(path, null); }
/** * Load properties from a resource file and more text if given. * * @param props * the properties file to load into * @param res * a resource to load from, null to ignore * @param moreText * a text to load from, null to ignore * @return the input properties */ public static Properties loadProperties(Properties props, Resource res, String moreText) { InputStream[] ins = new InputStream[2]; if (res != null) { try { ins[0] = res.getInputStream(); } catch (IOException e) { throw new PaxmlRuntimeException("Cannot load properties from resource " + res, e); } } if (moreText != null) { try { ins[1] = new ByteArrayInputStream(moreText.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new PaxmlRuntimeException(e); } } return loadProperties(props, true, ins); }
File file = getFile(path); if (file.isFile()) { path = filePrefix + file.getAbsolutePath();
private Object getUtilFunctions(String name, Context context) { for (ITagLibrary tagLib : context.getPaxml().getParser().getTagLibraries()) { Class<? extends IUtilFunctionsFactory> clazz = tagLib.getUtilFunctionsFactory(name); if (clazz != null) { return ReflectUtils.createObject(clazz).getUtilFunctions(context); } } return null; } }
/** * Get entity from cache, if not found, call parser to construct the entity. * * @param name * the name of the resource. * @param context * the parser context, set to null if not known. * @return the entity, null if not found or unknown how to parse. */ public IEntity getEntity(String name, IParserContext context) { PaxmlResource res = getResource(name); if (res == null) { throw new PaxmlRuntimeException("No resource found for paxml: " + name); } return parser.parse(res, false, context); }
private Plan processPlan(OMElement root, Properties props) { final long pid = LaunchModel.generateNextPid(); model.setPlanProcessId(pid); final Paxml paxml = new Paxml(pid, PaxmlUtils.getNextExecutionId()); paxml.addStaticConfig(model.getConfig()); // add the plan tag lib temporarily paxml.getParser().addTagLibrary(new PlanTagLibrary(), false); final PaxmlResource planFileResource; try { planFileResource = PaxmlResource.createFromPath(planFile.getURI().toString()); } catch (IOException e) { throw new PaxmlRuntimeException(e); } // add resource for execution paxml.addResources(planFileResource); IEntity entity = paxml.getParser().parseXml(root, planFileResource, null); if (entity == null) { throw new PaxmlRuntimeException("Internal error: should not be null!"); } props.put(LaunchModel.class, model); paxml.execute(entity, System.getProperties(), props); Plan plan = (Plan) entity; return plan; }
IEntity entity = null; if (context != null) { entity = detectCircle(context.getParserStack(), resource); if (entity != null) { return entity; OMElement root = AxiomUtils.getRootElement(in); entity = parseXml(root, resource, context); root.close(false);
/** * {@inheritDoc} */ @Override protected Object doInvoke(Context context) throws Exception { InputStream in = Parser.getResource(file, null).getInputStream(); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(in, out); return out.toString(encoding); } finally { IOUtils.closeQuietly(in); } }
public ResourceLocator getResourceLocator() { return parser.getResourceLocator(); }
private Object getUtilFunctions(String name, Context context) { for (ITagLibrary tagLib : context.getPaxml().getParser().getTagLibraries()) { Class<? extends IUtilFunctionsFactory> clazz = tagLib.getUtilFunctionsFactory(name); if (clazz != null) { return ReflectUtils.createObject(clazz).getUtilFunctions(context); } } return null; } }