Ignore:
Timestamp:
03/03/10 20:21:17 (14 years ago)
Author:
oschonef
Message:
  • implement basic search feature
File:
1 edited

Legend:

Unmodified
Added
Removed
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/query/EntityNode.java

    r190 r213  
    66
    77class EntityNode extends CommonTree implements ParseTreeNode {
    8         private String entity;
     8        public static enum Entity { VC, CREATOR };
     9        private Entity entity;
    910        private String property;
    1011       
    1112        public EntityNode(int type, Token entity, Token property) {
    1213                super(new CommonToken(type, "ENTITY"));
    13                 // check values for sanity!
    14                 this.entity   = entity.getText();
    15                 this.property = property.getText();
     14                this.entity    = entityFromString(entity.getText());
     15                this.property  = propertyFromString(property.getText());
    1616        }
    1717
    18         public String getEntity() {
     18        public Entity getEntity() {
    1919                return entity;
    2020        }
     
    2828        }
    2929
     30        private static Entity entityFromString(String s) {
     31                if (s == null) {
     32                        throw new NullPointerException("s == null");
     33                }
     34                s = s.trim();
     35                if (s.equalsIgnoreCase("vc")) {
     36                         return Entity.VC;
     37                } else if (s.equalsIgnoreCase("creator")) {
     38                        return Entity.CREATOR;
     39                } else {
     40                        throw new IllegalArgumentException("unknown entity: " + s);
     41                }
     42        }
     43
     44        private static String propertyFromString(String s) {
     45                if (s != null) {
     46                        s = s.trim();
     47                }
     48                if ((s == null) || (s.length() < 1)) {
     49                        throw new IllegalArgumentException("property is null or empty");
     50                }
     51                return s.toLowerCase();
     52        }
     53       
    3054} // class EntityNode
Note: See TracChangeset for help on using the changeset viewer.