Author: adrianc
Date: Thu May 3 14:57:40 2012 New Revision: 1333489 URL: http://svn.apache.org/viewvc?rev=1333489&view=rev Log: Created a base class - MiniLangElement - for all Mini-language elements, modified exception handling to accommodate the new base class. This change will provide a means for non-operation elements to throw exceptions. Added: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangElement.java (with props) Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangException.java ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangRuntimeException.java ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodOperation.java Added: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangElement.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangElement.java?rev=1333489&view=auto ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangElement.java (added) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangElement.java Thu May 3 14:57:40 2012 @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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.ofbiz.minilang; + +import org.w3c.dom.Element; + +/** + * A single Mini-language element. This class is the superclass for all <code>Element</code> models. + */ +public class MiniLangElement { + + private final Object lineNumber; + protected final SimpleMethod simpleMethod; + private final String tagName; + + public MiniLangElement(Element element, SimpleMethod simpleMethod) { + this.lineNumber = element.getUserData("startLine"); + this.simpleMethod = simpleMethod; + this.tagName = element.getTagName().intern(); + } + + public String getLineNumber() { + return this.lineNumber == null ? "unknown" : this.lineNumber.toString(); + } + + public SimpleMethod getSimpleMethod() { + return this.simpleMethod; + } + + public String getTagName() { + return this.tagName; + } + + @Override + public String toString() { + return "<".concat(this.tagName).concat(">"); + } +} Propchange: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangElement.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangElement.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Rev URL Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangException.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangException.java?rev=1333489&r1=1333488&r2=1333489&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangException.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangException.java Thu May 3 14:57:40 2012 @@ -35,4 +35,8 @@ public class MiniLangException extends o public MiniLangException(String str, Throwable nested) { super(str, nested); } + + public MiniLangException(Throwable nested) { + super(nested); + } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangRuntimeException.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangRuntimeException.java?rev=1333489&r1=1333488&r2=1333489&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangRuntimeException.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/MiniLangRuntimeException.java Thu May 3 14:57:40 2012 @@ -18,7 +18,6 @@ *******************************************************************************/ package org.ofbiz.minilang; -import org.ofbiz.minilang.method.MethodOperation; /** * Thrown to indicate a Mini-language run-time error. @@ -26,21 +25,26 @@ import org.ofbiz.minilang.method.MethodO @SuppressWarnings("serial") public class MiniLangRuntimeException extends MiniLangException { - private final MethodOperation operation; + private final MiniLangElement element; - public MiniLangRuntimeException(String str, MethodOperation operation) { + public MiniLangRuntimeException(String str, MiniLangElement element) { super(str); - this.operation = operation; + this.element = element; + } + + public MiniLangRuntimeException(Throwable nested, MiniLangElement element) { + super(nested); + this.element = element; } @Override public String getMessage() { StringBuilder sb = new StringBuilder(super.getMessage()); - if (operation != null) { - SimpleMethod method = operation.getSimpleMethod(); + if (this.element != null) { + SimpleMethod method = this.element.getSimpleMethod(); sb.append(" Method = ").append(method.methodName).append(", File = ").append(method.getFromLocation()); - sb.append(", Element = <").append(operation.getTagName()).append(">"); - sb.append(", Line ").append(operation.getLineNumber()); + sb.append(", Element = <").append(this.element.getTagName()).append(">"); + sb.append(", Line ").append(this.element.getLineNumber()); } return sb.toString(); } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodOperation.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodOperation.java?rev=1333489&r1=1333488&r2=1333489&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodOperation.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodOperation.java Thu May 3 14:57:40 2012 @@ -26,6 +26,7 @@ import java.util.List; import javolution.util.FastList; +import org.ofbiz.minilang.MiniLangElement; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.SimpleMethod; import org.w3c.dom.Element; @@ -33,16 +34,11 @@ import org.w3c.dom.Element; /** * A single operation, does the specified operation on the given field */ -public abstract class MethodOperation { +public abstract class MethodOperation extends MiniLangElement { - private final Object lineNumber; - protected final SimpleMethod simpleMethod; - private final String tagName; protected MethodOperation(Element element, SimpleMethod simpleMethod) { - this.lineNumber = element.getUserData("startLine"); - this.simpleMethod = simpleMethod; - this.tagName = element.getTagName().intern(); + super(element, simpleMethod); } public void addErrorMessage(MethodContext methodContext, String message) { @@ -71,18 +67,6 @@ public abstract class MethodOperation { /** Create an expanded string representation of the operation, is for the current context */ public abstract String expandedString(MethodContext methodContext); - public String getLineNumber() { - return this.lineNumber == null ? "unknown" : this.lineNumber.toString(); - } - - public SimpleMethod getSimpleMethod() { - return this.simpleMethod; - } - - public String getTagName() { - return this.tagName; - } - /** Create a raw string representation of the operation, would be similar to original XML */ public abstract String rawString(); |
Free forum by Nabble | Edit this page |