Package org.apache.cxf.javascript
Class JavascriptUtils
- java.lang.Object
-
- org.apache.cxf.javascript.JavascriptUtils
-
public class JavascriptUtils extends Object
A set of functions that assist in JavaScript generation. This includes functions for appending strings of JavaScript to a buffer as well as some type utilities.
-
-
Constructor Summary
Constructors Constructor Description JavascriptUtils(StringBuilder code)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendElse()voidappendExpression(String value)voidappendLine(String line)voidappendString(String value)emit javascript to append a value to the accumulator.voidendBlock()StringescapeStringQuotes(String data)voidgenerateCodeToSerializeAny(ParticleInfo itemInfo, String prefix, SchemaCollection schemaCollection)Generate code to serialize an xs:any.voidgenerateCodeToSerializeElement(ParticleInfo elementInfo, String referencePrefix, SchemaCollection schemaCollection)Given an element, generate the serialization code.static org.apache.ws.commons.schema.XmlSchemaAllgetAll(org.apache.ws.commons.schema.XmlSchemaComplexType type)static org.apache.ws.commons.schema.XmlSchemaChoicegetChoice(org.apache.ws.commons.schema.XmlSchemaComplexType type)static List<org.apache.ws.commons.schema.XmlSchemaObject>getContentElements(org.apache.ws.commons.schema.XmlSchemaComplexType type, SchemaCollection collection)static org.apache.ws.commons.schema.XmlSchemaSequencegetContentSequence(org.apache.ws.commons.schema.XmlSchemaComplexType type)StringgetDefaultValueForSimpleType(org.apache.ws.commons.schema.XmlSchemaType type)static org.apache.ws.commons.schema.XmlSchemaAnnotatedgetObjectAnnotated(org.apache.ws.commons.schema.XmlSchemaObject object, QName contextName)If the object is an attribute or an anyAttribute, return the 'Annotated'.static org.apache.ws.commons.schema.XmlSchemaParticlegetObjectParticle(org.apache.ws.commons.schema.XmlSchemaObject object, QName contextName, org.apache.ws.commons.schema.XmlSchema currentSchema)If the object is an element or an any, return the particle.static org.apache.ws.commons.schema.XmlSchemaSequencegetSequence(org.apache.ws.commons.schema.XmlSchemaComplexType type)booleanisStringSimpleType(QName typeName)static StringjavaScriptNameToken(String token)StringjavascriptParseExpression(org.apache.ws.commons.schema.XmlSchemaType type, String value)static booleanmtomCandidateType(org.apache.ws.commons.schema.XmlSchemaType type)Return true for xsd:base64Binary or simple restrictions of it, as in the xmime stock type.static booleannotVeryComplexType(org.apache.ws.commons.schema.XmlSchemaType type)We don't want to generate Javascript overhead for complex types with simple content models, at least until or unless we decide to cope with attributes in a general way.static StringprotectSingleQuotes(String value)voidsetXmlStringAccumulator(String variableName)voidstartBlock()voidstartDo()voidstartFor(String start, String test, String increment)voidstartForIn(String var, String collection)voidstartIf(String test)voidstartWhile(String test)voidstartXmlStringAccumulator(String variableName)
-
-
-
Constructor Detail
-
JavascriptUtils
public JavascriptUtils(StringBuilder code)
-
-
Method Detail
-
getDefaultValueForSimpleType
public String getDefaultValueForSimpleType(org.apache.ws.commons.schema.XmlSchemaType type)
-
isStringSimpleType
public boolean isStringSimpleType(QName typeName)
-
setXmlStringAccumulator
public void setXmlStringAccumulator(String variableName)
-
startXmlStringAccumulator
public void startXmlStringAccumulator(String variableName)
-
appendString
public void appendString(String value)
emit javascript to append a value to the accumulator.- Parameters:
value-
-
appendExpression
public void appendExpression(String value)
-
appendLine
public void appendLine(String line)
-
startIf
public void startIf(String test)
-
startBlock
public void startBlock()
-
appendElse
public void appendElse()
-
endBlock
public void endBlock()
-
startWhile
public void startWhile(String test)
-
startDo
public void startDo()
-
javascriptParseExpression
public String javascriptParseExpression(org.apache.ws.commons.schema.XmlSchemaType type, String value)
-
notVeryComplexType
public static boolean notVeryComplexType(org.apache.ws.commons.schema.XmlSchemaType type)
We don't want to generate Javascript overhead for complex types with simple content models, at least until or unless we decide to cope with attributes in a general way.- Parameters:
type-- Returns:
-
mtomCandidateType
public static boolean mtomCandidateType(org.apache.ws.commons.schema.XmlSchemaType type)
Return true for xsd:base64Binary or simple restrictions of it, as in the xmime stock type.- Parameters:
type-- Returns:
-
generateCodeToSerializeElement
public void generateCodeToSerializeElement(ParticleInfo elementInfo, String referencePrefix, SchemaCollection schemaCollection)
Given an element, generate the serialization code.- Parameters:
elementInfo- description of the element we are serializingreferencePrefix- prefix to the Javascript variable. Nothing for args, this._ for members.schemaCollection- caller's schema collection.
-
generateCodeToSerializeAny
public void generateCodeToSerializeAny(ParticleInfo itemInfo, String prefix, SchemaCollection schemaCollection)
Generate code to serialize an xs:any. There is too much duplicate code with the element serializer; fix that some day.- Parameters:
itemInfo-prefix-schemaCollection-
-
getObjectAnnotated
public static org.apache.ws.commons.schema.XmlSchemaAnnotated getObjectAnnotated(org.apache.ws.commons.schema.XmlSchemaObject object, QName contextName)If the object is an attribute or an anyAttribute, return the 'Annotated'. If it's not one of those, or it's a group, throw. We're not ready for groups yet.- Parameters:
object-
-
getObjectParticle
public static org.apache.ws.commons.schema.XmlSchemaParticle getObjectParticle(org.apache.ws.commons.schema.XmlSchemaObject object, QName contextName, org.apache.ws.commons.schema.XmlSchema currentSchema)If the object is an element or an any, return the particle. If it's not a particle, or it's a group, throw. We're not ready for groups yet.- Parameters:
object-
-
getSequence
public static org.apache.ws.commons.schema.XmlSchemaSequence getSequence(org.apache.ws.commons.schema.XmlSchemaComplexType type)
-
getChoice
public static org.apache.ws.commons.schema.XmlSchemaChoice getChoice(org.apache.ws.commons.schema.XmlSchemaComplexType type)
-
getAll
public static org.apache.ws.commons.schema.XmlSchemaAll getAll(org.apache.ws.commons.schema.XmlSchemaComplexType type)
-
getContentElements
public static List<org.apache.ws.commons.schema.XmlSchemaObject> getContentElements(org.apache.ws.commons.schema.XmlSchemaComplexType type, SchemaCollection collection)
-
getContentSequence
public static org.apache.ws.commons.schema.XmlSchemaSequence getContentSequence(org.apache.ws.commons.schema.XmlSchemaComplexType type)
-
-