Logo Search packages:      
Sourcecode: uimaj version File versions  Download package

Style_impl.java

/*
 * 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.uima.search.impl;

import org.apache.uima.resource.metadata.impl.MetaDataObject_impl;
import org.apache.uima.resource.metadata.impl.PropertyXmlInfo;
import org.apache.uima.resource.metadata.impl.XmlizationInfo;
import org.apache.uima.search.Attribute;
import org.apache.uima.search.Mapping;
import org.apache.uima.search.Style;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.XMLParser;
import org.w3c.dom.Element;
import org.xml.sax.helpers.AttributesImpl;

/**
 * 
 * 
 */
00037 public class Style_impl extends MetaDataObject_impl implements Style {
  private static final long serialVersionUID = -1506108274843606087L;

  private Attribute[] mAttributes = new Attribute[0];

  private String mName;

  private Mapping[] mAttributeMappings;

  /*
   * (non-Javadoc)
   * 
   * @see org.apache.uima.search.Style#getName()
   */
00051   public String getName() {
    return mName;
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.apache.uima.search.Style#setName(java.lang.String)
   */
00060   public void setName(String aName) {
    mName = aName.intern();
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.apache.uima.search.Style#getAttributes()
   */
00069   public Attribute[] getAttributes() {
    return mAttributes;
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.apache.uima.search.Style#setAttributes(org.apache.uima.search.Attribute[])
   */
00078   public void setAttributes(Attribute[] aAttributes) {
    mAttributes = (aAttributes == null) ? new Attribute[0] : aAttributes;
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.apache.uima.search.Style#getAttribute(java.lang.String)
   */
00087   public String getAttribute(String aName) {
    Attribute[] attrs = getAttributes();
    for (int i = 0; i < attrs.length; i++) {
      if (aName.equals(attrs[i].getName())) {
        return attrs[i].getValue();
      }
    }
    return null;
  }

00097   public Mapping[] getAttributeMappings() {
    return mAttributeMappings;
  }

00101   public void setAttributeMappings(Mapping[] aMappings) {
    mAttributeMappings = aMappings;
  }

  /**
   * Overridden to write the name property as an XML attribute.
   * 
   * @see org.apache.uima.resource.impl.MetaDataObject_impl#getXMLAttributeString()
   */
00110   protected AttributesImpl getXMLAttributes() {
    AttributesImpl attrs = super.getXMLAttributes();
    attrs.addAttribute("", "name", "name", null, getName());
    return attrs;
  }

  /**
   * Overridden to read the name property from XML attributes.
   * 
   * @see org.apache.uima.util.XMLizable#buildFromXMLElement(org.w3c.dom.Element,
   *      org.apache.uima.util.XMLParser)
   */
00122   public void buildFromXMLElement(Element aElement, XMLParser aParser,
          XMLParser.ParsingOptions aOptions) throws InvalidXMLException {
    setName(aElement.getAttribute("name"));

    // call superclass method to parse the "attributes" property, which is stored
    // as child elements (confusing, isn't it? :)
    super.buildFromXMLElement(aElement, aParser, aOptions);
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.apache.uima.resource.metadata.impl.MetaDataObject_impl#getXmlizationInfo()
   */
00136   protected XmlizationInfo getXmlizationInfo() {
    return XMLIZATION_INFO;
  }

  static final private XmlizationInfo XMLIZATION_INFO = new XmlizationInfo("style",
          new PropertyXmlInfo[] {
          // name is an attribute, not an element
              new PropertyXmlInfo("attributes", null), new PropertyXmlInfo("attributeMappings") });
}

Generated by  Doxygen 1.6.0   Back to index