Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.apache.tuscany.sca.node.configuration.xml;
 
 import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
 
 
 
Implements a StAX artifact processor for node implementations.

Version:
$Rev: 1002697 $ $Date: 2010-09-29 18:48:28 +0300 (Wed, 29 Sep 2010) $
 
 public class NodeConfigurationProcessor extends BaseStAXArtifactProcessor implements
     private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
     private static final QName NODE = new QName("node");
     private static final QName CONTRIBUTION = new QName("contribution");
     private static final QName BINDING = new QName("binding");
     private static final QName BASE_URI = new QName("baseURI");
     private static final QName DEPLOYMENT_COMPOSITE = new QName("deploymentComposite");
 
     private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
     private static final QName COMPOSITE = new QName("composite");
 
     private StAXArtifactProcessor processor;
     private StAXHelper helper;
 
                                       StAXArtifactProcessor processor) {
         FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
         this. = modelFactories.getFactory(NodeConfigurationFactory.class);
         this. = processor;
         this. = StAXHelper.getInstance(registry);
     }
 
     public QName getArtifactType() {
         // Returns the QName of the XML element processed by this processor
         return ;
     }
 
     public Class<NodeConfigurationgetModelType() {
         // Returns the type of model processed by this processor
         return NodeConfiguration.class;
     }
 
 
         NodeConfiguration node = null;
         ContributionConfiguration contribution = null;
         DeploymentComposite composite = null;
         BindingConfiguration binding = null;
 
         // Skip to end element
         while (true) {
             int event = reader.getEventType();
             switch (event) {
                case .:
                    QName name = reader.getName();
                    if (.equals(name)) {
                        node = .createNodeConfiguration();
                        node.setURI(reader.getAttributeValue(null"uri"));
                        node.setDomainURI(reader.getAttributeValue(null"domain"));
                        node.setDomainRegistryURI(reader.getAttributeValue(null"domainRegistry"));
                    } else if (.equals(name)) {
                        contribution = .createContributionConfiguration();
                        contribution.setURI(reader.getAttributeValue(null"uri"));
                        contribution.setLocation(reader.getAttributeValue(null"location"));
                        contribution.setMetaDataURL(reader.getAttributeValue(null"metaDataURL"));
                        String startDeployables = reader.getAttributeValue(null"startDeployables");
                        if (startDeployables != null) {
                            contribution.setStartDeployables(Boolean.parseBoolean(startDeployables));
                        }
                        String dependentURIs = reader.getAttributeValue(null"dependentURIs");
                        if (dependentURIs != null) {
                            contribution.setDependentContributionURIs(Arrays.asList(dependentURIs.split(",")));
                        }
                        node.getContributions().add(contribution);
                    } else if (.equals(name)) {
                        binding = .createBindingConfiguration();
                        binding.setBindingType(getQName(reader"name"));
                        String baseURIs = reader.getAttributeValue(null"baseURIs");
                        if (baseURIs != null) {
                            StringTokenizer tokenizer = new StringTokenizer(baseURIs);
                            while (tokenizer.hasMoreTokens()) {
                                binding.getBaseURIs().add(tokenizer.nextToken());
                            }
                        }
                        node.getBindings().add(binding);
                    } else if (.equals(name)) {
                        composite = .createDeploymentComposite();
                        composite.setLocation(reader.getAttributeValue(null"location"));
                        if (contribution != null) {
                            contribution.getDeploymentComposites().add(composite);
                        }
                    } else if(.equals(name)) {
                        // We also support <baseURI> element
                        String baseURI = reader.getElementText();
                        if (baseURI != null && binding != null) {
                            baseURI = baseURI.trim();
                            binding.addBaseURI(baseURI);
                        }
                        // getElementText() moves the event to END_ELEMENT
                        continue;
                    } else if (.equals(name)) {
                        /*
                        Object model = processor.read(reader);
                        if (model instanceof Composite) {
                            // FIXME: We need to capture the text here
                            // composite.setComposite((Composite)model);
                        }
                        */
                        StringWriter sw = new StringWriter();
                        XMLStreamWriter writer = .createXMLStreamWriter(sw);
                        .save(readerwriter);
                        composite.setContent(sw.toString());
                    } else {
                        node.getExtensions().add(.read(readercontext));
                    }
                    break;
                case :
                    name = reader.getName();
                    if (.equals(name)) {
                        return node;
                    } else if (.equals(name)) {
                        contribution = null;
                    } else if (.equals(name)) {
                        composite = null;
                    } else if (.equals(name)) {
                        binding = null;
                    }
            }
            if (reader.hasNext()) {
                reader.next();
            } else {
                break;
            }
        }
        return node;
    }
    public void resolve(NodeConfiguration nodeModelResolver resolverProcessorContext contextthrows ContributionResolveException {
    }
    public void write(NodeConfiguration nodeXMLStreamWriter writerProcessorContext contextthrows ContributionWriteException,
        XMLStreamException {
        writeStart(writer,
                   .getNamespaceURI(),
                   .getLocalPart(),
                   new XAttr("uri"node.getURI()),
                   new XAttr("domainRegistry"node.getDomainRegistryURI()),
                   new XAttr("domain"node.getDomainURI()));
        for (ContributionConfiguration c : node.getContributions()) {
            writeStart(writer,
                       .getNamespaceURI(),
                       .getLocalPart(),
                       new XAttr("uri"c.getURI()),
                       new XAttr("location"c.getLocation()));
            for (DeploymentComposite dc : c.getDeploymentComposites()) {
                writeStart(writer,
                           .getNamespaceURI(),
                           .getLocalPart(),
                           new XAttr("location"dc.getLocation()),
                           new XAttr("contribution"dc.getContributionURI()));
                if (dc.getContent() != null) {
                    XMLStreamReader reader = .createXMLStreamReader(new StringReader(dc.getContent()));
                    reader.nextTag(); // Move to the first element
                    .save(readerwriter);
                    reader.close();
                }
                writeEnd(writer);
            }
            writeEnd(writer);
        }
        for (BindingConfiguration b : node.getBindings()) {
            StringBuffer uris = new StringBuffer();
            for (String uri : b.getBaseURIs()) {
                uris.append(uri).append(' ');
            }
            if (uris.length() > 0) {
                uris.deleteCharAt(uris.length() - 1); // Remove the trailing space
            } else {
                uris = null;
            }
            String baseURIs = (uris == null) ? null : uris.toString();
            writeStart(writer,
                       .getNamespaceURI(),
                       .getLocalPart(),
                       new XAttr("name"b.getBindingType()),
                       new XAttr("baseURIs"baseURIs));
            writeEnd(writer);
        }
        
        for(Object onode.getExtensions()) {
            .write(owritercontext);
        }
        writeEnd(writer);
    }
New to GrepCode? Check out our FAQ X