Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 171:7fb9441dd8af
Format Code to max 80 Chars per Row and Cleanup
gnv-artifacts/trunk@208 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 09 Oct 2009 07:54:48 +0000 |
parents | ef157bd2fa92 |
children | 00c1a931b9c3 |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Fri Oct 09 07:49:47 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Fri Oct 09 07:54:48 2009 +0000 @@ -38,7 +38,7 @@ /** * @author Tim Englich <tim.englich@intevation.de> - * + * */ public abstract class GNVArtifactBase extends DefaultArtifact { /** @@ -49,23 +49,24 @@ * The UID of this Class */ private static final long serialVersionUID = -8907096744400741458L; - + /** * The Identifier for the Replacement of the Artifactname */ public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER"; - + /** * The XPATH to the XML-Fragment that should be used for the Configuration */ - public static final String XPATH_ARTIFACT_CONFIGURATION= "/artifact-database/artifacts/artifact[@name='"+XPATH_IDENTIFIER_REPLACE+"']"; - - + public static final String XPATH_ARTIFACT_CONFIGURATION = "/artifact-database/artifacts/artifact[@name='" + + XPATH_IDENTIFIER_REPLACE + + "']"; + /** * The current Transition */ protected Transition current = null; - + /** * The Transitions that can be used */ @@ -75,18 +76,19 @@ * The Name of the Artifact */ protected String name = null; - + private ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities(); - + /** * Constructor */ public GNVArtifactBase() { super(); } - + /** - * @see de.intevation.artifactdatabase.DefaultArtifact#advance(org.w3c.dom.Document, de.intevation.artifacts.CallContext) + * @see de.intevation.artifactdatabase.DefaultArtifact#advance(org.w3c.dom.Document, + * de.intevation.artifacts.CallContext) */ @Override public Document advance(Document target, CallContext context) { @@ -94,188 +96,221 @@ String uuid = Config.getStringXPath(target, "action/uuid/@value"); Document result = XMLUtils.newDocument(); try { - if (this.current != null){ + if (this.current != null) { String transitionName = this.readTransitionName(target); - log.debug("Transitionsname: "+transitionName); - if (this.current.isTransitionReachable(transitionName)){ + log.debug("Transitionsname: " + transitionName); + if (this.current.isTransitionReachable(transitionName)) { // 1. Prüfung ob Transition valide ist - if (this.current.validate()){ - + if (this.current.validate()) { + try { - Transition nextStep = this.transitions.get(transitionName); + Transition nextStep = this.transitions + .get(transitionName); // 2.Ergebnisse Berechnen - this.current.advance(uuid,context.getMeta()); + this.current.advance(uuid, context.getMeta()); // 3. Ergebnisse übergeben - nextStep.setDescibeData(this.current.getDescibeData()); - nextStep.putInputData(this.current.getInputData(),uuid); + nextStep.setDescibeData(this.current + .getDescibeData()); + nextStep.putInputData(this.current.getInputData(), + uuid); // 4. Umschalten auf neue Transistion this.current = nextStep; - result = new ArtifactXMLUtilities().createSuccessReport("Advance success", XMLUtils.newDocument()); + result = new ArtifactXMLUtilities() + .createSuccessReport("Advance success", + XMLUtils.newDocument()); } catch (TransitionException e) { - log.error(e,e); - result = new ArtifactXMLUtilities().createExceptionReport(e.getLocalizedMessage(), XMLUtils.newDocument()); + log.error(e, e); + result = new ArtifactXMLUtilities() + .createExceptionReport(e + .getLocalizedMessage(), XMLUtils + .newDocument()); } - - }else{ - String msg = "Advance nicht möglich, da die Bedingungen für den Übergang " + - "in den neuen Zustand noch nicht gegeben ist."; + + } else { + String msg = "Advance nicht möglich, da die Bedingungen für den Übergang " + + "in den neuen Zustand noch nicht gegeben ist."; log.error(msg); - result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument()); + result = new ArtifactXMLUtilities() + .createExceptionReport(msg, XMLUtils + .newDocument()); } - - }else{ + + } else { String msg = "Transitionsübergang wird nicht unterstützt."; log.error(msg); - result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument()); + result = new ArtifactXMLUtilities().createExceptionReport( + msg, XMLUtils.newDocument()); } - }else{ + } else { String msg = "Kein Transitionsschritt aktiviert."; log.error(msg); - result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument()); + result = new ArtifactXMLUtilities().createExceptionReport(msg, + XMLUtils.newDocument()); } } catch (Exception e) { - log.error(e,e); - result = new ArtifactXMLUtilities().createExceptionReport(e.getLocalizedMessage(), XMLUtils.newDocument()); + log.error(e, e); + result = new ArtifactXMLUtilities().createExceptionReport(e + .getLocalizedMessage(), XMLUtils.newDocument()); } return result; } protected String readTransitionName(Document document) { - String returnValue = Config.getStringXPath(document, "action/target/@name"); + String returnValue = Config.getStringXPath(document, + "action/target/@name"); return returnValue; } - protected Node getConfigurationFragment(Document document){ + protected Node getConfigurationFragment(Document document) { log.debug("GNVArtifactBase.getConfigurationFragment"); - String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(XPATH_IDENTIFIER_REPLACE, this.name); + String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll( + XPATH_IDENTIFIER_REPLACE, this.name); log.debug(xpathQuery); - return Config.getNodeXPath(document,xpathQuery); + return Config.getNodeXPath(document, xpathQuery); } - + /** - * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, de.intevation.artifacts.CallContext) + * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, + * de.intevation.artifacts.CallContext) */ @Override public Document feed(Document target, CallContext context) { log.debug("GNVArtifactBase.feed"); Document result = XMLUtils.newDocument(); try { - if (this.current != null){ - String uuid = Config.getStringXPath(target, "action/uuid/@value"); - this.current.putInputData(this.parseInputData(target, "/action/data/input"),uuid); - result = new ArtifactXMLUtilities().createSuccessReport("Feed success", XMLUtils.newDocument()); - }else{ + if (this.current != null) { + String uuid = Config.getStringXPath(target, + "action/uuid/@value"); + this.current.putInputData(this.parseInputData(target, + "/action/data/input"), uuid); + result = new ArtifactXMLUtilities().createSuccessReport( + "Feed success", XMLUtils.newDocument()); + } else { String msg = "No Transition instantiated"; log.warn(msg); - result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument()); + result = new ArtifactXMLUtilities().createExceptionReport(msg, + XMLUtils.newDocument()); } } catch (TransitionException e) { - log.error(e,e); - result = new ArtifactXMLUtilities().createExceptionReport(e.getLocalizedMessage(), XMLUtils.newDocument()); + log.error(e, e); + result = new ArtifactXMLUtilities().createExceptionReport(e + .getLocalizedMessage(), XMLUtils.newDocument()); } return result; } - + /** - * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, java.lang.Object) + * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, + * java.lang.Object) */ @Override public void setup(String identifier, ArtifactFactory factory, Object context) { log.debug("GNVArtifactBase.setup"); super.setup(identifier, factory, context); - + Object localContext = context; - if (context instanceof CallContext){ - localContext = ((CallContext)context).globalContext(); - + if (context instanceof CallContext) { + localContext = ((CallContext) context).globalContext(); + } - - if (localContext instanceof GNVArtifactContext){ - GNVArtifactContext gnvContext = (GNVArtifactContext)localContext; + + if (localContext instanceof GNVArtifactContext) { + GNVArtifactContext gnvContext = (GNVArtifactContext) localContext; Document doc = gnvContext.getConfig(); Node artifactNode = this.getConfigurationFragment(doc); - NodeList transitionList = Config.getNodeSetXPath(artifactNode, "transitions/transition"); - this.transitions = new HashMap<String, Transition>(transitionList.getLength()); - for (int i = 0 ; i < transitionList.getLength(); i++){ - Transition tmpTransition = TransitionFactory.getInstance().createTransition(transitionList.item(i)); - if (tmpTransition != null){ + NodeList transitionList = Config.getNodeSetXPath(artifactNode, + "transitions/transition"); + this.transitions = new HashMap<String, Transition>(transitionList + .getLength()); + for (int i = 0; i < transitionList.getLength(); i++) { + Transition tmpTransition = TransitionFactory.getInstance() + .createTransition(transitionList.item(i)); + if (tmpTransition != null) { this.transitions.put(tmpTransition.getID(), tmpTransition); - if (this.current == null){ + if (this.current == null) { this.current = tmpTransition; } } } - + } } - - - protected Document createDescibeOutput(CallMeta callMeta){ + + protected Document createDescibeOutput(CallMeta callMeta) { log.debug("GNVArtifactBase.createDescibeOutput"); Document document = XMLUtils.newDocument(); - Element rootNode = this.createRootNode(document); + Element rootNode = this.createRootNode(document); this.createHeader(rootNode, document, "describe"); this.createOutputs(rootNode, document); this.createCurrentState(rootNode, document); this.createReachableStates(rootNode, document); this.createModel(rootNode, document); - this.createUserInterface(rootNode, document,callMeta); + this.createUserInterface(rootNode, document, callMeta); return document; } - - protected Element createRootNode(Document document){ - Element rootNode = xmlUtilities.createArtifactElement(document,"result"); + + protected Element createRootNode(Document document) { + Element rootNode = xmlUtilities.createArtifactElement(document, + "result"); document.appendChild(rootNode); return rootNode; } - - protected void createHeader(Element parent, Document document, String documentType){ - Element typeNode = xmlUtilities.createArtifactElement(document,"type"); + + protected void createHeader(Element parent, Document document, + String documentType) { + Element typeNode = xmlUtilities.createArtifactElement(document, "type"); typeNode.setAttribute("name", documentType); parent.appendChild(typeNode); - - Element uuidNode = xmlUtilities.createArtifactElement(document,"uuid"); + + Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid"); uuidNode.setAttribute("value", super.identifier); parent.appendChild(uuidNode); - - Element hashNode = xmlUtilities.createArtifactElement(document,"hash"); + + Element hashNode = xmlUtilities.createArtifactElement(document, "hash"); hashNode.setAttribute("value", this.hash()); parent.appendChild(hashNode); } - protected void createReachableStates(Element parent,Document document){ - Element stateNode = xmlUtilities.createArtifactElement(document,"reachable-states"); - if (this.current != null){ - Iterator<String> states = this.current.reachableTransitions().iterator(); - while(states.hasNext()){ + protected void createReachableStates(Element parent, Document document) { + Element stateNode = xmlUtilities.createArtifactElement(document, + "reachable-states"); + if (this.current != null) { + Iterator<String> states = this.current.reachableTransitions() + .iterator(); + while (states.hasNext()) { String value = states.next(); - Element currentNode = xmlUtilities.createArtifactElement(document,"state"); + Element currentNode = xmlUtilities.createArtifactElement( + document, "state"); currentNode.setAttribute("name", value); - log.debug("Reachable State: "+value); - currentNode.setAttribute("description", transitions.get(value).getDescription()); + log.debug("Reachable State: " + value); + currentNode.setAttribute("description", transitions.get(value) + .getDescription()); stateNode.appendChild(currentNode); } } parent.appendChild(stateNode); } - - protected void createCurrentState(Element parent, Document document){ - Element stateNode = xmlUtilities.createArtifactElement(document,"state"); + + protected void createCurrentState(Element parent, Document document) { + Element stateNode = xmlUtilities.createArtifactElement(document, + "state"); stateNode.setAttribute("name", this.current.getID()); stateNode.setAttribute("description", this.current.getDescription()); parent.appendChild(stateNode); } - - - protected void createModel(Element parent, Document document){ - Element modelNode = xmlUtilities.createArtifactElement(document,"model"); - if (this.current != null){ - Collection<InputValue> inputValues = this.current.getRequiredInputValues(); - if (inputValues != null){ + + protected void createModel(Element parent, Document document) { + Element modelNode = xmlUtilities.createArtifactElement(document, + "model"); + if (this.current != null) { + Collection<InputValue> inputValues = this.current + .getRequiredInputValues(); + if (inputValues != null) { Iterator<InputValue> it = inputValues.iterator(); - while(it.hasNext()){ + while (it.hasNext()) { InputValue inputValue = it.next(); - Element inputNode = xmlUtilities.createArtifactElement(document,"input"); + Element inputNode = xmlUtilities.createArtifactElement( + document, "input"); inputNode.setAttribute("name", inputValue.getName()); inputNode.setAttribute("type", inputValue.getType()); modelNode.appendChild(inputNode); @@ -284,86 +319,101 @@ } parent.appendChild(modelNode); } - - protected void createUserInterface(Element parent, Document document, CallMeta callMeta){ - Element uiNode = xmlUtilities.createArtifactElement(document,"ui"); - - if (this.current != null){ - this.current.describe(document, uiNode,callMeta); + + protected void createUserInterface(Element parent, Document document, + CallMeta callMeta) { + Element uiNode = xmlUtilities.createArtifactElement(document, "ui"); + + if (this.current != null) { + this.current.describe(document, uiNode, callMeta); } - + parent.appendChild(uiNode); } - - protected void createOutputs(Element parent, Document document){ + + protected void createOutputs(Element parent, Document document) { log.debug("GNVArtifactBase.createOutputs"); - Element outputsNode = xmlUtilities.createArtifactElement(document,"outputs"); - if (this.current instanceof OutputTransition){ - Collection<OutputMode> outputModes = ((OutputTransition)this.current).getOutputModes(); - if (outputModes != null){ + Element outputsNode = xmlUtilities.createArtifactElement(document, + "outputs"); + if (this.current instanceof OutputTransition) { + Collection<OutputMode> outputModes = ((OutputTransition) this.current) + .getOutputModes(); + if (outputModes != null) { Iterator<OutputMode> it = outputModes.iterator(); - while(it.hasNext()){ + while (it.hasNext()) { OutputMode outputMode = it.next(); - log.debug("Write Outputnode for "+ outputMode.toString()); - Element outputModeNode = xmlUtilities.createArtifactElement(document,"output"); + log.debug("Write Outputnode for " + outputMode.toString()); + Element outputModeNode = xmlUtilities + .createArtifactElement(document, "output"); outputModeNode.setAttribute("name", outputMode.getName()); - outputModeNode.setAttribute("description", outputMode.getDescription()); - outputModeNode.setAttribute("mime-type", outputMode.getMimeType()); + outputModeNode.setAttribute("description", outputMode + .getDescription()); + outputModeNode.setAttribute("mime-type", outputMode + .getMimeType()); outputsNode.appendChild(outputModeNode); - - Collection<InputValue> inputParameters = outputMode.getInputParameters(); - if (inputParameters != null){ - Element inputParametersNode = xmlUtilities.createArtifactElement(document,"parameter"); + + Collection<InputValue> inputParameters = outputMode + .getInputParameters(); + if (inputParameters != null) { + Element inputParametersNode = xmlUtilities + .createArtifactElement(document, "parameter"); outputModeNode.appendChild(inputParametersNode); Iterator<InputValue> it2 = inputParameters.iterator(); - while (it2.hasNext()){ + while (it2.hasNext()) { InputValue inputValue = it2.next(); - Element inputParameterNode = xmlUtilities.createArtifactElement(document,"parameter"); + Element inputParameterNode = xmlUtilities + .createArtifactElement(document, + "parameter"); inputParametersNode.appendChild(inputParameterNode); - inputParameterNode.setAttribute("name", inputValue.getName()); - inputParameterNode.setAttribute("type", inputValue.getType()); - inputParameterNode.setAttribute("value", inputValue.getDefaultValue()); + inputParameterNode.setAttribute("name", inputValue + .getName()); + inputParameterNode.setAttribute("type", inputValue + .getType()); + inputParameterNode.setAttribute("value", inputValue + .getDefaultValue()); } } } - }else{ + } else { log.warn("No Outputmodes given."); } } parent.appendChild(outputsNode); } - - protected Collection<InputData> parseInputData(Document document, String xPath){ + protected Collection<InputData> parseInputData(Document document, + String xPath) { log.debug("GNVArtifactBase.parseInputData"); - HashMap<String,InputData> returnValue = null; - + HashMap<String, InputData> returnValue = null; + log.debug(new ArtifactXMLUtilities().writeDocument2String(document)); - - NodeList inputElemets = (NodeList)XMLUtils.xpath(document, xPath,XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);//Config.getNodeSetXPath(document, ""); - if(inputElemets != null){ - returnValue = new HashMap<String,InputData>(inputElemets.getLength()); - for (int i = 0; i < inputElemets.getLength(); i++){ + + NodeList inputElemets = (NodeList) XMLUtils.xpath(document, xPath, + XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);// Config.getNodeSetXPath(document, + // ""); + if (inputElemets != null) { + returnValue = new HashMap<String, InputData>(inputElemets + .getLength()); + for (int i = 0; i < inputElemets.getLength(); i++) { Node inputDataNode = inputElemets.item(i); - String name = Config.getStringXPath(inputDataNode,"@name"); - String value = Config.getStringXPath(inputDataNode,"@value"); - - if (returnValue.containsKey(name)){ + String name = Config.getStringXPath(inputDataNode, "@name"); + String value = Config.getStringXPath(inputDataNode, "@value"); + + if (returnValue.containsKey(name)) { InputData inputData = returnValue.get(name); inputData.concartValue(value); log.debug(inputData.toString()); returnValue.put(name, inputData); - }else{ - InputData inputData = new DefaultInputData(name,value); - - returnValue.put(name,inputData); + } else { + InputData inputData = new DefaultInputData(name, value); + + returnValue.put(name, inputData); } } } return returnValue.values(); } - /** * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document, * java.io.OutputStream, de.intevation.artifacts.CallContext) @@ -388,9 +438,8 @@ } } - - protected String readOutputType(Document document){ - String value = Config.getStringXPath(document,"action/out/@name"); + protected String readOutputType(Document document) { + String value = Config.getStringXPath(document, "action/out/@name"); return value; } }