You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/01/29 17:00:24 UTC
svn commit: r1065049 -
/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java
Author: simonetripodi
Date: Sat Jan 29 16:00:24 2011
New Revision: 1065049
URL: http://svn.apache.org/viewvc?rev=1065049&view=rev
Log:
first checkin of ObjectCreateRule class, a tidy version of the proper one on /trunk
Added:
commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java (with props)
Added: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java?rev=1065049&view=auto
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java (added)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java Sat Jan 29 16:00:24 2011
@@ -0,0 +1,97 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.digester3;
+
+import org.xml.sax.Attributes;
+
+/**
+ * Rule implementation that creates a new object and pushes it
+ * onto the object stack. When the element is complete, the
+ * object will be popped
+ */
+class ObjectCreateRule extends Rule {
+
+ /**
+ * The Java class name of the object to be created.
+ */
+ private final String className;
+
+ /**
+ * The attribute containing an override class name if it is present.
+ */
+ private final String attributeName; // @Nullable
+
+ /**
+ *
+ *
+ * @param className The Java class name of the object to be created
+ * @param attributeName The attribute containing an override class name if it is present
+ */
+ public ObjectCreateRule(String className, String attributeName) {
+ this.className = className;
+ this.attributeName = attributeName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void begin(String namespace, String name, Attributes attributes) throws Exception {
+ // Identify the name of the class to instantiate
+ String realClassName = this.className;
+ if (this.attributeName != null) {
+ String value = attributes.getValue(this.attributeName);
+ if (value != null) {
+ realClassName = value;
+ }
+ }
+ if (this.getDigester().getLog().isDebugEnabled()) {
+ this.getDigester().getLog().debug(String.format("[ObjectCreateRule]{%s} New %s",
+ this.getDigester().getMatch(),
+ realClassName));
+ }
+
+ // Instantiate the new object and push it on the context stack
+ Class<?> clazz = this.getDigester().getClassLoader().loadClass(realClassName);
+ Object instance = clazz.newInstance();
+ this.getDigester().push(instance);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void end(String namespace, String name) throws Exception {
+ Object top = this.getDigester().pop();
+
+ if (this.getDigester().getLog().isDebugEnabled()) {
+ this.getDigester().getLog().debug(String.format("[ObjectCreateRule]{%s} Pop %s",
+ this.getDigester().getMatch(),
+ top.getClass().getName()));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return String.format("ObjectCreateRule[className=%s, attributeName=%s]", this.className, this.attributeName);
+ }
+
+}
Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java
------------------------------------------------------------------------------
svn:mime-type = text/plain