.getLogger(SvcLogicExprListener.class);
private SvcLogicExpression curExpr;
- private SvcLogicExpression topExpr;
+ //private SvcLogicExpression topExpr;
private LinkedList<SvcLogicExpression> exprStack;
public SvcLogicExprListener()
{
if (exprStack.isEmpty())
{
- LOG.trace("Popping last expression");
- topExpr = curExpr;
+ //topExpr = curExpr;
}
else
{
SvcLogicExpression lastExpr = curExpr;
curExpr = exprStack.pop();
curExpr.addOperand(lastExpr);
- LOG.trace("New curExpr is ["+curExpr.getClass().getName()+"]");
}
}
@Override
public void enterAtom(AtomContext ctx) {
-
- String atomText = ctx.getText();
-
- LOG.trace("enterAtom: text = "+atomText);
-
-
+ String atomText = ctx.getText();
SvcLogicAtom newAtom = new SvcLogicAtom(atomText);
-
pushExpr(newAtom);
}
@Override
public void enterMultExpr(MultExprContext ctx) {
- LOG.trace("enterMultExpr: text = "+ctx.getText());
-
SvcLogicBinaryExpression curBinExpr = new SvcLogicBinaryExpression();
pushExpr(curBinExpr);
for (TerminalNode nd : opList)
{
- LOG.trace("enterMultExpr: operator - "+nd.getText());
curBinExpr.addOperator(nd.getText());
}
@Override
public void exitMultExpr(MultExprContext ctx) {
-
- LOG.trace("exitMultExpr: text = "+ctx.getText());
-
popExpr();
-
}
@Override
public void exitAtom(AtomContext ctx) {
- LOG.trace("exitAtom: text = "+ctx.getText());
popExpr();
}
@Override
public void enterAddExpr(AddExprContext ctx) {
- LOG.trace("enterAddExpr: text = "+ctx.getText());
List<TerminalNode> opList = ctx.ADDOP();
for (TerminalNode nd : opList)
{
- LOG.trace("enterAddExpr: operator - "+nd.getText());
curBinExpr.addOperator(nd.getText());
}
}
@Override
- public void exitAddExpr(AddExprContext ctx) {
- LOG.trace("exitAddExpr: text = "+ctx.getText());
-
+ public void exitAddExpr(AddExprContext ctx) {
popExpr();
}
}
@Override
- public void exitFuncExpr(FuncExprContext ctx) {
- LOG.trace("exitFuncExpr: text = "+ctx.getText());
-
+ public void exitFuncExpr(FuncExprContext ctx) {
popExpr();
}
}
@Override
- public void enterRelExpr(RelExprContext ctx) {
- LOG.trace("enterRelExpr: text = "+ctx.getText());
-
+ public void enterRelExpr(RelExprContext ctx) {
List<TerminalNode> opList = ctx.RELOP();
for (TerminalNode nd : opList)
{
- LOG.trace("enterRelExpr: operator - "+nd.getText());
curBinExpr.addOperator(nd.getText());
}
}
@Override
- public void exitRelExpr(RelExprContext ctx) {
- LOG.trace("exitRelExpr: text = "+ctx.getText());
-
+ public void exitRelExpr(RelExprContext ctx) {
popExpr();
}
@Override
public void enterCompareExpr(CompareExprContext ctx) {
- LOG.trace("enterCompareExpr: text = "+ctx.getText());
TerminalNode nd = ctx.COMPAREOP();
SvcLogicBinaryExpression curBinExpr = new SvcLogicBinaryExpression();
pushExpr(curBinExpr);
- LOG.trace("enterCompareExpr: operator - "+nd.getText());
curBinExpr.addOperator(nd.getText());
}
@Override
public void exitCompareExpr(CompareExprContext ctx) {
- LOG.trace("exitCompareExpr : text = "+ctx.getText());
popExpr();
}
@Override
public void enterConstant(ConstantContext ctx) {
- LOG.trace("enterConstant: text = "+ctx.getText());
}
@Override
public void exitConstant(ConstantContext ctx) {
- LOG.trace("exitConstant: text = "+ctx.getText());
}
@Override
public void enterVariable(VariableContext ctx) {
- LOG.trace("enterVariable: text = "+ctx.getText());
-
-
}
@Override
- public void exitVariable(VariableContext ctx) {
- LOG.debug("exitVariable: text ="+ctx.getText());
-
+ public void exitVariable(VariableContext ctx) {
}
@Override
public void enterVariableLead(VariableLeadContext ctx) {
-
- LOG.debug("enterVariableLead: text ="+ctx.getText());
-
-
}
@Override
public void exitVariableLead(VariableLeadContext ctx) {
-
- LOG.trace("exitVariableLead: text ="+ctx.getText());
}
@Override
- public void enterVariableTerm(VariableTermContext ctx) {
- LOG.trace("enterVariableTerm: text ="+ctx.getText());
-
+ public void enterVariableTerm(VariableTermContext ctx) {
String name = ctx.getText();
int subscrStart = name.indexOf("[");
@Override
public void exitVariableTerm(VariableTermContext ctx) {
- LOG.trace("exitVariableTerm: text="+ctx.getText());
- popExpr();
+ popExpr();
}
}
}
String simpleTypeName = fromObj.getClass().getTypeName();
simpleTypeName = simpleTypeName.substring(simpleTypeName.lastIndexOf(".") + 1);
- LOG.trace("Extracting properties from " + fromClass.getName() + " class");
if (classHasSpecialHandling(simpleTypeName)) {
try {
+ ".getValue() to Properties entry", e);
}
} else if (fromObj instanceof List) {
-
- // Class is a List. List should contain yang-generated classes.
- LOG.trace(fromClass.getName() + " is a List");
-
List fromList = (List) fromObj;
for (int i = 0; i < fromList.size(); i++) {
} else if (isYangGenerated(fromClass)) {
// Class is yang generated.
- LOG.trace(fromClass.getName() + " is a Yang-generated class");
String propNamePfx = null;
Object retValue = m.invoke(fromObj);
if (retValue instanceof byte[]) {
- LOG.trace(m.getName() + " returns a byte[]");
retValue = new String((byte[]) retValue, "UTF-8");
- LOG.trace("Converted byte array " + propNamePfx + "." + fieldName + "to string "
- + retValue);
}
if (!isAccessible) {
m.setAccessible(isAccessible);
}
} else if (returnType.equals(Class.class)) {
- LOG.trace(m.getName() + " returns a Class object - not interested");
-
} else if (List.class.isAssignableFrom(returnType)) {
// This getter method returns a list.
if (propValObj != null) {
if (propValObj instanceof byte[]) {
- LOG.trace(m.getName() + " returns a byte[]");
propVal = new String((byte[]) propValObj, "UTF-8");
- LOG.trace("Converted byte array " + propNamePfx + "." + fieldName + "to string "
- + propVal);
-
} else {
propVal = propValObj.toString();
}
if (fromObj instanceof byte[]) {
try {
fromVal = new String((byte[]) fromObj, "UTF-8");
- LOG.trace("Converted byte array " + pfx + "to string " + fromVal);
} catch (Exception e) {
LOG.warn("Caught exception trying to convert " + pfx + " from byte[] to String", e);
fromVal = fromObj.toString();
int maxIdx = -1;
boolean foundValue = false;
- LOG.trace("Saving properties to List<" + elemType.getName() + "> from " + pfx);
-
if (props.containsKey(pfx + "_length")) {
try {
int listLength = Integer.parseInt(props.getProperty(pfx + "_length"));
}
}
- LOG.trace(pfx + " has max index of " + maxIdx);
for (int i = 0; i <= maxIdx; i++) {
String curBase = pfx + "[" + i + "]";
Method buildMethod = builderClass.getMethod("build");
builderObj = toBuilder(props, curBase, builderObj, true);
if (builderObj != null) {
- LOG.trace(
- "Calling " + builderObj.getClass().getName() + "." + buildMethod.getName() + "()");
Object builtObj = buildMethod.invoke(builderObj);
toObj.add(builtObj);
foundValue = true;
Class toClass = toObj.getClass();
boolean foundValue = false;
- LOG.trace("Saving properties to " + toClass.getName() + " class from " + pfx);
-
Ipv4Address addr;
if (isYangGenerated(toClass)) {
// Class is yang generated.
- LOG.trace(toClass.getName() + " is a Yang-generated class");
-
String propNamePfx = null;
if (preservePfx) {
propNamePfx = pfx;
}
if (toObj instanceof Identifier) {
- LOG.trace(toClass.getName() + " is a Key - skipping");
return (toObj);
}
String paramValue = props.getProperty(propName);
if (paramValue == null) {
- LOG.trace(propName + " is unset");
+
} else if ("".equals(paramValue)) {
LOG.trace(propName + " was set to the empty string, setting it to null");
paramValue = null;
} else {
- LOG.trace(propName + " = " + paramValue);
+
}
// Is the return type a yang generated class?
// Is it an enum?
if (paramClass.isEnum()) {
- LOG.trace(m.getName() + " expects an Enum");
// Param type is a typedef.
if ((paramValue != null) && (paramValue.length() > 0)) {
Object paramObj = null;
m.setAccessible(true);
}
- LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
- + paramValue + ")");
m.invoke(toObj, paramObj);
if (!isAccessible) {
if (!isAccessible) {
m.setAccessible(true);
}
- LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
- + paramValue + ")");
+
m.invoke(toObj, paramValue);
if (!isAccessible) {
m.setAccessible(isAccessible);
Object constObj = null;
- LOG.trace(m.getName() + " expects a yang-generated class - looking for builder "
- + builderName);
try {
builderClass = Class.forName(builderName);
builderObj = builderClass.newInstance();
if (!isAccessible) {
m.setAccessible(true);
}
- LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName()
- + "(null)");
+
m.invoke(toObj, new Object[] { null });
if (!isAccessible) {
m.setAccessible(isAccessible);
try {
Method buildMethod = builderClass.getMethod("build");
- LOG.trace("Calling " + paramObj.getClass().getName() + "."
- + buildMethod.getName() + "()");
+
Object builtObj = buildMethod.invoke(paramObj);
boolean isAccessible = m.isAccessible();
m.setAccessible(true);
}
- LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "()");
m.invoke(toObj, builtObj);
if (!isAccessible) {
m.setAccessible(isAccessible);
}
if (constObj != null) {
-
- LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
- + constObj.toString() + ")");
m.invoke(toObj, constObj);
} else {
- LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
- + paramValue + ")");
m.invoke(toObj, paramValue);
-
}
if (!isAccessible) {
m.setAccessible(isAccessible);
// if it is a List.
if (List.class.isAssignableFrom(paramClass)) {
-
- LOG.trace("Parameter class " + paramClass.getName() + " is a List");
-
// Figure out what type of args are in List and pass
// that to toList().
if (!isAccessible) {
m.setAccessible(true);
}
- LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
- + paramValue + ")");
m.invoke(toObj, paramObj);
if (!isAccessible) {
m.setAccessible(isAccessible);
// Setter expects something that is not a List and
// not yang-generated. Just pass the parameter value
-
- LOG.trace("Parameter class " + paramClass.getName()
- + " is not a yang-generated class or a List");
-
if ((paramValue != null) && (paramValue.length() > 0)) {
Object constObj = null;
if (constObj != null) {
try {
- LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
- + constObj + ")");
m.invoke(toObj, constObj);
foundValue = true;
} catch (Exception e2) {
if (!isAccessible) {
m.setAccessible(true);
}
- LOG.trace("Calling " + toObj.getClass().getName() + "." + m.getName() + "("
- + paramValue + ")");
m.invoke(toObj, paramValue);
if (!isAccessible) {
m.setAccessible(isAccessible);
public static void printPropertyList(PrintStream pstr, String pfx, Class toClass) {
boolean foundValue = false;
- LOG.trace("Analyzing " + toClass.getName() + " class : pfx " + pfx);
-
if (isYangGenerated(toClass) && (!Identifier.class.isAssignableFrom(toClass))) {
// Class is yang generated.
- LOG.trace(toClass.getName() + " is a Yang-generated class");
-
- if (toClass.getName().endsWith("Key")) {
- if (Identifier.class.isAssignableFrom(toClass)) {
- LOG.trace(Identifier.class.getName() + " is assignable from " + toClass.getName());
- } else {
-
- LOG.trace(Identifier.class.getName() + " is NOT assignable from " + toClass.getName());
- }
- }
-
String propNamePfx = null;
if (pfx.endsWith("]")) {
propNamePfx = pfx;
// set
for (Method m : toClass.getMethods()) {
- LOG.trace("Is " + m.getName() + " method a getter?");
if (isGetter(m)) {
- LOG.trace(m.getName() + " is a getter");
Class returnClass = m.getReturnType();
String fieldName = toLowerHyphen(m.getName().substring(3));
if (isYangGenerated(returnClass)) {
// Is it an enum?
if (returnClass.isEnum()) {
-
- LOG.trace(m.getName() + " is an Enum");
pstr.print("\n\n * " + propName);
-
} else {
String simpleName = returnClass.getSimpleName();
if (IPV4_ADDRESS.equals(simpleName) || IPV6_ADDRESS.equals(simpleName)
|| IP_ADDRESS.equals(simpleName) || IP_PREFIX.equals(simpleName)
|| "PortNumber".equals(simpleName) || "Dscp".equals(simpleName)) {
- LOG.trace(m.getName() + " is an " + simpleName);
pstr.print("\n\n * " + propName);
} else {
printPropertyList(pstr, propNamePfx, returnClass);
// if it is a List.
if (List.class.isAssignableFrom(returnClass)) {
-
- LOG.trace("Parameter class " + returnClass.getName() + " is a List");
-
// Figure out what type of args are in List and pass
// that to toList().
Type returnType = m.getGenericReturnType();
Type elementType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
Class elementClass = (Class) elementType;
- LOG.trace("Calling printPropertyList on list type (" + elementClass.getName()
- + "), pfx is (" + pfx + "), toClass is (" + toClass.getName() + ")");
printPropertyList(pstr,
propNamePfx + "." + toLowerHyphen(elementClass.getSimpleName()) + "[]",
elementClass);
// Setter expects something that is not a List and
// not yang-generated. Just pass the parameter value
-
- LOG.trace("Parameter class " + returnClass.getName()
- + " is not a yang-generated class or a List");
-
pstr.print("\n\n * " + propName);
}
}
String retval = str.replaceAll(regex, replacement).toLowerCase();
- LOG.trace("Converting " + inStr + " => " + str + " => " + retval);
return (retval);
}