View Javadoc

1   package com.terradue.jcatalogue.client.internal.digester;
2   
3   /*
4    *    Copyright 2011-2012 Terradue srl
5    *
6    *    Licensed under the Apache License, Version 2.0 (the "License");
7    *    you may not use this file except in compliance with the License.
8    *    You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *    Unless required by applicable law or agreed to in writing, software
13   *    distributed under the License is distributed on an "AS IS" BASIS,
14   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *    See the License for the specific language governing permissions and
16   *    limitations under the License.
17   */
18  
19  import static com.terradue.jcatalogue.client.internal.digester.Namespaces.ATOM;
20  import static com.terradue.jcatalogue.client.internal.digester.Namespaces.GML;
21  
22  import org.apache.commons.digester3.binder.AbstractNamespaceURIBasedRulesModule;
23  
24  import com.terradue.jcatalogue.client.DataSet;
25  import com.terradue.jcatalogue.client.geo.Box;
26  import com.terradue.jcatalogue.client.geo.Line;
27  import com.terradue.jcatalogue.client.geo.Point;
28  import com.terradue.jcatalogue.client.geo.Polygon;
29  
30  public final class DataSetRulesModule
31      extends AbstractNamespaceURIBasedRulesModule
32  {
33  
34      public DataSetRulesModule()
35      {
36          super( ATOM );
37      }
38  
39      @Override
40      protected void configure()
41      {
42          forPattern( "feed/entry" ).createObject().ofType( DataSet.class )
43                                    .then()
44                                    .setNext( "addDataSet" );
45          forPattern( "feed/entry/title" ).setBeanProperty();
46          forPattern( "feed/entry/subtitle" ).setBeanProperty();
47          forPattern( "feed/entry/published" ).setBeanProperty();
48          forPattern( "feed/entry/updated" ).setBeanProperty();
49          forPattern( "feed/entry/id" ).setBeanProperty();
50  
51          forPattern( "feed/entry/validTime/TimePeriod/beginPosition" )
52              .withNamespaceURI( GML )
53              .setBeanProperty().withName( "beginPosition" );
54          forPattern( "feed/entry/validTime/TimePeriod/endPosition" )
55              .withNamespaceURI( GML )
56              .setBeanProperty().withName( "endPosition" );
57  
58          forPattern( "feed/entry/where/Envelope" )
59              .withNamespaceURI( GML )
60              .createObject().ofType( Box.class );
61          forPattern( "feed/entry/where/Envelope/lowerCorner" )
62              .withNamespaceURI( GML )
63              .setBeanProperty().withName( "lowerCorner" );
64          forPattern( "feed/entry/where/Envelope/upperCorner" )
65              .withNamespaceURI( GML )
66              .setBeanProperty().withName( "upperCorner" );
67          forPattern( "feed/entry/where/LineString/posList" )
68              .withNamespaceURI( GML )
69              .addRuleCreatedBy( new SetGeoDataLocationRule.Factory( Line.class ) );
70          forPattern( "feed/entry/where/Polygon/exterior/LinearRing/posList" )
71              .withNamespaceURI( GML )
72              .addRuleCreatedBy( new SetGeoDataLocationRule.Factory( Polygon.class ) );
73          forPattern( "feed/entry/where/Point/pos" )
74              .withNamespaceURI( GML )
75              .addRuleCreatedBy( new SetGeoDataLocationRule.Factory( Point.class ) );
76  
77          forPattern( "feed/entry/link" ).callMethod( "addLink" )
78                                               .withParamTypes( String.class, String.class, String.class, Integer.class )
79                                               .then()
80                                               .callParam()
81                                                   .fromAttribute( "rel" )
82                                                   .ofIndex( 0 )
83                                                   .then()
84                                               .callParam()
85                                                   .fromAttribute( "type" )
86                                                   .ofIndex( 1 )
87                                                   .then()
88                                               .callParam()
89                                                   .fromAttribute( "href" )
90                                                   .ofIndex( 2 )
91                                                   .then()
92                                               .addRuleCreatedBy( new PriorityParamRule.PriorityParamRuleProvider( 3 ) );
93      }
94  
95  }