Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.xb.builder;
 
 
 
JBossXBBuilder.

Author(s):
Adrian Brock
Version:
$Revision: 1.1 $
 
 public class JBossXBBuilder
 {
   
The configuration
 
    static Configuration configuration = new PropertyConfiguration();
   
   
The string type
 
    static final ClassInfo STRING = .getClassInfo(String.class);
   
   
The object type
 
    static final ClassInfo OBJECT = .getClassInfo(Object.class);
   
   
Create a new schema binding initializer

Parameters:
<T> the root type
root the root class
Returns:
the initializer
Throws:
java.lang.IllegalArgumentException for a null root
 
    public static <T> SchemaBindingInitializer newInitializer(Class<T> root)
    {
       return new BuilderSchemaBindingInitializer<T>(root);
    }
   
   
Build from a preparsed schema binding

Parameters:
schemaBinding the schema binding
root the root
Throws:
java.lang.IllegalArgumentException for a null schema binding or root
 
    public static void build(SchemaBinding schemaBindingClass<?> root)
    {
       if (schemaBinding == null)
          throw new IllegalArgumentException("Null schemaBinding");
       if (root == null)
          throw new IllegalArgumentException("Null root");
 
       // TODO build
    }
   
   
Build the SchemaBinding from the class

Parameters:
root the root
Returns:
the schema binding
Throws:
java.lang.IllegalArgumentException for a null root
 
    public static SchemaBinding build(Class<?> root)
    {
       ClassInfo classInfo = ..getClassInfo(root);
 
       SchemaBinding binding = classInfo.getAttachment(SchemaBinding.class);
       if (binding == null)
      {
         JBossXBNoSchemaBuilder builder = new JBossXBNoSchemaBuilder(classInfo);
         binding = builder.build();
         classInfo.setAttachment(SchemaBinding.class.getName(), binding);
      }
      return binding;
   }
   
   
Initialize the schema binding from the root

Parameters:
schemaBinding the schema binding
classInfo the classInfo
   protected static void initSchema(SchemaBinding schemaBindingClassInfo classInfo)
   {
      // Look for a schema attribute on either the root or the root's package
      JBossXmlSchema schema = classInfo.getUnderlyingAnnotation(JBossXmlSchema.class);
      PackageInfo packageInfo = classInfo.getPackage();
      if (schema == null && packageInfo != null)
      {
         schema = packageInfo.getUnderlyingAnnotation(JBossXmlSchema.class);
      }
      
      // Use the root's package name
      String packageName = null;
      if (packageInfo != null)
         packageName = packageInfo.getName();
      // Look for annotation override
      if (schema != null)
      {
         String schemaPackageName = schema.packageName();
         if (..equals(schemaPackageName) == false)
            packageName = schemaPackageName;
         
         if(schema.xmlns().length > 0)
         {
            for(int i = 0; i < schema.xmlns().length; ++i)
            {
               schemaBinding.addPrefixMapping(schema.xmlns()[i].prefix(), schema.xmlns()[i].namespaceURI());
            }
         }
      }
      // Set the default namespace, if there are none already
      if (schemaBinding.getNamespaces().isEmpty())
      {
         String namespace = .;
         if (schema != null)
         {
            String schemaNamespace = schema.namespace();
            if (..equals(schemaNamespace) == false)
               namespace = schemaNamespace;
         }
         schemaBinding.setNamespaces(new HashSet<String>(Collections.singleton(namespace)));
      }
      
      // Apply the package name
      if (packageName != null)
      {
         PackageMetaData packageMetaData = new PackageMetaData();
         packageMetaData.setName(packageName);
         schemaBinding.setPackageMetaData(packageMetaData);
      }
      // Nothing more to do if no annotation
      if (schema == null)
         return;
      
      // Apply the annotation values
      schemaBinding.setIgnoreLowLine(schema.ignoreLowLine());
      schemaBinding.setReplacePropertyRefs(schema.replacePropertyRefs());
      schemaBinding.setStrictSchema(schema.strict());
   }

   
Generate an xml name from a clazz name

Parameters:
typeInfo the typeInfo
ignoreLowerLine whether to ignore the lower line
Returns:
the xml name
   public static String generateXMLNameFromClassName(TypeInfo typeInfoboolean ignoreLowerLine)
   {
      return generateXMLNameFromJavaName(typeInfo.getSimpleName(), trueignoreLowerLine);
   }
   
   
Generate an xml name from a java name

Parameters:
string the java name
dash whether to insert dashes to seperate words
ignoreLowerLine TODO ignore the lower line
Returns:
the xml name
   public static String generateXMLNameFromJavaName(String stringboolean dashboolean ignoreLowerLine)
   {
      // Whether we have seen a lower case character
      boolean seenLower = false;
      // Whether this is the first character
      boolean first = true;
      
      StringBuilder result = new StringBuilder(string.length());
      for (int i = 0; i < string.length(); ++i)
      {
         char c = string.charAt(i);
         // Lowercase until we see an uppercase character (but always on the first character)
         if (first || seenLower == false && Character.isUpperCase(c))
         {
            result.append(Character.toLowerCase(c));
            first = false;
         }
         // Insert the dash and start the next word with lowercase
         // but only if we have seen a lower case character
         else if (seenLower && Character.isUpperCase(c) && dash)
         {
            result.append('-');
            result.append(Character.toLowerCase(c));
            seenLower = false;
         }
         // Just append the character
         else
         {
            result.append(c);
            seenLower = true;
         }
      }
      return result.toString();
   }
New to GrepCode? Check out our FAQ X