|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
CreateObjectRule.java | - | 91.7% | 100% | 94.4% |
|
1 |
// Copyright 2004 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.ApplicationRuntimeException;
|
|
18 |
import org.apache.hivemind.ClassResolver;
|
|
19 |
import org.apache.hivemind.Element;
|
|
20 |
import org.apache.hivemind.HiveMind;
|
|
21 |
import org.apache.hivemind.schema.SchemaProcessor;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* Basic {@link org.apache.hivemind.schema.Rule} for creating
|
|
25 |
* a new object. Created from the
|
|
26 |
* the <code><create-object></code> element. Generally, this
|
|
27 |
* is the first rule in a sequence of rules.
|
|
28 |
*
|
|
29 |
* @author Howard Lewis Ship
|
|
30 |
*/
|
|
31 |
public class CreateObjectRule extends BaseRule |
|
32 |
{ |
|
33 |
private String _className;
|
|
34 |
|
|
35 | 2019 |
public CreateObjectRule()
|
36 |
{ |
|
37 |
} |
|
38 |
|
|
39 | 323 |
public CreateObjectRule(String className)
|
40 |
{ |
|
41 | 323 |
_className = className; |
42 |
} |
|
43 |
|
|
44 |
/**
|
|
45 |
* Creates the new object and pushes it onto the processor's stack. If the
|
|
46 |
* object implement {@link LocationHolder} then
|
|
47 |
* the {@link org.apache.hivemind.Location} of the element is assigned
|
|
48 |
* to the object.
|
|
49 |
*/
|
|
50 | 2795 |
public void begin(SchemaProcessor processor, Element element) |
51 |
{ |
|
52 | 2795 |
ClassResolver resolver = processor.getContributingModule().getClassResolver(); |
53 | 2795 |
Object object = null;
|
54 |
|
|
55 | 2795 |
try
|
56 |
{ |
|
57 | 2795 |
Class objectClass = resolver.findClass(_className); |
58 |
|
|
59 | 2795 |
object = objectClass.newInstance(); |
60 |
|
|
61 |
} |
|
62 |
catch (Exception ex)
|
|
63 |
{ |
|
64 | 0 |
throw new ApplicationRuntimeException( |
65 |
RulesMessages.errorCreatingObject(_className, getLocation(), ex), |
|
66 |
getLocation(), |
|
67 |
ex); |
|
68 |
} |
|
69 |
|
|
70 | 2795 |
HiveMind.setLocation(object, element.getLocation()); |
71 |
|
|
72 | 2795 |
processor.push(object); |
73 |
} |
|
74 |
|
|
75 |
/**
|
|
76 |
* Pops the object off of the processor's stack.
|
|
77 |
*/
|
|
78 | 2794 |
public void end(SchemaProcessor processor, Element element) |
79 |
{ |
|
80 | 2794 |
processor.pop(); |
81 |
} |
|
82 |
|
|
83 | 1 |
public String getClassName()
|
84 |
{ |
|
85 | 1 |
return _className;
|
86 |
} |
|
87 |
|
|
88 | 2019 |
public void setClassName(String string) |
89 |
{ |
|
90 | 2019 |
_className = string; |
91 |
} |
|
92 |
|
|
93 |
} |
|
94 |
|
|