Package org.jibx.schema.validation

Examples of org.jibx.schema.validation.ProblemLocation


     */
    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;
        }
    }
View Full Code Here


        // get the class to be used for class decorator instance
        ValidationContext vctx = (ValidationContext)ictx.getUserContext();
        UnmarshallingContext ctx = (UnmarshallingContext)ictx;
        String cname = ctx.attributeText(null, "class", null);
        if (cname == null) {
            vctx.addError("Missing required 'class' attribute", new ProblemLocation(ctx));
        } else {
            try {
               
                // make sure the class implements the required interface
                Class clas = SchemaRootBase.class.getClassLoader().loadClass(cname);
                if (ClassDecorator.class.isAssignableFrom(clas)) {
                    vctx.addError("Class " + cname + " does not implement the required IClassDecorator interface",
                        new ProblemLocation(ictx));
                } else {
                    try {
                        return (ClassDecorator)clas.newInstance();
                    } catch (InstantiationException e) {
                        vctx.addError("Error creating instance of class " + cname + ": " + e.getMessage(),
                            new ProblemLocation(ictx));
                    } catch (IllegalAccessException e) {
                        vctx.addError("Unable to access constructor for class " + cname + ": " + e.getMessage(),
                            new ProblemLocation(ictx));
                    }
                }
               
            } catch (ClassNotFoundException e) {
                vctx.addError("Unable to find class " + cname + " in classpath", new ProblemLocation(ictx));
            }
        }
        return null;
    }
View Full Code Here

                    if (ctx.getAttributeNamespace(i).length() == 0) {
                        if (!"class".equals(name)) {
                            map.put(name, value);
                        }
                    } else {
                        vctx.addError("Unknown namespaced attribute '" + name + "'", new ProblemLocation(ctx));
                    }
                }
               
                // create and populate values on instance
                try {
                    ReflectionUtilities.applyKeyValueMap(map, obj);
                } catch (IllegalArgumentException e) {
                    vctx.addError(e.getMessage(), new ProblemLocation(ctx));
                }
            }
           
            // skip element and return unmarshalled decorator instance
            ctx.skipElement();
View Full Code Here

                                try {
                                    return cons.newInstance(new Object[] { prior });
                                } 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));
                                }
                               
                            } catch (SecurityException e) { /* ignore failure */
                            } catch (NoSuchMethodException e) { /* ignore failure */ }
                        }
                       
                        // just create instance using no-argument constructor
                        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));
                    }
                } else {
                    vctx.addError("Class " + cname + " does not implement the required NameConverter interface",
                        new ProblemLocation(ctx));
                }
               
            } catch (ClassNotFoundException e) {
                vctx.addError("Unable to find class " + cname + " in classpath", new ProblemLocation(ctx));
            }
            return null;
        }
View Full Code Here

        protected Object createInstance(String cname, UnmarshallingContext ctx) {
           
            // check class to be used for class decorator instance
            ValidationContext vctx = (ValidationContext)ctx.getUserContext();
            if (cname == null) {
                vctx.addError("Missing required 'class' attribute", new ProblemLocation(ctx));
            } else {
                try {
                   
                    // make sure the class implements the required interface
                    Class clas = SchemaRootBase.class.getClassLoader().loadClass(cname);
                    if (ClassDecorator.class.isAssignableFrom(clas)) {
                        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));
                        }
                    } else {
                        vctx.addError("Class " + cname + " does not implement the required ClassDecorator interface",
                            new ProblemLocation(ctx));
                    }
                   
                } catch (ClassNotFoundException e) {
                    vctx.addError("Unable to find class " + cname + " in classpath", new ProblemLocation(ctx));
                }
            }
            return null;
        }
View Full Code Here

               
            } else {
               
                // report a validation error for unsupported element
                ValidationContext vctx = (ValidationContext)ictx.getUserContext();
                vctx.addFatal("No customizations allowed", new ProblemLocation(ictx));
               
            }
        } else {
           
            // report a validation error for unknown element
            ValidationContext vctx = (ValidationContext)ictx.getUserContext();
            vctx.addFatal("Unknown element", new ProblemLocation(ictx));
           
        }
        ctx.skipElement();
        return null;
    }
View Full Code Here

TOP

Related Classes of org.jibx.schema.validation.ProblemLocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.