[Major] Multiple issues
- setId() and setName() don't allow empty values - added Locator.newBuilder(String) - fixed wrong locator created by ParameterizedElement - Better exception handling when parsing from XML as Sax
This commit is contained in:
parent
d15d163ebf
commit
0dae330e72
|
@ -22,6 +22,8 @@ import li.strolch.model.Locator.LocatorBuilder;
|
|||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
|
@ -70,12 +72,11 @@ public abstract class AbstractStrolchElement implements StrolchElement {
|
|||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
if (id == null)
|
||||
throw new StrolchException("The id may never be null"); //$NON-NLS-1$
|
||||
|
||||
if (id.isEmpty())
|
||||
throw new StrolchException("The id may never be empty"); //$NON-NLS-1$
|
||||
|
||||
if (StringHelper.isEmpty(id)) {
|
||||
String msg = "The id may never be empty for {0}";
|
||||
msg = MessageFormat.format(msg, getClass().getSimpleName());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
@ -86,6 +87,11 @@ public abstract class AbstractStrolchElement implements StrolchElement {
|
|||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
if (StringHelper.isEmpty(name)) {
|
||||
String msg = "The name may never be empty for {0} with id {1}";
|
||||
msg = MessageFormat.format(msg, getClass().getSimpleName(), id);
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
|
@ -243,6 +243,18 @@ public class Locator {
|
|||
return new Locator(locatorPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link LocatorBuilder} instance and appends the given root element tag to it
|
||||
*
|
||||
* @param rootElement
|
||||
* the first element on the {@link Locator}
|
||||
*
|
||||
* @return a new {@link LocatorBuilder} instance with the given root element tag as the first element
|
||||
*/
|
||||
public static LocatorBuilder newBuilder(String rootElement) {
|
||||
return new LocatorBuilder().append(rootElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link LocatorBuilder} is used to build {@link Locator}s where a deep hierarchy is to be created. The
|
||||
* {@link #append(String)} method returns itself for chain building
|
||||
|
|
|
@ -189,7 +189,6 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
|||
@Override
|
||||
public Locator getLocator() {
|
||||
LocatorBuilder lb = new LocatorBuilder();
|
||||
this.parent.fillLocator(lb);
|
||||
fillLocator(lb);
|
||||
return lb.build();
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import li.strolch.model.ResourceVisitor;
|
|||
import li.strolch.model.Tags;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -41,7 +40,7 @@ public class ResourceToSaxVisitor extends StrolchElementToDomVisitor implements
|
|||
toSax(res);
|
||||
this.contentHandler.endElement(null, null, Tags.RESOURCE);
|
||||
|
||||
} catch (SAXException e) {
|
||||
} catch (Exception e) {
|
||||
String msg = "Failed to transform Resource {0} to XML due to {1}"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, res.getLocator(), e.getMessage());
|
||||
throw new RuntimeException(msg, e);
|
||||
|
|
|
@ -20,6 +20,7 @@ import static ch.eitchnet.utils.helper.StringHelper.NULL;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.ParameterBag;
|
||||
|
@ -122,8 +123,10 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
String paramValue = attributes.getValue(Tags.VALUE);
|
||||
String paramHiddenS = attributes.getValue(Tags.HIDDEN);
|
||||
String paramIndexS = attributes.getValue(Tags.INDEX);
|
||||
try {
|
||||
int index = StringHelper.isEmpty(paramIndexS) ? 0 : Integer.valueOf(paramIndexS);
|
||||
boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper.parseBoolean(paramHiddenS);
|
||||
boolean paramHidden = StringHelper.isEmpty(paramHiddenS) ? false : StringHelper
|
||||
.parseBoolean(paramHiddenS);
|
||||
String paramUom = attributes.getValue(Tags.UOM);
|
||||
String paramInterpretation = attributes.getValue(Tags.INTERPRETATION);
|
||||
Parameter<?> param;
|
||||
|
@ -158,6 +161,10 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
param.setInterpretation(paramInterpretation);
|
||||
param.setIndex(index);
|
||||
this.pBag.addParameter(param);
|
||||
} catch (Exception e) {
|
||||
throw new StrolchException("Failed to instantiate parameter " + paramId + " for bag "
|
||||
+ this.pBag.getLocator() + " due to " + e.getMessage(), e);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue