View Javadoc

1   /***
2    * ***************************************************************
3    * JADE - Java Agent DEvelopment Framework is a framework to develop
4    * multi-agent systems in compliance with the FIPA specifications.
5    * Copyright (C) 2000 CSELT S.p.A.
6    * 
7    * GNU Lesser General Public License
8    * 
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation,
12   * version 2.1 of the License.
13   * 
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   * 
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the
21   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22   * Boston, MA  02111-1307, USA.
23   * **************************************************************
24   */
25  package JADE_SL.schema;
26  
27  import JADE_SL.abs.*;
28  import JADE_SL.onto.*;
29  
30  /***
31   * @author Federico Bergenti - Universita` di Parma
32   */
33  public class PrimitiveSchema extends TermSchema {
34      public static final String         BASE_NAME = "Primitive";
35      private static PrimitiveSchema baseSchema = new PrimitiveSchema();
36  
37      /***
38       * Construct a schema that vinculates an entity to be a generic
39       * primitive element
40       */
41      private PrimitiveSchema() {
42          super(BASE_NAME);
43      }
44  
45      /***
46       * Creates a <code>PrimitiveSchema</code> with a given type-name.
47       *
48       * @param typeName The name of this <code>PrimitiveSchema</code>.
49       */
50      public PrimitiveSchema(String typeName) {
51          super(typeName);
52      }
53  
54      /***
55       * Retrieve the generic base schema for all primitives.
56       *
57       * @return the generic base schema for all primitives.
58       */
59      public static ObjectSchema getBaseSchema() {
60          return baseSchema;
61      } 
62  
63      /***
64       * Creates an Abstract descriptor to hold a primitive of
65       * the proper type.
66       */
67      public AbsObject newInstance() throws OntologyException {
68          return new AbsPrimitive(getTypeName());
69      } 
70  
71  		/***
72  	     Check whether a given abstract descriptor complies with this 
73  	     schema.
74  	     @param abs The abstract descriptor to be checked
75  	     @throws OntologyException If the abstract descriptor does not 
76  	     complies with this schema
77  	   */
78    	public void validate(AbsObject abs, Ontology onto) throws OntologyException {
79  			// Check the type of the abstract descriptor
80    		if (!(abs instanceof AbsPrimitive)) {
81  				throw new OntologyException(abs+" is not an AbsPrimitive");
82  			}
83    	}
84    	
85    	/***
86    	   Return true if 
87    	   - s is the base schema for the XXXSchema class this schema is
88    	     an instance of (e.g. s is ConceptSchema.getBaseSchema() and this 
89    	     schema is an instance of ConceptSchema)
90    	   - s is the base schema for a super-class of the XXXSchema class
91    	     this schema is an instance of (e.g. s is TermSchema.getBaseSchema()
92    	     and this schema is an instance of ConceptSchema)
93    	 */
94    	protected boolean descendsFrom(ObjectSchema s) {
95    		if (s != null) {
96    			if (s.equals(getBaseSchema())) {
97  	  			return true;
98    			}
99    			return super.descendsFrom(s);
100   		}
101   		else {
102   			return false;
103   		}
104   	}
105 }
106