|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
CreateObjectRule.java | - | 100% | 100% | 100% |
|
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><create-object></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 _className; | |
31 | ||
32 | 3828 | public CreateObjectRule() |
33 | { | |
34 | } | |
35 | ||
36 | 524 | public CreateObjectRule(String className) |
37 | { | |
38 | 524 | _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 | 5867 | public void begin(SchemaProcessor processor, Element element) |
47 | { | |
48 | 5867 | Object object = InstanceCreationUtils.createInstance( |
49 | processor.getDefiningModule(), | |
50 | _className, | |
51 | element.getLocation()); | |
52 | ||
53 | 5867 | processor.push(object); |
54 | } | |
55 | ||
56 | /** | |
57 | * Pops the object off of the processor's stack. | |
58 | */ | |
59 | 5866 | public void end(SchemaProcessor processor, Element element) |
60 | { | |
61 | 5866 | processor.pop(); |
62 | } | |
63 | ||
64 | 82 | public String getClassName() |
65 | { | |
66 | 82 | return _className; |
67 | } | |
68 | ||
69 | 3828 | public void setClassName(String string) |
70 | { | |
71 | 3828 | _className = string; |
72 | } | |
73 | ||
74 | } |
|