Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2008, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file 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.util;
 
JBossXB deployer helper.

Parameters:
<T> the expected type
Author(s):
Ales Justin
 
 public class JBossXBHelper<T> implements FeatureAware
 {
   
The log
 
    private Logger log = Logger.getLogger(JBossXBHelper.class);

   
Unmarshaller factory
 
    private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance();

   
The singleton schema resolver
 
    private static MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();

   
The output
 
    private Class<T> output;

   
Whether the Unmarshaller will use schema validation
 
    private boolean useSchemaValidation = true;

   
Whether to validate
 
    private boolean useValidation = true;

   
Create a new SchemaResolverDeployer.

Parameters:
output the output
Throws:
java.lang.IllegalArgumentException for a null output
 
    public JBossXBHelper(Class<T> output)
    {
       if (output == null)
          throw new IllegalArgumentException("Null output.");
       this. = output;
    }
 
    public void setFeature(String featureNameboolean flagthrows Exception
    {
       .setFeature(featureNameflag);
    }

   
Get the useSchemaValidation.

Returns:
the useSchemaValidation.
 
    public boolean isUseSchemaValidation()
    {
       return ;
    }

   
Set the useSchemaValidation.

Parameters:
useSchemaValidation the useSchemaValidation.
 
    public void setUseSchemaValidation(boolean useSchemaValidation)
    {
       this. = useSchemaValidation;
    }

   
Get the useValidation.

Returns:
the useValidation.
   public boolean isUseValidation()
   {
      return ;
   }

   
Set the useValidation.

Parameters:
useValidation the useValidation.
   public void setUseValidation(boolean useValidation)
   {
      this. = useValidation;
   }

   
Add class binding.

Parameters:
namespace the namespace
metadata the metadata
   public static void addClassBinding(String namespaceClass<?> metadata)
   {
      .mapURIToClass(namespacemetadata);
   }

   
Remove class binding.

Parameters:
namespace the namespace
   public static void removeClassBinding(String namespace)
   {
      .removeURIToClassMapping(namespace);
   }

   
Find the namespace on class/package

Parameters:
metadata the metadata class
Returns:
jboss xml schema namespace
   public static String findNamespace(Class<?> metadata)
   {
      JBossXmlSchema jBossXmlSchema = metadata.getAnnotation(JBossXmlSchema.class);
      if (jBossXmlSchema == null)
      {
         Package pckg = metadata.getPackage();
         if (pckg != null)
            jBossXmlSchema = pckg.getAnnotation(JBossXmlSchema.class);
      }
      return jBossXmlSchema != null ? jBossXmlSchema.namespace() : null;
   }

   
Parse file to output metadata.

Parameters:
source the source to parse
Returns:
new metadata instance
Throws:
java.lang.Exception for any error
   public T parse(InputSource sourcethrows Exception
   {
      return parse(source);
   }

   
Parse the file to create metadata instance.

Parameters:
<U> the expect type
expectedType the expected type
source the source
Returns:
new metadata instance
Throws:
java.lang.Exception for any error
   public <U> U parse(Class<U> expectedTypeInputSource sourcethrows Exception
   {
      if (expectedType == null)
         throw new IllegalArgumentException("Null expected type");
      if (source == null)
         throw new IllegalArgumentException("Null source");
      .debug("Parsing file: " + source + " for type: " + expectedType);
      Unmarshaller unmarshaller = .newUnmarshaller();
      unmarshaller.setSchemaValidation(isUseSchemaValidation());
      unmarshaller.setValidation(isUseValidation());
      Object parsed = unmarshaller.unmarshal(source);
      if (parsed == null)
         throw new Exception("The xml " + source + " is not well formed!");
      .debug("Parsed file: " + source + " to: " + parsed);
      return expectedType.cast(parsed);
   }

   
Parse the file using object model factory.

Parameters:
source the source to parse
root the previous root
omf the object model factory
Returns:
new metadata instance
Throws:
java.lang.Exception for any error
   public T parse(InputSource source, T rootObjectModelFactory omfthrows Exception
   {
      return parse(sourcerootomf);
   }

   
Parse the file using object model factory.

Parameters:
<U> the expect type
expectedType the expected type
source the source to parse
root the previous root
omf the object model factory
Returns:
new metadata instance
Throws:
java.lang.Exception for any error
   public <U> U parse(Class<U> expectedTypeInputSource source, U rootObjectModelFactory omfthrows Exception
   {
      if (source == null)
         throw new IllegalArgumentException("Null source");
      .debug("Parsing source: " + source + " for deploymentType: " + expectedType);
      Unmarshaller unmarshaller = .newUnmarshaller();
      unmarshaller.setSchemaValidation(isUseSchemaValidation());
      unmarshaller.setValidation(isUseValidation());
      Object parsed = unmarshaller.unmarshal(sourceomfroot);
      if (parsed == null)
         throw new Exception("The xml " + source + " is not well formed!");
      .debug("Parsed file: " + source + " to: "+parsed);
      return expectedType.cast(parsed);
   }
New to GrepCode? Check out our FAQ X