You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by aj...@apache.org on 2006/04/27 10:58:04 UTC
svn commit: r397479 -
/webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
Author: ajith
Date: Thu Apr 27 01:57:55 2006
New Revision: 397479
URL: http://svn.apache.org/viewcvs?rev=397479&view=rev
Log:
Did an optimization of the code
Modified:
webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
Modified: webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java?rev=397479&r1=397478&r2=397479&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java (original)
+++ webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java Thu Apr 27 01:57:55 2006
@@ -35,6 +35,7 @@
import java.util.HashMap;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
import org.apache.axis2.namespace.Constants;
import org.apache.axis2.util.URLProcessor;
@@ -84,7 +85,6 @@
boolean debug = false;
/**
- *
* @param additionalSchemas
* @throws RuntimeException
*/
@@ -92,7 +92,6 @@
Element[] additionalSchemas, CodeGenConfiguration cgconfig) throws RuntimeException {
try {
-
//check for the imported types. Any imported types are supposed to be here also
if (schemas == null || schemas.isEmpty()) {
//there are no types to be code generated
@@ -134,12 +133,12 @@
XmlOptions options = new XmlOptions();
options.setLoadAdditionalNamespaces(
nameSpacesMap); //add the namespaces
- topLevelSchemaList.add(
- XmlObject.Factory.parse(
- getSchemaAsString(schema)
- , options));
+ topLevelSchemaList.add(
+ XmlObject.Factory.parse(
+ getSchemaAsString(schema)
+ , options));
- }
+ }
// add the third party schemas
//todo perhaps checking the namespaces would be a good idea to
@@ -148,13 +147,13 @@
completeSchemaList.add(XmlObject.Factory.parse(
additionalSchemas[i]
, null));
- topLevelSchemaList.add(XmlObject.Factory.parse(
+ topLevelSchemaList.add(XmlObject.Factory.parse(
additionalSchemas[i]
, null));
}
//compile the type system
- Axis2EntityResolver er = new Axis2EntityResolver();
+ Axis2EntityResolver er = new Axis2EntityResolver();
er.setSchemas(convertToSchemaDocumentArray(completeSchemaList));
er.setBaseUri(cgconfig.getBaseURI());
@@ -235,7 +234,6 @@
}
/**
- *
* @param sts
* @return
*/
@@ -249,14 +247,13 @@
for (Iterator iterator = allSeenTypes.iterator(); iterator.hasNext();) {
SchemaType stype = (SchemaType) iterator.next();
- findPlainBase64Types(stype, base64Types,new ArrayList());
+ findPlainBase64Types(stype, base64Types, new ArrayList());
}
return base64Types;
}
/**
- *
* @param stype
* @param base64Types
*/
@@ -270,7 +267,7 @@
for (int i = 0; i < elementProperties.length; i++) {
schemaType = elementProperties[i].getType();
name = elementProperties[i].getName();
- if (!base64Types.contains(name) && !processedTypes.contains(schemaType.getName())){
+ if (!base64Types.contains(name) && !processedTypes.contains(schemaType.getName())) {
processedTypes.add(stype.getName());
if (schemaType.isPrimitiveType()) {
SchemaType primitiveType = schemaType.getPrimitiveType();
@@ -279,7 +276,7 @@
}
} else {
- findPlainBase64Types(schemaType, base64Types,processedTypes);
+ findPlainBase64Types(schemaType, base64Types, processedTypes);
}
}
}
@@ -348,16 +345,16 @@
public Axis2BindingConfig(Map uri2packageMappings) {
this.uri2packageMappings = uri2packageMappings;
- if (this.uri2packageMappings==null){
+ if (this.uri2packageMappings == null) {
//make an empty one to avoid nasty surprises
this.uri2packageMappings = new HashMap();
}
}
public String lookupPackageForNamespace(String uri) {
- if (uri2packageMappings.containsKey(uri)){
- return (String)uri2packageMappings.get(uri);
- }else{
+ if (uri2packageMappings.containsKey(uri)) {
+ return (String) uri2packageMappings.get(uri);
+ } else {
return URLProcessor.makePackageName(uri);
}
@@ -365,7 +362,6 @@
}
/**
- *
* @param vec
* @return
*/
@@ -381,7 +377,7 @@
if (!uniqueSchemaTns.contains(s.getTargetNamespace())) {
uniqueSchemas.add(schemaDocuments[i]);
uniqueSchemaTns.add(s.getTargetNamespace());
- }else if (s.getTargetNamespace()==null){
+ } else if (s.getTargetNamespace() == null) {
//add anyway
uniqueSchemas.add(schemaDocuments[i]);
}
@@ -395,6 +391,7 @@
* Converts a given vector of schemaDocuments to XmlBeans processable
* schema objects. One drawback we have here is the non-inclusion of
* untargeted namespaces
+ *
* @param vec
* @return
*/
@@ -410,7 +407,7 @@
if (!uniqueSchemaTns.contains(s.getTargetNamespace())) {
uniqueSchemas.add(s);
uniqueSchemaTns.add(s.getTargetNamespace());
- }else if(s.getTargetNamespace()==null){
+ } else if (s.getTargetNamespace() == null) {
uniqueSchemas.add(s);
}
}
@@ -430,15 +427,15 @@
}
/**
- * @see EntityResolver#resolveEntity(String, String)
- * @param publicId - this is the target namespace
- * @param systemId - this is the location (value of schemaLocation)
+ * @param publicId - this is the target namespace
+ * @param systemId - this is the location (value of schemaLocation)
* @return
+ * @see EntityResolver#resolveEntity(String, String)
*/
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException,IOException{
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
//System.out.println("Lookup:" + "[ " + publicId + "]" + "[" + systemId + "]");
try {
- for (int i = 0; i < schemas.length; i++) {
+ for (int i = 0; i < schemas.length; i++){
SchemaDocument.Schema schema = schemas[i].getSchema();
if (schema.getTargetNamespace() != null &&
publicId != null &&
@@ -450,41 +447,16 @@
}
}
}
- if(systemId.indexOf(':') == -1) {
- File f;
- if (baseUri!=null){
- URI uri = new URI(baseUri + systemId);
- if (baseUri.startsWith("file:")){
- //it's file
- f=new File(uri);
- }else{
- return new InputSource(
- uri.toURL().openStream()
- );
- }
- }else{
- if (systemId.startsWith("http://") ||
- systemId.startsWith("https://")){
- return new InputSource(systemId);
- }else{
- //treat it as a file
- f = new File(systemId);
- }
-
- }
- if(f.exists()) {
- try {
- return new InputSource(new FileInputStream(f));
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-
+ if (systemId.indexOf(':') == -1) {
+ //if the base URI is missing then attache the file:/// to it
+ //if the systemId actually had a scheme then as per the URL
+ //constructor, the context URL scheme should be ignored
+ baseUri = (baseUri == null) ? "file:///" : baseUri;
+ URL url = new URL(new URL(baseUri),systemId);
+ return new InputSource(url.openStream() );
}
return XMLUtils.getEmptyInputSource();
- } catch (URISyntaxException e) {
- throw new SAXException(e);
- }catch (Exception e){
+ } catch (Exception e) {
throw new SAXException(e);
}
}