[New] Added New StrolchElementVisitor for StrolchRootElement
Also added getParent() and getRootElement() on StrolchElement
This commit is contained in:
parent
7147bc1570
commit
d15d163ebf
|
@ -18,6 +18,7 @@ package li.strolch.model;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
|
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
@ -169,6 +170,21 @@ public class Order extends GroupedParameterizedElement implements StrolchRootEle
|
||||||
return lb.build();
|
return lb.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchElement getParent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Order getRootElement() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(StrolchRootElementVisitor visitor) {
|
||||||
|
return visitor.visitOrder(this);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -92,25 +92,6 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns this {@link ParameterizedElement}'s parent
|
|
||||||
*
|
|
||||||
* @return the parent
|
|
||||||
*/
|
|
||||||
public GroupedParameterizedElement getParent() {
|
|
||||||
return this.parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the parent for this {@link ParameterizedElement}
|
|
||||||
*
|
|
||||||
* @param parent
|
|
||||||
* the parent to set
|
|
||||||
*/
|
|
||||||
public void setParent(GroupedParameterizedElement parent) {
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link Parameter} with the given id, or null if it does not exist
|
* Returns the {@link Parameter} with the given id, or null if it does not exist
|
||||||
*
|
*
|
||||||
|
@ -278,6 +259,26 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GroupedParameterizedElement getParent() {
|
||||||
|
return this.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the parent for this {@link ParameterizedElement}
|
||||||
|
*
|
||||||
|
* @param parent
|
||||||
|
* the parent to set
|
||||||
|
*/
|
||||||
|
public void setParent(GroupedParameterizedElement parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchRootElement getRootElement() {
|
||||||
|
return this.parent.getRootElement();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
package li.strolch.model;
|
package li.strolch.model;
|
||||||
|
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
|
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
@ -84,6 +85,21 @@ public class Resource extends GroupedParameterizedElement implements StrolchRoot
|
||||||
return lb.build();
|
return lb.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchElement getParent() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resource getRootElement() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(StrolchRootElementVisitor visitor) {
|
||||||
|
return visitor.visitResource(this);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -94,6 +94,10 @@ public interface StrolchElement extends Serializable, Comparable<StrolchElement>
|
||||||
*/
|
*/
|
||||||
public String getType();
|
public String getType();
|
||||||
|
|
||||||
|
public StrolchElement getParent();
|
||||||
|
|
||||||
|
public StrolchRootElement getRootElement();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a clone of this {@link StrolchElement}
|
* Return a clone of this {@link StrolchElement}
|
||||||
*
|
*
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model;
|
package li.strolch.model;
|
||||||
|
|
||||||
|
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Root element for all top level {@link StrolchElement}. These are elements which have no parent, e.g. {@link Resource
|
* Root element for all top level {@link StrolchElement}. These are elements which have no parent, e.g. {@link Resource
|
||||||
* Resources} and {@link Order Orders}
|
* Resources} and {@link Order Orders}
|
||||||
|
@ -23,5 +25,5 @@ package li.strolch.model;
|
||||||
*/
|
*/
|
||||||
public interface StrolchRootElement extends StrolchElement {
|
public interface StrolchRootElement extends StrolchElement {
|
||||||
|
|
||||||
// marker interface
|
public <T> T accept(StrolchRootElementVisitor visitor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,10 @@ import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.AbstractStrolchElement;
|
import li.strolch.model.AbstractStrolchElement;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
import li.strolch.model.visitor.ParameterVisitor;
|
|
||||||
import li.strolch.model.ParameterizedElement;
|
import li.strolch.model.ParameterizedElement;
|
||||||
|
import li.strolch.model.StrolchRootElement;
|
||||||
import li.strolch.model.Tags;
|
import li.strolch.model.Tags;
|
||||||
|
import li.strolch.model.visitor.ParameterVisitor;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
@ -121,6 +122,11 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StrolchRootElement getRootElement() {
|
||||||
|
return this.parent.getRootElement();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Element toDom(Document doc) {
|
public Element toDom(Document doc) {
|
||||||
Element element = doc.createElement(Tags.PARAMETER);
|
Element element = doc.createElement(Tags.PARAMETER);
|
||||||
|
|
|
@ -20,7 +20,7 @@ import li.strolch.model.StrolchElement;
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public interface StrolchElementVisitor<T extends StrolchElement> {
|
public interface StrolchElementVisitor<T extends StrolchElement> extends StrolchVisitor {
|
||||||
|
|
||||||
public void visit(T element);
|
public void visit(T element);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed 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 li.strolch.model.visitor;
|
||||||
|
|
||||||
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public interface StrolchRootElementVisitor extends StrolchVisitor {
|
||||||
|
|
||||||
|
public <T> T visitOrder(Order order);
|
||||||
|
|
||||||
|
public <T> T visitResource(Resource resource);
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed 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 li.strolch.model.visitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marker interface to allow to quickly see the visitor implementations in Strolch
|
||||||
|
*
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public interface StrolchVisitor {
|
||||||
|
|
||||||
|
// marker interface
|
||||||
|
}
|
Loading…
Reference in New Issue