Package org.apache.commons.digester

Examples of org.apache.commons.digester.Rule


    /**
     * Factory for creating a BeanPropertySetterRule.
     */
    private class BeanPropertySetterRuleFactory extends AbstractObjectCreationFactory {
        public Object createObject(Attributes attributes) throws Exception {
            Rule beanPropertySetterRule = null;
            String propertyname = attributes.getValue("propertyname");
               
            if (propertyname == null) {
                // call the setter method corresponding to the element name.
                beanPropertySetterRule = new BeanPropertySetterRule();
View Full Code Here


    /**
     * Factory for creating a CallMethodRule.
     */
    protected class CallMethodRuleFactory extends AbstractObjectCreationFactory {
        public Object createObject(Attributes attributes) {
            Rule callMethodRule = null;
            String methodName = attributes.getValue("methodname");
            if (attributes.getValue("paramcount") == null) {
                // call against empty method
                callMethodRule = new CallMethodRule(methodName);
           
View Full Code Here

        public Object createObject(Attributes attributes) {
            // create callparamrule
            int paramIndex = Integer.parseInt(attributes.getValue("paramnumber"));
            String attributeName = attributes.getValue("attrname");
            String fromStack = attributes.getValue("from-stack");
            Rule callParamRule = null;
            if (attributeName == null) {
                if (fromStack == null) {
               
                    callParamRule = new CallParamRule( paramIndex );
               
View Full Code Here

            int paramIndex = Integer.parseInt(attributes.getValue("paramnumber"));
            String attributeName = attributes.getValue("attrname");
            String type = attributes.getValue("type");
            String value = attributes.getValue("value");

            Rule objectParamRule = null;

            // type name is requried
            if (type == null) {
                throw new RuntimeException("Attribute 'type' is required.");
            }
View Full Code Here

        if ((rules != null) && (rules.size() > 0)) {
            Log log = digester.getLogger();
            boolean debug = log.isDebugEnabled();
            for (int i = 0; i < rules.size(); i++) {
                try {
                    Rule rule = (Rule) rules.get(i);
                    if (debug) {
                        log.debug("  Fire begin() for " + rule);
                    }
                    rule.begin(namespace, name, list);
                } catch (Exception e) {
                    throw digester.createSAXException(e);
                } catch (Error e) {
                    throw e;
                }
View Full Code Here

        if ((rules != null) && (rules.size() > 0)) {
            Log log = digester.getLogger();
            boolean debug = log.isDebugEnabled();
            for (int i = 0; i < rules.size(); i++) {
                try {
                    Rule rule = (Rule) rules.get(i);
                    if (debug) {
                        log.debug("  Fire body() for " + rule);
                    }
                    rule.body(namespaceURI, name, text);
                } catch (Exception e) {
                    throw digester.createSAXException(e);
                } catch (Error e) {
                    throw e;
                }
View Full Code Here

            Log log = digester.getLogger();
            boolean debug = log.isDebugEnabled();
            for (int i = 0; i < rules.size(); i++) {
                int j = (rules.size() - i) - 1;
                try {
                    Rule rule = (Rule) rules.get(j);
                    if (debug) {
                        log.debug("  Fire end() for " + rule);
                    }
                    rule.end(namespaceURI, name);
                } catch (Exception e) {
                    throw digester.createSAXException(e);
                } catch (Error e) {
                    throw e;
                }
View Full Code Here

     * working.
     */
    private void addOldArgRules(Digester digester) {

        // Create a new rule to process args elements
        Rule rule = new Rule() {
            public void begin(String namespace, String name,
                               Attributes attributes) throws Exception {
                // Create the Arg
                Arg arg = new Arg();
                arg.setKey(attributes.getValue("key"));
View Full Code Here

        digester.addCallMethod( "*/folder/description", "setDescription", 0 );
       
        // PhotoInfo mappings
        digester.addFactoryCreate( "*/photos/photo", new PhotoFactory() );
        // After the photo  is ready, inform listeners  if a new photo was created.
        digester.addRule( "*/photos/photo", new Rule() {
            public void end( String namespace, String name ) {
                Boolean isCreatingNew = (Boolean) digester.pop( STACK_CREATING_NEW );
                if ( isCreatingNew.booleanValue() ) {
                    photoCount++;
                    fireObjectImportedEvent( digester.peek() );
                }
            }
        });
        digester.addCallMethod( "*/photos/photo/shooting-place", "setShootingPlace", 0 );
        digester.addCallMethod( "*/photos/photo/photographer", "setPhotographer", 0 );
        digester.addCallMethod( "*/photos/photo/camera", "setCamera", 0 );
        digester.addCallMethod( "*/photos/photo/lens", "setLens", 0 );
        digester.addCallMethod( "*/photos/photo/film", "setFilm", 0 );
        digester.addCallMethod( "*/photos/photo/orig-fname", "setOrigFname", 0 );
        digester.addCallMethod( "*/photos/photo/description", "setDesc", 0 );
        digester.addCallMethod( "*/photos/photo/tech-notes", "setTechNotes", 0 );
        digester.addCallMethod( "*/photos/photo/f-stop", "setFStop", 0, new Class[] {Double.class} );
        digester.addCallMethod( "*/photos/photo/shutter-speed", "setShutterSpeed", 0, new Class[] {Double.class} );
        digester.addCallMethod( "*/photos/photo/focal-length", "setFocalLength", 0, new Class[] {Double.class} );
        digester.addCallMethod( "*/photos/photo/quality", "setQuality", 0, new Class[] {Integer.class} );
        digester.addCallMethod( "*/photos/photo/film-speed", "setFilmSpeed", 0, new Class[] {Integer.class} );
       
        digester.addFactoryCreate( "*/photos/photo/shoot-time", new FuzzyDateFactory() );
        digester.addSetNext( "*/photos/photo/shoot-time", "setFuzzyShootTime" );
       
        // Crop settings
        digester.addCallMethod( "*/photos/photo/crop", "setPrefRotation", 1, new Class[] {Double.class} );
        digester.addCallParam( "*/photos/photo/crop", 0, "rot" );
        digester.addFactoryCreate( "*/photos/photo/crop", new RectangleFactory() );
        digester.addSetNext( "*/photos/photo/crop", "setCropBounds" );
       
        /*
         Raw conversion setting mappings. All of these expect that a RawSettingsFactory
         is the topmost object in Digester stack. Note that in practice there must be
         and explicit rule for each raw setting field since the rule that
         instantates the raw setting object & assign it to the parent object will
         override this.
         */
        digester.addObjectCreate( "*/raw-conversion", RawSettingsFactory.class );
        digester.addCallMethod( "*/raw-conversion/whitepoint", "setWhite", 0, new Class[] {Integer.class} );
        digester.addCallMethod( "*/raw-conversion/blackpoint", "setBlack", 0, new Class[] {Integer.class} );
        digester.addCallMethod( "*/raw-conversion/ev-corr", "setEvCorr", 0, new Class[] {Double.class} );
        digester.addCallMethod( "*/raw-conversion/hlight-corr", "setHlightComp", 0, new Class[] {Double.class} );
        digester.addRule( "*/raw-conversion/color-balance", new Rule() {
            public void begin( String namespace, String name, Attributes attrs ) {
                String rgStr = attrs.getValue( "red-green-ratio" );
                String bgStr = attrs.getValue( "blue-green-ratio" );
                double bg = 1.0;
                double rg = 1.0;
                try {
                    bg = Double.parseDouble( bgStr );
                    rg = Double.parseDouble(rgStr);
                } catch (NumberFormatException ex) {
                    digester.createSAXException( ex );
                }
                RawSettingsFactory f = (RawSettingsFactory) digester.peek();
                f.setRedGreenRation( rg );           
                f.setBlueGreenRatio( bg );           
            }
        });
        digester.addRule( "*/raw-conversion/daylight-color-balance", new Rule() {
            public void begin( String namespace, String name, Attributes attrs ) {
                String rgStr = attrs.getValue( "red-green-ratio" );
                String bgStr = attrs.getValue( "blue-green-ratio" );
                double bg = 1.0;
                double rg = 1.0;
               
                try {
                    bg = Double.parseDouble( bgStr );
                    rg = Double.parseDouble(rgStr);
                } catch (NumberFormatException ex) {
                    digester.createSAXException( ex );
                }
                RawSettingsFactory f = (RawSettingsFactory) digester.peek();
                f.setDaylightMultipliers( new double[] {rg, 1.0, bg} );
            }
        });
        digester.addRuleSet( new ChannelMapRuleSet( "*/photo/") );
        digester.addRule( "*/photo/color-mapping", new Rule() {
            public void end( String namespace, String name ) {
                PhotoInfo p = (PhotoInfo) digester.peek(1);
                ChannelMapOperationFactory f =
                        (ChannelMapOperationFactory) digester.peek();
                p.setColorChannelMapping( f.create() );               
            }
        });
       
        digester.addObjectCreate( "*/photo/raw-conversion", RawSettingsFactory.class );
        digester.addRule( "*/photo/raw-conversion", new Rule() {
            public void end( String namespace, String name ) {
                PhotoInfo p = (PhotoInfo)digester.peek(1);
                RawSettingsFactory f = (RawSettingsFactory) digester.peek();
                try {
                    p.setRawSettings( f.create() );
                } catch (PhotovaultException ex) {
                    digester.createSAXException( ex );
                }
            }
        })
       
        // Instance mappings
        digester.addFactoryCreate( "*/photo/instances/instance", new InstanceFactory() );
        digester.addCallMethod( "*/instance/file-size", "setFileSize", 0, new Class[] {Long.class} );
        digester.addCallMethod( "*/instance/width", "setWidth", 0, new Class[] {Integer.class} );
        digester.addCallMethod( "*/instance/height", "setHeight", 0, new Class[] {Integer.class} );
        digester.addCallMethod( "*/instance/crop", "setRotated", 1, new Class[] {Double.class} );
        digester.addCallParam( "*/instance/crop", 0, "rot" );
        digester.addFactoryCreate( "*/instance/crop", new RectangleFactory() );
        digester.addSetNext( "*/instance/crop", "setCropBounds" );
        digester.addRule( "*/instance/hash", new Rule() {
            public void body( String namespace, String name, String text ) {
                byte[] hash = Base64.decode( text );
                ImageInstance i = (ImageInstance) digester.peek();
                i.setHash( hash );
            }
        } );
        digester.addRuleSet( new ChannelMapRuleSet( "*/instance/") );
        digester.addRule( "*/instance/color-mapping", new Rule() {
            public void end( String namespace, String name ) {
                ImageInstance i = (ImageInstance) digester.peek(1);
                ChannelMapOperationFactory f =
                        (ChannelMapOperationFactory) digester.peek();
                i.setColorChannelMapping( f.create() );               
            }
        });
        // Raw conversion parsing was already specified earlier. We just need a
        // method for binding the RawConversionSettings object to instance
        digester.addObjectCreate( "*/instance/raw-conversion", RawSettingsFactory.class );
        digester.addRule( "*/instance/raw-conversion", new Rule() {
            public void end( String namespace, String name ) {
                ImageInstance i = (ImageInstance)digester.peek(1);
                RawSettingsFactory f = (RawSettingsFactory) digester.peek();
                try {
                    i.setRawSettings( f.create() );
View Full Code Here

     @param d The digerster to which the rules will be added.
     */
    public void addRuleInstances(Digester d) {
        d.addObjectCreate( pathPrefix + "color-mapping", ChannelMapOperationFactory.class );
        d.addObjectCreate( pathPrefix + "color-mapping/channel", ColorCurve.class );
        d.addRule( pathPrefix + "color-mapping/channel", new Rule() {
            public void begin( String namespace, String name, Attributes attrs ) {
                String channelName = attrs.getValue( "name" );
                ChannelMapOperationFactory f = (ChannelMapOperationFactory) digester.peek( 1 );
                ColorCurve c = (ColorCurve) digester.peek();
                f.setChannelCurve( channelName, c );
View Full Code Here

TOP

Related Classes of org.apache.commons.digester.Rule

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.