Search in sources :

Example 1 with FeatureDefinition

use of com.ibm.j9tools.om.FeatureDefinition in project openj9 by eclipse.

the class FeatureParser method parse.

/**
 * Parse passed input stream. Expects well formed XML adhering to the specified
 * schema. This method should not be called directly but rather via the FeatureIO.load
 * method.
 *
 * @param 	input		InputStream containing build spec XML to be parsed
 * @return	initialized instance of a Feature
 *
 * @throws 			InvalidFeatureDefinitionException
 */
public FeatureDefinition parse(InputStream input, String objectId, FlagDefinitions flagDefinitions) throws InvalidFeatureDefinitionException, IOException {
    this.flagDefinitions = flagDefinitions;
    this._feature = new FeatureDefinition();
    try {
        _parser.getXMLReader().parse(new InputSource(input));
    } catch (SAXException e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        error(new SAXParseException(e.getMessage(), "", "", 0, 0));
    } finally {
        if (hasErrors() || hasWarnings()) {
            throw new InvalidFeatureDefinitionException(getErrors(), getWarnings(), objectId);
        }
    }
    return _feature;
}
Also used : InvalidFeatureDefinitionException(com.ibm.j9tools.om.InvalidFeatureDefinitionException) InputSource(org.xml.sax.InputSource) SAXParseException(org.xml.sax.SAXParseException) FeatureDefinition(com.ibm.j9tools.om.FeatureDefinition) SAXException(org.xml.sax.SAXException)

Example 2 with FeatureDefinition

use of com.ibm.j9tools.om.FeatureDefinition in project openj9 by eclipse.

the class BuildSpecParser method startElement.

/**
 * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
 */
@Override
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes attributes) {
    /* We are starting to parse a new element, reset the parsed value */
    // $NON-NLS-1$
    _parsedValue = "";
    if (qName.equalsIgnoreCase("spec")) {
        // $NON-NLS-1$
        /* Reset all lists */
        _owners = new Vector<Owner>();
        _features = new Vector<Feature>();
        _flags = new Vector<Flag>();
        _sources = new Vector<Source>();
        _properties = new Vector<Property>();
        /* Set the build spec id */
        // $NON-NLS-1$
        _buildSpec.setId(attributes.getValue("id"));
        /* Remember where this build spec was defined */
        _buildSpec.setLocation(_documentLocatorFile, _documentLocator);
    } else /* Parse owners of the build spec */
    if (qName.equalsIgnoreCase("owners")) {
        // $NON-NLS-1$
        _owners = new Vector<Owner>();
    } else /* Parse flags of the build spec */
    if (qName.equalsIgnoreCase("flags")) {
        // $NON-NLS-1$
        _flags = new Vector<Flag>();
    } else if (qName.equalsIgnoreCase("flag") && _flags != null) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        String flagName = attributes.getValue("id");
        // $NON-NLS-1$
        Boolean flagState = Boolean.valueOf(attributes.getValue("value"));
        FlagDefinition flagDefinition = flagDefinitions.getFlagDefinition(flagName);
        Flag flag = new Flag(flagName, flagState);
        flag.setLocation(_documentLocatorFile, _documentLocator);
        if (flagDefinition != null) {
            flag.setDefinition(flagDefinition);
        }
        _flags.add(flag);
    } else /* Parse features of the build spec */
    if (qName.equalsIgnoreCase("features")) {
        // $NON-NLS-1$
        _features = new Vector<Feature>();
    } else if (qName.equalsIgnoreCase("feature") && _features != null) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        String featureId = attributes.getValue("id");
        FeatureDefinition featureDefinition = featureDefinitions.get(featureId);
        Feature feature = new Feature(featureId);
        feature.setLocation(_documentLocatorFile, _documentLocator);
        if (featureDefinition != null) {
            feature.setDefinition(featureDefinition);
        }
        _features.add(feature);
    } else /* Parse sources of the build spec */
    if (qName.equalsIgnoreCase("source")) {
        // $NON-NLS-1$
        _sources = new Vector<Source>();
    } else if (qName.equalsIgnoreCase("project") && _sources != null) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        Source source = new Source(attributes.getValue("id"));
        source.setLocation(_documentLocatorFile, _documentLocator);
        _sources.add(source);
    } else /* Parse properties of the build spec */
    if (qName.equalsIgnoreCase("properties")) {
        // $NON-NLS-1$
        _properties = new Vector<Property>();
    } else if (qName.equalsIgnoreCase("property") && _properties != null) {
        // $NON-NLS-1$
        // $NON-NLS-1$ //$NON-NLS-2$
        Property property = new Property(attributes.getValue("name"), attributes.getValue("value"));
        property.setLocation(_documentLocatorFile, _documentLocator);
        _properties.add(property);
    }
}
Also used : Owner(com.ibm.j9tools.om.Owner) FlagDefinition(com.ibm.j9tools.om.FlagDefinition) Feature(com.ibm.j9tools.om.Feature) Flag(com.ibm.j9tools.om.Flag) Source(com.ibm.j9tools.om.Source) InputSource(org.xml.sax.InputSource) FeatureDefinition(com.ibm.j9tools.om.FeatureDefinition) Property(com.ibm.j9tools.om.Property) Vector(java.util.Vector)

Example 3 with FeatureDefinition

use of com.ibm.j9tools.om.FeatureDefinition in project openj9 by eclipse.

the class FeatureParser method parse.

/**
 * Parses the specified file.
 *
 * @param 	file	the feature file to be parsed
 * @return	the parsed feature
 *
 * @throws InvalidFeatureDefinitionException
 */
public FeatureDefinition parse(File file, FlagDefinitions flagDefinitions) throws InvalidFeatureDefinitionException, IOException {
    setDocumentLocatorFile(file);
    FileInputStream fis = new FileInputStream(file);
    FeatureDefinition result = parse(fis, file.getName().substring(0, file.getName().length() - ConfigDirectory.FEATURE_FILE_EXTENSION.length()), flagDefinitions);
    fis.close();
    return result;
}
Also used : FeatureDefinition(com.ibm.j9tools.om.FeatureDefinition) FileInputStream(java.io.FileInputStream)

Aggregations

FeatureDefinition (com.ibm.j9tools.om.FeatureDefinition)3 InputSource (org.xml.sax.InputSource)2 Feature (com.ibm.j9tools.om.Feature)1 Flag (com.ibm.j9tools.om.Flag)1 FlagDefinition (com.ibm.j9tools.om.FlagDefinition)1 InvalidFeatureDefinitionException (com.ibm.j9tools.om.InvalidFeatureDefinitionException)1 Owner (com.ibm.j9tools.om.Owner)1 Property (com.ibm.j9tools.om.Property)1 Source (com.ibm.j9tools.om.Source)1 FileInputStream (java.io.FileInputStream)1 Vector (java.util.Vector)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1