/** * Load the customizations file. This method must load the specified customizations file, or create a default * customizations instance, of the appropriate type. * * @param path customization file path * @return <code>true</code> if successful, <code>false</code> if an error * @throws JiBXException JiBX error * @throws IOException I/O error */ protected boolean loadCustomizations(String path) throws JiBXException, IOException { // load customizations and check for errors String[] spaths = (String[])m_sourcePaths.toArray(new String[m_sourcePaths.size()]); ValidationContext vctx = new ValidationContext(); loadCustomizations(path, new ClassSourceLocator(spaths), vctx); ArrayList probs = vctx.getProblems(); if (probs.size() > 0) { for (int i = 0; i < probs.size(); i++) { ValidationProblem prob = (ValidationProblem)probs.get(i); System.out.print(prob.getSeverity() >= ValidationProblem.ERROR_LEVEL ? "Error: " : "Warning: "); System.out.println(prob.getDescription()); } if (vctx.getErrorCount() > 0 || vctx.getFatalCount() > 0) { return false; } } return true; }
} catch (IllegalArgumentException e) { /* ignore failure */ } catch (InvocationTargetException e) { vctx.addWarning("Failed passing existing name converter to constructor for class " + cname + ": " + e.getMessage(), new ProblemLocation(ctx)); vctx.addError("Error creating instance of class " + cname + ": " + e.getMessage(), new ProblemLocation(ctx)); } catch (IllegalAccessException e) { vctx.addError("Unable to access constructor for class " + cname + ": " + e.getMessage(), new ProblemLocation(ctx)); vctx.addError("Class " + cname + " does not implement the required NameConverter interface", new ProblemLocation(ctx)); vctx.addError("Unable to find class " + cname + " in classpath", new ProblemLocation(ctx));
for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) { SchemaElement schema = (SchemaElement)iter.next(); int count = schema.getChildCount(); m_validationContext.clearTraversed(); boolean modified = false; for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) { SchemaElement schema = (SchemaElement)iter.next(); m_validationContext.enterSchema(schema); s_logger.debug("Applying extensions to schema " + ++index + ": " + schema.getResolver().getName()); int count = schema.getChildCount(); modified = true; m_validationContext.exitSchema();
ValidationContext vctx = new ValidationContext(); ValidationUtils.load(resolves, null, vctx); ProblemMultiHandler handler = new ProblemMultiHandler(); handler.addHandler(new ProblemConsoleLister()); handler.addHandler(new ProblemLogLister(s_logger)); if (vctx.reportProblems(handler)) { System.exit(2); TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker()); for (Iterator iter = resolves.iterator(); iter.hasNext();) { SchemaElement schema = vctx.getSchemaById(((ISchemaResolver)iter.next()).getId()); exists.add(schema); final SchemaHolder holder = new SchemaHolder(schema);
/** * Set the list of facet elements to be enforced. * * @param facets facets * @param ictx Unmarshalling Context */ public void setEnforcedFacets(String[] facets, IUnmarshallingContext ictx) { ValidationContext vctx = (ValidationContext)ictx.getUserContext(); long mask = 0; if (facets != null) { for (int i = 0; i < facets.length; i++) { String facet = facets[i]; int index = Arrays.binarySearch(FacetElement.FACET_ELEMENT_NAMES, facet); if (index >= 0) { mask |= SchemaBase.ELEMENT_MASKS[FacetElement.FACET_ELEMENT_INDEXES[index]]; } else { vctx.addError("'" + facet + "' is not a facet name", this); } } } m_enforcedFacetsMask = mask; }
ValidationContext vctx = new ValidationContext(); if (path == null) { custom = new SchemasetCustom((SchemasetCustom)null); if (vctx.reportProblems(handler)) { return null;
schema.setResolver(resolver); String id = resolver.getId(); m_validationContext.setSchema(id, schema); m_validationContext.clearTraversed(); for (int i = 0; i < count; i++) { SchemaElement schema = schemas[i];
ItemVisitor itembuilder = new ItemVisitor(); int index = 0; for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) { SchemaElement schema = (SchemaElement)iter.next(); m_validationContext.enterSchema(schema); s_logger.info("Building item structure for schema " + ++index + ": " + schema.getResolver().getName()); int count = schema.getChildCount();
/** * Set name converter to be used. * * @param nconv * @param ictx */ private void setNameConverter(NameConverter nconv, IUnmarshallingContext ictx) { if (nconv != null) { if (m_nameConverter != null) { ValidationContext vctx = (ValidationContext)ictx.getUserContext(); vctx.addWarning("Repeated 'name-converter' element overrides previous setting", new ProblemLocation(ictx)); } m_nameConverter = nconv; } }
/** * Constructor. * * @param global schema customization root element * @param root URL for base of schema paths * @param target destination directory for code generation */ public CodeGen(SchemasetCustom global, URL root, File target) { m_global = global; addDefaultSubstitutions(m_global); m_targetDir = target; m_validationContext = new ValidationContext(); }
m_validationContext.clearTraversed(); s_logger.debug("Beginning schema prevalidation pass"); for (int i = 0; i < schemas.length; i++) { m_validationContext.clearTraversed(); for (int i = 0; i < schemas.length; i++) { wlkr.walkSchema(schemas[i], new NameRegistrationVisitor(m_validationContext)); m_validationContext.clearTraversed(); for (int i = 0; i < schemas.length; i++) { wlkr.walkSchema(schemas[i], new NameMergeVisitor(m_validationContext)); m_validationContext.clearTraversed(); for (int i = 0; i < schemas.length; i++) { wlkr.walkSchema(schemas[i], new ValidationVisitor(m_validationContext));
QName group = element.getSubstitutionGroup(); if (group != null) { ElementElement base = m_validationContext.findElement(group); DefinitionItem basedef = ((GlobalExtension)base.getExtension()).getDefinition(); mapping.setExtendsName(basedef.getGenerateClass().getFullName()); ElementElement base = m_validationContext.findElement(group); DefinitionItem basedef = ((GlobalExtension)base.getExtension()).getDefinition(); elmapping.setExtendsName(basedef.getGenerateClass().getFullName());
for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) { SchemaElement schema = (SchemaElement)iter.next(); int count = schema.getChildCount(); m_validationContext.clearTraversed(); boolean modified = false; for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) { SchemaElement schema = (SchemaElement)iter.next(); m_validationContext.enterSchema(schema); s_logger.debug("Applying extensions to schema " + ++index + ": " + schema.getResolver().getName()); int count = schema.getChildCount(); modified = true; m_validationContext.exitSchema();
/** * Set the list of facet elements to be ignored. * * @param facets Facets * @param ictx Unmarshalling Context */ public void setIgnoredFacets(String[] facets, IUnmarshallingContext ictx) { ValidationContext vctx = (ValidationContext)ictx.getUserContext(); long mask = 0; if (facets != null) { for (int i = 0; i < facets.length; i++) { String facet = facets[i]; int index = Arrays.binarySearch(FacetElement.FACET_ELEMENT_NAMES, facet); if (index >= 0) { mask |= SchemaBase.ELEMENT_MASKS[FacetElement.FACET_ELEMENT_INDEXES[index]]; } else { vctx.addError("'" + facet + "' is not a facet name", this); } } } m_ignoredFacetsMask = mask; }
/** * Evaluate the remaining path for a customization after the first step, and apply it to the extension for each * matching schema component. If no matches are found or multiple matches are found this generates a warning. * * @param path customization path * @param match starting point for path * @param custom customization information * @param vctx validation context */ private static void applyRemainingCustomizationPath(SchemaPath path, OpenAttrBase match, ComponentCustom custom, ValidationContext vctx) { List matches = path.partialMatchMultiple(1, path.getPathLength()-1, match); if (matches.size() == 0) { vctx.addWarning("No matches found for customization expression", custom); } else { if (matches.size() > 1) { vctx.addWarning("Found " + matches.size() + " matches for customization expression", custom); } for (Iterator iter = matches.iterator(); iter.hasNext();) { OpenAttrBase target = (OpenAttrBase)iter.next(); custom.apply((ComponentExtension)target.getExtension(), vctx); } } }
/** * Constructor. * * @param parms command line parameters */ public Refactory(RefactoryCommandLine parms) { m_global = parms.getCustomRoot(); m_global.setSubstitutions(DEFAULT_REPLACEMENTS); m_schemaRoot = parms.getSchemaRoot(); m_schemaDir = parms.getSchemaDir(); m_targetDir = parms.getGeneratePath(); m_validationContext = new ValidationContext(); }
org.jibx.schema.validation.ValidationContext vctx = new org.jibx.schema.validation.ValidationContext(); for (int i = 0; i < holders.size(); i++) { SchemaHolder holder = (SchemaHolder)holders.get(i); SchemaElement schema = holder.getSchema(); schema.setResolver(new MemoryResolver(id)); vctx.setSchema(id, schema); vctx.setSchema(schema.getResolver().getName(), schema); ArrayList probs = vctx.getProblems(); if (probs.size() > 0) { for (int j = 0; j < probs.size(); j++) { System.out.println(prob.getDescription()); if ((vctx.getErrorCount() > 0 || vctx.getFatalCount() > 0)) { throw new RuntimeException("Errors found in generated schemas");
vctx.addError("Undefined attribute " + name, ictx.getStackTop()); vctx.addError("Undefined attribute " + name, ictx.getStackTop()); vctx.addWarning("Non-WSDL attribute not allowed " + qname, ictx.getStackTop());