@Override protected T parse(DeploymentUnit unit, String name, T root) throws Exception { if (ignoreName(unit, name)) return null; // Try to find the metadata VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit; VirtualFile file = getMetadataFile(vfsDeploymentUnit, getOutput(), name, true); return (file != null && ignoreFile(vfsDeploymentUnit, file) == false) ? parseAndInit(vfsDeploymentUnit, file, root) : null; }
/** * Parse the file, initialize the result if exists. * * @param unit the deployment unit * @param file the file * @param root the root * @param checkIgnore do we check for ignored names * @return parsed result * @throws Exception for any error */ protected T parseAndInit(VFSDeploymentUnit unit, VirtualFile file, T root, boolean checkIgnore) throws Exception { if (checkIgnore && ignoreFile(unit, file)) return null; T result = parse(unit, file, root); if (result != null) init(unit, result, file); return result; }
/** * Match file name to metadata class. * * @param unit the deployment unit * @param fileName the file name * @return matching metadata class */ protected Class<?> matchFileToClass(DeploymentUnit unit, String fileName) { Map<String, Class<?>> altMappingsMap = getAltMappings(unit); return altMappingsMap != null ? altMappingsMap.get(fileName) : null; }
@Override protected T parse(DeploymentUnit unit, String name, T root) throws Exception { // Try to find the metadata VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit; VirtualFile file = vfsDeploymentUnit.getMetaDataFile(name); if (file == null) return null; T result = parse(vfsDeploymentUnit, file, root); if (result != null) init(vfsDeploymentUnit, result, file); return result; }
@Override protected T parse(DeploymentUnit unit, String name, String suffix, T root) throws Exception { // Should we include the deployment // The infrastructure will only check leafs anyway so no need to check here if (name == null && isIncludeDeploymentFile()) name = unit.getName(); // Try to find the metadata VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit; // let's check altDD first VirtualFile file = getMetadataFile(vfsDeploymentUnit, getOutput(), name, false); if (file != null) return parseAndInit(vfsDeploymentUnit, file, root, true); // try all name+suffix matches List<VirtualFile> files = vfsDeploymentUnit.getMetaDataFiles(name, suffix, getMetaDataTypeFilter(unit)); switch (files.size()) { case 0 : return null; case 1 : return parseAndInit(vfsDeploymentUnit, files.get(0), root, true); default : return handleMultipleFiles(vfsDeploymentUnit, root, files); } }
/** * Handle multiple files. * * @param unit the vfs deployment unit * @param root possibly null pre-existing root * @param files the matching files * @return null or merged single result * @throws Exception for any error */ protected T handleMultipleFiles(VFSDeploymentUnit unit, T root, List<VirtualFile> files) throws Exception { if (allowsMultipleFiles(files) == false) throw new IllegalArgumentException("Multiple matching files not allowed: " + files); for (VirtualFile file : files) { if (ignoreFile(unit, file) == false) { T result = parse(unit, file, root); if (result != null) { init(unit, result, file); unit.addAttachment(file.toURL().toString(), result, getOutput()); } } } return null; }
if (ignoreName(unit, name)) VirtualFile file = getMetadataFile(vfsDeploymentUnit, matchFileToClass(unit, name), name, true); if (file != null) if (ignoreFile(vfsDeploymentUnit, file)) ignoredFiles.add(file.getName()); else return null; return mergeFiles(vfsDeploymentUnit, root, files, missingFiles);
@Override protected T parse(DeploymentUnit unit, String name, String suffix, T root) throws Exception { // Should we include the deployment // The infrastructure will only check leafs anyway so no need to check here if (name == null && isIncludeDeploymentFile()) name = unit.getName(); // Try to find the metadata VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit; List<VirtualFile> files = vfsDeploymentUnit.getMetaDataFiles(name, suffix); if (files.size() == 0) return null; // TODO JBMICROCONT-184 remove this limitation if (files.size() > 1) throw new DeploymentException("Only one file is allowed, found=" + files); VirtualFile file = files.get(0); T result = parse(vfsDeploymentUnit, file, root); if (result != null) init(vfsDeploymentUnit, result, file); return result; }
@Override protected boolean accepts(DeploymentUnit unit) throws DeploymentException { // Ignore non-vfs deployments if (unit instanceof VFSDeploymentUnit == false) { log.trace("Not a vfs deployment: " + unit.getName()); return false; } return accepts((VFSDeploymentUnit) unit); }
public void create() throws Exception { Class<?>[] classes = {super.getOutput()}; context = JAXBContext.newInstance(classes); }
/** * Get metadata file. * First try altDD, then fallback to original name. * * @param unit the vfs deployment unit * @param altExpectedClass the expected class of altDD * @param originalName the original file name * @param checkMetaDataFile should we fall back to metadata file * @return metadata file or null if it doesn't exist */ protected VirtualFile getMetadataFile(VFSDeploymentUnit unit, Class<?> altExpectedClass, String originalName, boolean checkMetaDataFile) { String altPrefix = (altExpectedClass != null ? altExpectedClass.getName() : originalName); VirtualFile file = unit.getAttachment(altPrefix + ".altDD", VirtualFile.class); if (file != null && altExpectedClass != null) { Map<String, Class<?>> altMappingsMap = getAltMappings(unit); if (altMappingsMap == null) { altMappingsMap = new HashMap<String, Class<?>>(); unit.addAttachment(ALT_MAPPINGS_MAP_KEY, altMappingsMap, Map.class); } altMappingsMap.put(file.getName(), altExpectedClass); } if(checkMetaDataFile && file == null) file = unit.getMetaDataFile(originalName, getMetaDataTypeFilter(unit)); return file; }
NameIgnoreMechanism mechanism = getNameIgnoreMechanism(); if (mechanism != null)
if (ignoreName(unit, name)) VirtualFile file = getMetadataFile(vfsDeploymentUnit, matchFileToClass(unit, name), name, false); if (file == null) List<VirtualFile> matched = vfsDeploymentUnit.getMetaDataFiles(name, suffix, getMetaDataTypeFilter(unit)); if (matched != null && matched.isEmpty() == false) if (ignoreFile(vfsDeploymentUnit, m)) ignoredFiles.add(m.getName()); else missingFiles.add(name); else if (ignoreFile(vfsDeploymentUnit, file)) return null; return mergeFiles(vfsDeploymentUnit, root, files, missingFiles);
@Override protected boolean accepts(DeploymentUnit unit) throws DeploymentException { // Ignore non-vfs deployments if (unit instanceof VFSDeploymentUnit == false) { if (log.isTraceEnabled()) log.trace("Not a vfs deployment: " + unit.getName()); return false; } return accepts((VFSDeploymentUnit) unit); }