/** * 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; } }
public void handleFatal(ValidationProblem prob) { LOG.log(Level.SEVERE, prob.getDescription()); }
/** * 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 error * @throws IOException error */ protected boolean loadCustomizations(String path) throws JiBXException, IOException { // load customizations and check for errors ProblemMultiHandler handler = new ProblemMultiHandler(); handler.addHandler(new ProblemConsoleLister()); handler.addHandler(new ProblemLogLister(s_logger)); m_customRoot = SchemasetCustom.loadCustomizations(path, handler); // set specified default package on root customization element if (m_defaultPackage != null) { m_customRoot.setPackage(m_defaultPackage); } return true; }
/** * 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; }
m_validationContext.clearTraversed(); s_logger.debug("Beginning schema prevalidation pass"); for (int i = 0; i < schemas.length; i++) { wlkr.walkSchema(schemas[i], new PrevalidationVisitor(m_validationContext)); s_logger.debug("After prevalidation schema " + schemas[i].getResolver().getName() + " has effective namespace " + schemas[i].getEffectiveNamespace()); 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)); s_logger.debug("After validation schema " + schemas[i].getResolver().getName() + " has effective namespace " + schemas[i].getEffectiveNamespace());
/** * Report problems using console output. This clears the problem list after they've been reported, to avoid multiple * reports of the same problems. * * @param vctx * @return <code>true</code> if one or more errors, <code>false</code> if not */ private static boolean reportProblems(ValidationContext vctx) { ArrayList probs = vctx.getProblems(); boolean error = false; if (probs.size() > 0) { for (int j = 0; j < probs.size(); j++) { ValidationProblem prob = (ValidationProblem)probs.get(j); String text; if (prob.getSeverity() >= ValidationProblem.ERROR_LEVEL) { error = true; text = "Error: " + prob.getDescription(); s_logger.error(text); } else { text = "Warning: " + prob.getDescription(); s_logger.info(text); } System.out.println(text); } } probs.clear(); return error; }
custom = (SchemaCustom)child; } else { vctx.addError("Multiple matches to schema " + name + " (first match " + ValidationProblem.componentDescription(custom) + ')', child);
vctx.addError("Missing required 'class' attribute", new ProblemLocation(ctx)); } else { try { return clas.newInstance(); } catch (InstantiationException e) { 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 ClassDecorator interface", new ProblemLocation(ctx)); vctx.addError("Unable to find class " + cname + " in classpath", new ProblemLocation(ctx));
/** * List the schemas in use. * * @param schemas * @param vctx * @param handler */ private static void listSchemas(SchemaElement[] schemas, ValidationContext vctx, ProblemHandler handler) { Set topset = new HashSet(); for (int i = 0; i < schemas.length; i++) { SchemaElement schema = schemas[i]; topset.add(schema); handler.report(" " + "top-level schema " + schema.getResolver().getName()); } for (Iterator iter = vctx.iterateSchemas(); iter.hasNext();) { SchemaElement schema = (SchemaElement)iter.next(); if (!topset.contains(schema)) { handler.report(" " + "referenced schema " + schema.getResolver().getName()); } } }
/** * 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(); }
/** * 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; }
/** * Report problems found in binding. * * @param vctx Validation Context * @param handler Problem Handler */ private static void reportBindingProblems(org.jibx.binding.model.ValidationContext vctx, ProblemHandler handler) { StringBuffer buff = new StringBuffer(); ArrayList problems = vctx.getProblems(); for (int i = 0; i < problems.size(); i++) { org.jibx.binding.model.ValidationProblem prob = (org.jibx.binding.model.ValidationProblem)problems.get(i); buff.setLength(0); buff.append(prob.getSeverity() >= org.jibx.binding.model.ValidationProblem.ERROR_LEVEL ? "Error: " : "Warning: "); buff.append(prob.getDescription()); handler.report(buff.toString()); } }
/** * Check if no-namespace namespace is used in any of the schemas. * * @return <code>true</code> if no-namespace used, <code>false</code> if not */ private boolean checkNoNamespacedUsed() { SchemaNameVisitor visitor = new SchemaNameVisitor(); TreeWalker walker = new TreeWalker(null, new SchemaContextTracker()); for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) { walker.walkSchema((SchemaElement)iter.next(), visitor); } return visitor.isNoNamespaceUsed(); }
public void handleWarning(ValidationProblem prob) { LOG.log(Level.WARNING, prob.getDescription()); }
owner = match; } else { m_validationContext.addError("schema-set overlap on schema " + name + " (first match " + ValidationProblem.componentDescription(owner) + ')', match);
/** * 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(); }
/** * 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; }
public void handleError(ValidationProblem prob) { LOG.log(Level.SEVERE, prob.getDescription()); }
owner = match; } else { m_validationContext.addError("schema-set overlap on schema " + name + " (first match " + ValidationProblem.componentDescription(owner) + ')', match);
public void handleUnimplemented(ValidationProblem prob) { LOG.log(Level.INFO, "Unimplemented feature - " + prob.getDescription()); }