001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.hivemind.schema.rules;
016
017 import org.apache.hivemind.Element;
018 import org.apache.hivemind.schema.SchemaProcessor;
019 import org.apache.hivemind.util.InstanceCreationUtils;
020
021 /**
022 * Basic {@link org.apache.hivemind.schema.Rule} for creating a new object. Created from the the
023 * <code><create-object></code> element. Generally, this is the first rule in a sequence of
024 * rules.
025 *
026 * @author Howard Lewis Ship
027 */
028 public class CreateObjectRule extends BaseRule
029 {
030 private String _className;
031
032 public CreateObjectRule()
033 {
034 }
035
036 public CreateObjectRule(String className)
037 {
038 _className = className;
039 }
040
041 /**
042 * Creates the new object and pushes it onto the processor's stack. If the object implement
043 * {@link org.apache.hivemind.LocationHolder} then the {@link org.apache.hivemind.Location} of
044 * the element is assigned to the object.
045 */
046 public void begin(SchemaProcessor processor, Element element)
047 {
048 Object object = InstanceCreationUtils.createInstance(
049 processor.getDefiningModule(),
050 _className,
051 element.getLocation());
052
053 processor.push(object);
054 }
055
056 /**
057 * Pops the object off of the processor's stack.
058 */
059 public void end(SchemaProcessor processor, Element element)
060 {
061 processor.pop();
062 }
063
064 public String getClassName()
065 {
066 return _className;
067 }
068
069 public void setClassName(String string)
070 {
071 _className = string;
072 }
073
074 }