blob: 114a8453d40bdf5703129bd34d129ce2e4211c6f [file] [log] [blame]
/*
* 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.axiom.ts.om.sourcedelement;
import java.io.StringReader;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMSourcedElement;
import org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromReader;
public abstract class OMSourcedElementVariant {
public static final OMSourcedElementVariant[] INSTANCES = {
new OMSourcedElementVariant("qname-aware-source", false, false, false) {
public OMSourcedElement createOMSourcedElement(OMFactory factory, QName qname) {
return factory.createOMElement(new WrappedTextNodeOMDataSourceFromReader(qname, new StringReader("test")));
}
},
new OMSourcedElementVariant("unknown-name", true, true, true) {
public OMSourcedElement createOMSourcedElement(OMFactory factory, QName qname) {
// TODO: can't use createOMElement(QName) here because it would generate a prefix if the prefix in the QName is empty
OMElement orgElement = factory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix());
return factory.createOMElement(new TestDataSource(orgElement.toString()));
}
}
};
private final String name;
private final boolean localNameRequiresExpansion;
private final boolean namespaceURIRequiresExpansion;
private final boolean prefixRequiresExpansion;
public OMSourcedElementVariant(String name, boolean localNameRequiresExpansion,
boolean namespaceURIRequiresExpansion,
boolean prefixRequiresExpansion) {
this.name = name;
this.localNameRequiresExpansion = localNameRequiresExpansion;
this.namespaceURIRequiresExpansion = namespaceURIRequiresExpansion;
this.prefixRequiresExpansion = prefixRequiresExpansion;
}
public String getName() {
return name;
}
public boolean isLocalNameRequiresExpansion() {
return localNameRequiresExpansion;
}
public boolean isNamespaceURIRequiresExpansion() {
return namespaceURIRequiresExpansion;
}
public boolean isPrefixRequiresExpansion() {
return prefixRequiresExpansion;
}
public abstract OMSourcedElement createOMSourcedElement(OMFactory factory, QName qname);
}