/** * 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 a collection of resources. * * @param resourcesToAdd * the resource collection. */ public void addResources(Collection<PaxmlResource> resourcesToAdd) { for (PaxmlResource res : resourcesToAdd) { addResource(res); } }
/** * Get paxml entity by name, triggering the parse if needed. * * @param name * the tag name * @return the parsed entity, or null if not found. */ public IEntity getEntity(String name) { return parser.getResourceLocator().getEntity(name, 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); }
/** * Inspect a parsed paxml entity. * * @param name * the name of the paxml entity * @return the printed xml tree in string. */ public String inspectEntity(String name) { AbstractTag tag = ((AbstractTag) parser.getResourceLocator().getEntity(name, null)); if (tag == null) { throw new PaxmlRuntimeException("No resource found from locator: " + parser.getResourceLocator().getResourceNames()); } return tag.printTree(0); }
/** * {@inheritDoc} */ @Override protected Object doInvoke(Context context) { Object val = getValue(); String entityName = val == null ? null : val.toString().trim(); if (StringUtils.isBlank(entityName)) { val = getEntity().printTree(0); } else { ResourceLocator locator = getResourceLocator(); PaxmlResource res = locator.getResource(entityName); val = getResourceLocator().getEntity(entityName, null); } return val; }
public Parser getParser() { return locator.getParser(); }
public static Set<PaxmlResource> findResources(String base, Set<String> includes, Set<String> excludes) { if (includes == null) { includes = new HashSet<String>(1); includes.add("**/*.*"); } if (excludes == null) { excludes = Collections.EMPTY_SET; } if (StringUtils.isEmpty(base)) { base = PaxmlUtils.getCurrentDir().getAbsolutePath(); } File f = new File(base); if (f.isDirectory()) { f = new File(f, "fake.file"); } Resource baseRes = new FileSystemResource(f).getSpringResource(); Set<PaxmlResource> include = new LinkedHashSet<PaxmlResource>(0); Set<PaxmlResource> exclude = new LinkedHashSet<PaxmlResource>(0); ResourceMatcher matcher = new ResourceMatcher(includes, excludes); for (String pattern : matcher.include) { include.addAll(ResourceLocator.findResources(pattern, baseRes)); } for (String pattern : matcher.exclude) { exclude.addAll(ResourceLocator.findResources(pattern, baseRes)); } include.removeAll(exclude); return include; }
/** * Add a static config to this. * * @param config * the config */ public void addStaticConfig(StaticConfig config) { // add resources getResourceLocator().addResources(config.getResources()); // add tag libs for (Class<? extends ITagLibrary> lib : config.getTagLibs()) { addTagLibrary(lib); } // add listeners for (Class<? extends IExecutionListener> lis : config.getExecutionListeners()) { addPaxmlExecutionListener(ReflectUtils.createObject(lis)); } for (Class<? extends IEntityExecutionListener> lis : config.getEntityListeners()) { addEntityExecutionListener(ReflectUtils.createObject(lis)); } for (Class<? extends ITagExecutionListener> lis : config.getTagListeners()) { addTagExecutionListener(ReflectUtils.createObject(lis)); } }
if (!springPattern.startsWith("file:") && !springPattern.startsWith("classpath:") && !springPattern.startsWith("classpath*:")) { springPattern = getRelativeResource(baseFile, springPattern);
if (forceRefresh || (cached = this.resourceLocator.getCachedPaxmlEntities().get(resource)) == null || cached.isModified()) { resourceLocator.getCachedPaxmlEntities().put(resource, entity);
private static Class<? extends ITag> getTagImplFromResources(ParserContext context, String ns, String tagName) { Class<? extends ITag> clazz = null; ResourceLocator locator = context.getLocator(); // search from resources PaxmlResource tagRes = locator.getResource(tagName); if (tagRes == null) { // this tag is unknown, regarded as a const tag clazz = ConstTag.class; } else { // this is a xml defined tag, create a file invoker clazz = FileInvokerTag.class; context.setResource(tagRes); } return clazz; }
/** * Inspect a parsed paxml entity. * * @param name * the name of the paxml entity * @return the printed xml tree in string. */ public String inspectEntity(String name) { AbstractTag tag = ((AbstractTag) parser.getResourceLocator().getEntity(name, null)); if (tag == null) { throw new PaxmlRuntimeException("No resource found from locator: " + parser.getResourceLocator().getResourceNames()); } return tag.printTree(0); }
/** * {@inheritDoc} */ @Override protected Object doInvoke(Context context) { Object val = getValue(); String entityName = val == null ? null : val.toString().trim(); if (StringUtils.isBlank(entityName)) { val = getEntity().printTree(0); } else { ResourceLocator locator = getResourceLocator(); PaxmlResource res = locator.getResource(entityName); val = getResourceLocator().getEntity(entityName, null); } return val; }
public Parser getParser() { return locator.getParser(); }
private void buildResources(OMElement root, boolean detach) { for (OMElement ele : AxiomUtils.getElements(root, "resource")) { ResourceMatcher matcher = parseIncludeAndExclude(ele); Set<PaxmlResource> include = new LinkedHashSet<PaxmlResource>(0); Set<PaxmlResource> exclude = new LinkedHashSet<PaxmlResource>(0); for (String pattern : matcher.include) { include.addAll(ResourceLocator.findResources(pattern, planFile)); } for (String pattern : matcher.exclude) { exclude.addAll(ResourceLocator.findResources(pattern, planFile)); } include.removeAll(exclude); final PaxmlResource planFileResource; try { planFileResource = PaxmlResource.createFromPath(planFile.getURI().toString()); } catch (IOException e) { throw new PaxmlRuntimeException(e); } include.remove(planFileResource); model.getConfig().getResources().addAll(include); if (detach) { ele.detach(); } } }
/** * Add a static config to this. * * @param config * the config */ public void addStaticConfig(StaticConfig config) { // add resources getResourceLocator().addResources(config.getResources()); // add tag libs for (Class<? extends ITagLibrary> lib : config.getTagLibs()) { addTagLibrary(lib); } // add listeners for (Class<? extends IExecutionListener> lis : config.getExecutionListeners()) { addPaxmlExecutionListener(ReflectUtils.createObject(lis)); } for (Class<? extends IEntityExecutionListener> lis : config.getEntityListeners()) { addEntityExecutionListener(ReflectUtils.createObject(lis)); } for (Class<? extends ITagExecutionListener> lis : config.getTagListeners()) { addTagExecutionListener(ReflectUtils.createObject(lis)); } }
if (!springPattern.startsWith("file:") && !springPattern.startsWith("classpath:") && !springPattern.startsWith("classpath*:")) { springPattern = getRelativeResource(baseFile, springPattern);
if (forceRefresh || (cached = this.resourceLocator.getCachedPaxmlEntities().get(resource)) == null || cached.isModified()) { resourceLocator.getCachedPaxmlEntities().put(resource, entity);
/** * 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); }