KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > schema > rules > CreateObjectRule


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.schema.rules;
16
17 import org.apache.hivemind.Element;
18 import org.apache.hivemind.schema.SchemaProcessor;
19 import org.apache.hivemind.util.InstanceCreationUtils;
20
21 /**
22  * Basic {@link org.apache.hivemind.schema.Rule} for creating a new object. Created from the the
23  * <code>&lt;create-object&gt;</code> element. Generally, this is the first rule in a sequence of
24  * rules.
25  *
26  * @author Howard Lewis Ship
27  */

28 public class CreateObjectRule extends BaseRule
29 {
30     private String JavaDoc _className;
31
32     public CreateObjectRule()
33     {
34     }
35
36     public CreateObjectRule(String JavaDoc className)
37     {
38         _className = className;
39     }
40
41     /**
42      * Creates the new object and pushes it onto the processor's stack. If the object implement
43      * {@link org.apache.hivemind.LocationHolder} then the {@link org.apache.hivemind.Location} of
44      * the element is assigned to the object.
45      */

46     public void begin(SchemaProcessor processor, Element element)
47     {
48         Object JavaDoc object = InstanceCreationUtils.createInstance(
49                 processor.getDefiningModule(),
50                 _className,
51                 element.getLocation());
52
53         processor.push(object);
54     }
55
56     /**
57      * Pops the object off of the processor's stack.
58      */

59     public void end(SchemaProcessor processor, Element element)
60     {
61         processor.pop();
62     }
63
64     public String JavaDoc getClassName()
65     {
66         return _className;
67     }
68
69     public void setClassName(String JavaDoc string)
70     {
71         _className = string;
72     }
73
74 }
Popular Tags