use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class JavascriptUtils method generateCodeToSerializeElement.
/**
* Given an element, generate the serialization code.
*
* @param elementInfo description of the element we are serializing
* @param referencePrefix prefix to the Javascript variable. Nothing for
* args, this._ for members.
* @param schemaCollection caller's schema collection.
*/
public void generateCodeToSerializeElement(ParticleInfo elementInfo, String referencePrefix, SchemaCollection schemaCollection) {
if (elementInfo.isGroup()) {
for (ParticleInfo childElement : elementInfo.getChildren()) {
generateCodeToSerializeElement(childElement, referencePrefix, schemaCollection);
}
return;
}
XmlSchemaType type = elementInfo.getType();
boolean nillable = elementInfo.isNillable();
boolean optional = elementInfo.isOptional();
boolean array = elementInfo.isArray();
boolean mtom = treatAsMtom(elementInfo.getParticle());
String jsVar = referencePrefix + elementInfo.getJavascriptName();
appendLine("// block for local variables");
// allow local variables.
startBlock();
// first question: optional?
if (optional) {
startIf(jsVar + " != null");
}
// and nillable in the array case applies to the elements.
if (nillable && !array) {
startIf(jsVar + " == null");
appendString("<" + elementInfo.getXmlName() + " " + XmlSchemaUtils.XSI_NIL + "/>");
appendElse();
}
if (array) {
// protected against null in arrays.
startIf(jsVar + " != null");
startFor("var ax = 0", "ax < " + jsVar + ".length", "ax ++");
jsVar = jsVar + "[ax]";
// we need an extra level of 'nil' testing here. Or do we, depending
// on the type structure?
// Recode and fiddle appropriately.
startIf(jsVar + " == null");
if (nillable) {
appendString("<" + elementInfo.getXmlName() + " " + XmlSchemaUtils.XSI_NIL + "/>");
} else {
appendString("<" + elementInfo.getXmlName() + "/>");
}
appendElse();
}
if (elementInfo.isAnyType()) {
serializeAnyTypeElement(elementInfo, jsVar);
// mtom can be turned on for the special complex type that is really a basic type with
// a content-type attribute.
} else if (!mtom && type instanceof XmlSchemaComplexType) {
// it has a value
// pass the extra null in the slot for the 'extra namespaces' needed
// by 'any'.
appendExpression(jsVar + ".serialize(cxfjsutils, '" + elementInfo.getXmlName() + "', null)");
} else {
// simple type
appendString("<" + elementInfo.getXmlName() + ">");
if (mtom) {
appendExpression("cxfjsutils.packageMtom(" + jsVar + ")");
} else {
appendExpression("cxfjsutils.escapeXmlEntities(" + jsVar + ")");
}
appendString("</" + elementInfo.getXmlName() + ">");
}
if (array) {
// for the extra level of nil checking, which might be
endBlock();
// wrong.
// for the for loop.
endBlock();
// the null protection.
endBlock();
}
if (nillable && !array) {
endBlock();
}
if (optional) {
endBlock();
}
// local variables
endBlock();
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class CorbaUtils method getXmlSchemaType.
public static XmlSchemaType getXmlSchemaType(ServiceInfo serviceInfo, QName name) {
XmlSchemaType result = null;
if ((name != null) && (serviceInfo != null)) {
SchemaCollection col = serviceInfo.getXmlSchemaCollection();
result = col.getTypeByQName(name);
if (result == null) {
// check the name, if it is an element
XmlSchemaElement el = col.getElementByQName(name);
if (el != null) {
result = el.getSchemaType();
}
}
}
return result;
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class JAXBSchemaInitializer method begin.
@Override
public void begin(MessagePartInfo part) {
// Check to see if the WSDL information has been filled in for us.
if (part.getTypeQName() != null || part.getElementQName() != null) {
checkForExistence(part);
return;
}
Class<?> clazz = part.getTypeClass();
if (clazz == null) {
return;
}
boolean isFromWrapper = part.getMessageInfo().getOperation().isUnwrapped();
boolean isList = false;
if (clazz.isArray()) {
if (isFromWrapper && !Byte.TYPE.equals(clazz.getComponentType())) {
clazz = clazz.getComponentType();
} else if (!isFromWrapper) {
Annotation[] anns = (Annotation[]) part.getProperty("parameter.annotations");
for (Annotation a : anns) {
if (a instanceof XmlList) {
part.setProperty("honor.jaxb.annotations", Boolean.TRUE);
clazz = clazz.getComponentType();
isList = true;
}
}
}
}
Annotation[] anns = (Annotation[]) part.getProperty("parameter.annotations");
XmlJavaTypeAdapter jta = findFromTypeAdapter(context, clazz, anns);
JAXBBeanInfo jtaBeanInfo = null;
if (jta != null) {
jtaBeanInfo = findFromTypeAdapter(context, jta.value());
}
JAXBBeanInfo beanInfo = getBeanInfo(clazz);
if (jtaBeanInfo != beanInfo && jta != null) {
beanInfo = jtaBeanInfo;
if (anns == null) {
anns = new Annotation[] { jta };
} else {
boolean found = false;
for (Annotation t : anns) {
if (t == jta) {
found = true;
}
}
if (!found) {
Annotation[] tmp = new Annotation[anns.length + 1];
System.arraycopy(anns, 0, tmp, 0, anns.length);
tmp[anns.length] = jta;
anns = tmp;
}
}
part.setProperty("parameter.annotations", anns);
part.setProperty("honor.jaxb.annotations", Boolean.TRUE);
}
if (beanInfo == null) {
if (Exception.class.isAssignableFrom(clazz)) {
QName name = (QName) part.getMessageInfo().getProperty("elementName");
part.setElementQName(name);
buildExceptionType(part, clazz);
}
return;
}
boolean isElement = beanInfo.isElement() && !Boolean.TRUE.equals(part.getMessageInfo().getOperation().getProperty("operation.force.types"));
boolean hasType = !beanInfo.getTypeNames().isEmpty();
if (isElement && isFromWrapper && hasType) {
// if there is both a Global element and a global type, AND we are in a wrapper,
// make sure we use the type instead of a ref to the element to
// match the rules for wrapped/unwrapped
isElement = false;
}
part.setElement(isElement);
if (isElement) {
QName name = new QName(beanInfo.getElementNamespaceURI(null), beanInfo.getElementLocalName(null));
XmlSchemaElement el = schemas.getElementByQName(name);
if (el != null && el.getRef().getTarget() != null) {
part.setTypeQName(el.getRef().getTargetQName());
} else {
part.setElementQName(name);
}
part.setXmlSchema(el);
} else {
QName typeName = getTypeName(beanInfo);
if (typeName != null) {
XmlSchemaType type = schemas.getTypeByQName(typeName);
if (isList && type instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(type.getParent(), false);
XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
XmlSchemaSimpleType stype = (XmlSchemaSimpleType) type;
list.setItemTypeName(stype.getQName());
simpleType.setContent(list);
part.setXmlSchema(simpleType);
if (part.getConcreteName() == null) {
part.setConcreteName(new QName(null, part.getName().getLocalPart()));
}
} else {
part.setTypeQName(typeName);
part.setXmlSchema(type);
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaType in project ddf by codice.
the class FeatureMetacardType method processComplexType.
private void processComplexType(XmlSchemaElement xmlSchemaElement) {
if (!processGmlType(xmlSchemaElement)) {
XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
if (schemaType instanceof XmlSchemaComplexType) {
XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaType;
if (complexType.getParticle() != null) {
processXmlSchemaParticle(complexType.getParticle());
} else if (complexType.getContentModel() != null) {
XmlSchemaContent content = complexType.getContentModel().getContent();
if (content instanceof XmlSchemaComplexContentExtension) {
XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension) content;
processXmlSchemaParticle(extension.getParticle());
} else if (content instanceof XmlSchemaSimpleContentExtension) {
final XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension) content;
processSimpleContent(xmlSchemaElement, extension.getBaseTypeName());
} else if (content instanceof XmlSchemaSimpleContentRestriction) {
final XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) content;
processSimpleContent(xmlSchemaElement, restriction.getBaseTypeName());
}
}
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaType in project cxf by apache.
the class SchemaCollectionContextProxy method mapToSchemaType.
private XmlSchemaType mapToSchemaType(Class<?> cls, String namespace) {
QName qn = getTypeQName(cls, namespace);
XmlSchemaType type = schemas.getTypeByQName(qn);
if (type == null && cls.isArray()) {
Class<?> compType = cls.getComponentType();
int count = 1;
while (compType.isArray()) {
compType = compType.getComponentType();
count++;
}
QName aqn = getTypeQName(compType, namespace);
while (count > 0) {
aqn = new QName(aqn.getNamespaceURI(), aqn.getLocalPart() + "Array");
count--;
}
type = schemas.getTypeByQName(aqn);
if (type == null) {
type = schemas.getTypeByQName(new QName("http://jaxb.dev.java.net/array", aqn.getLocalPart()));
}
}
/*
if (type == null) {
System.out.println("HELP: " + cls.getName());
}
*/
return type;
}
Aggregations