当前位置: 首页>>代码示例>>Java>>正文


Java UnmarshalException类代码示例

本文整理汇总了Java中javax.xml.bind.UnmarshalException的典型用法代码示例。如果您正苦于以下问题:Java UnmarshalException类的具体用法?Java UnmarshalException怎么用?Java UnmarshalException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UnmarshalException类属于javax.xml.bind包,在下文中一共展示了UnmarshalException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createUnmarshalException

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
/**
 * Creates an UnmarshalException from a SAXException.
 *
 * This is an utility method provided for the derived classes.
 *
 * <p>
 * When a provider-implemented ContentHandler wants to throw a
 * JAXBException, it needs to wrap the exception by a SAXException.
 * If the unmarshaller implementation blindly wrap SAXException
 * by JAXBException, such an exception will be a JAXBException
 * wrapped by a SAXException wrapped by another JAXBException.
 * This is silly.
 *
 * <p>
 * This method checks the nested exception of SAXException
 * and reduce those excessive wrapping.
 *
 * @return the resulting UnmarshalException
 */
protected UnmarshalException createUnmarshalException( SAXException e ) {
    // check the nested exception to see if it's an UnmarshalException
    Exception nested = e.getException();
    if(nested instanceof UnmarshalException)
        return (UnmarshalException)nested;

    if(nested instanceof RuntimeException)
        // typically this is an unexpected exception,
        // just throw it rather than wrap it, so that the full stack
        // trace can be displayed.
        throw (RuntimeException)nested;


    // otherwise simply wrap it
    if(nested!=null)
        return new UnmarshalException(nested);
    else
        return new UnmarshalException(e);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:AbstractUnmarshallerImpl.java

示例2: unmarshallUploadFromDocument

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
public static  <T> T unmarshallUploadFromDocument(Document dom,
        String rootElement, Class<T> resultingClass)
        throws UnmarshalException {
    try {           
        String xmlString = getStringFromXML(dom, rootElement); 
        xmlString = xmlString.replaceAll(" xmlns(?:.*?)?=\".*?\"", "");            
        
        if (rootElement != null) {
            xmlString = "<" + rootElement + ">" + xmlString + "</"
                    + rootElement + ">";
        }

        return (T) unmarshallFromString(xmlString, resultingClass);
    } catch (Throwable e) {
        throw new UnmarshalException("Unable to unmarshal string", e);
    }
}
 
开发者ID:webinerds,项目名称:s3-proxy-chunk-upload,代码行数:18,代码来源:JAXBUtils.java

示例3: unmarshallUploadFromDocumentString

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
public static final <T> T unmarshallUploadFromDocumentString(String xmlString,
                                                       String rootElement, Class<T> resultingClass)
        throws UnmarshalException {
    try {
        xmlString = xmlString.replaceAll(" xmlns(?:.*?)?=\".*?\"", "");

        if (rootElement != null) {
            xmlString = "<" + rootElement + ">" + xmlString + "</"
                    + rootElement + ">";
        }

        return (T) unmarshallFromString(xmlString, resultingClass);
    } catch (Throwable e) {
        throw new UnmarshalException("Unable to unmarshall string", e);
    }
}
 
开发者ID:webinerds,项目名称:s3-proxy-chunk-upload,代码行数:17,代码来源:JAXBUtils.java

示例4: getStringFromXML

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
private static String getStringFromXML(Document dom,
        String rootElement) throws UnmarshalException {
    try {
        DOMSource domSource = new DOMSource(dom);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.setOutputProperty("omit-xml-declaration", "yes");
        transformer.transform(domSource, result);
        String xmlString = writer.toString();            
        
        if (rootElement != null) {
            xmlString = "<" + rootElement + ">" + xmlString + "</"
                    + rootElement + ">";
        }
        
        return xmlString;
    } catch (Throwable e) {
        throw new UnmarshalException("Unable to unmarshall string", e);
    }
}
 
开发者ID:webinerds,项目名称:s3-proxy-chunk-upload,代码行数:23,代码来源:JAXBUtils.java

示例5: unmarshallBusinessProcessXml

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
@Nonnull
@Override
public Process unmarshallBusinessProcessXml(@NotNull final File file) throws UnmarshalException {
    Validate.notNull(file);

    try {
        if (null == this.jaxbContext) {
            LOG.error(String.format(
                "Can not unmarshall '%s' because JAXBContext has not been created.", file.getAbsolutePath()
            ));

            return null;
        }

        final Unmarshaller jaxbUnmarshaller = this.jaxbContext.get().createUnmarshaller();

        return (Process) jaxbUnmarshaller.unmarshal(file);
    } catch (Exception e) {
        throw new UnmarshalException("Can not unmarshall " + file.getAbsolutePath(), e);
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:22,代码来源:DefaultBpJaxbService.java

示例6: handleEvent

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
/**
 * Reports an error to the user, and asks if s/he wants
 * to recover. If the canRecover flag is false, regardless
 * of the client instruction, an exception will be thrown.
 *
 * Only if the flag is true and the user wants to recover from an error,
 * the method returns normally.
 *
 * The thrown exception will be catched by the unmarshaller.
 */
public void handleEvent(ValidationEvent event, boolean canRecover ) throws SAXException {
    ValidationEventHandler eventHandler = parent.getEventHandler();

    boolean recover = eventHandler.handleEvent(event);

    // if the handler says "abort", we will not return the object
    // from the unmarshaller.getResult()
    if(!recover)    aborted = true;

    if( !canRecover || !recover )
        throw new SAXParseException2( event.getMessage(), locator,
            new UnmarshalException(
                event.getMessage(),
                event.getLinkedException() ) );
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:UnmarshallingContext.java

示例7: handleStreamException

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
private static JAXBException handleStreamException(XMLStreamException e) {
    // StAXStreamConnector wraps SAXException to XMLStreamException.
    // XMLStreamException doesn't print its nested stack trace when it prints
    // its stack trace, so if we wrap XMLStreamException in JAXBException,
    // it becomes harder to find out the real problem.
    // So we unwrap them here. But we don't want to unwrap too eagerly, because
    // that could throw away some meaningful exception information.
    Throwable ne = e.getNestedException();
    if(ne instanceof JAXBException) {
        return (JAXBException)ne;
    }
    if(ne instanceof SAXException) {
        return new UnmarshalException(ne);
    }
    return new UnmarshalException(e);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:UnmarshallerImpl.java

示例8: loadConfiguration

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
static public Configuration loadConfiguration(String path) throws UnmarshalException {
    Configuration configuration;
    File file = new File(path);
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(Configuration.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        configuration = (Configuration) unmarshaller.unmarshal(file);
        if (configuration.debug == null) {
            configuration.debug = false;
        }
    } catch (JAXBException e) {
        logger.error("Failed to parse configuration file (file path: "
                + file.getAbsolutePath() + ").", e);
        configuration = null;
    }
    if (configuration == null) {
        throw new UnmarshalException("Failed to load configuration. Make sure that " + file.getAbsolutePath() + " exists and is configured correctly");
    }
    return configuration;
}
 
开发者ID:razreg,项目名称:ubongo,代码行数:21,代码来源:Configuration.java

示例9: convertJaxbException

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
/**
 * Convert the given {@code JAXBException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * @param ex {@code JAXBException} that occured
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertJaxbException(JAXBException ex) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JAXB validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		return new MarshallingFailureException("JAXB marshalling exception", ex);
	}
	else if (ex instanceof UnmarshalException) {
		return new UnmarshallingFailureException("JAXB unmarshalling exception", ex);
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown JAXB exception", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:Jaxb2Marshaller.java

示例10: unmarshal

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
/**
 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
 */
@Override
public Map<String, String> unmarshal(QualificationList v) throws Exception {
    if (v != null) {
        NormalizedStringAdapter normalizedStringAdapter = new NormalizedStringAdapter();
        Map<String, String> map = new HashMap<String, String>();
        for (MapStringStringAdapter.StringMapEntry stringMapEntry : v.getQualifications()) {
            String tempKey = normalizedStringAdapter.unmarshal(stringMapEntry.getKey());
            if (StringUtils.isBlank(tempKey)) {
                throw new UnmarshalException("Cannot create a qualification entry with a blank key");
            } else if (map.containsKey(tempKey)) {
                throw new UnmarshalException("Cannot create more than one qualification entry with a key of \"" + tempKey + "\"");
            }
            map.put(tempKey, normalizedStringAdapter.unmarshal(stringMapEntry.getValue()));
        }
    }
    return null;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:21,代码来源:QualificationListAdapter.java

示例11: unmarshal

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
/**
 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
 */
@Override
public Map<String, String> unmarshal(PermissionDetailList v) throws Exception {
    if (v != null) {
        NormalizedStringAdapter normalizedStringAdapter = new NormalizedStringAdapter();
        Map<String, String> map = new HashMap<String, String>();
        for (MapStringStringAdapter.StringMapEntry stringMapEntry : v.getPermissionDetails()) {
            String tempKey = normalizedStringAdapter.unmarshal(stringMapEntry.getKey());
            if (StringUtils.isBlank(tempKey)) {
                throw new UnmarshalException("Cannot create a permission detail entry with a blank key");
            } else if (map.containsKey(tempKey)) {
                throw new UnmarshalException("Cannot create more than one permission detail entry with a key of \"" + tempKey + "\"");
            }
            map.put(tempKey, normalizedStringAdapter.unmarshal(stringMapEntry.getValue()));
        }
    }
    return null;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:21,代码来源:PermissionDetailListAdapter.java

示例12: newItemAdded

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
/**
 * @see org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener#newItemAdded(java.lang.Object)
 */
public void newItemAdded(RoleXmlDTO item) {
    // Persist the role if it has not already been persisted yet.
    if (!item.isAlreadyPersisted()) {
        try {
            RoleXmlUtil.validateAndPersistNewRole(item);
        } catch (UnmarshalException e) {
            throw new RuntimeException(e);
        }
    }
    
    // If a "roleMembers" element was present, remove any existing roles that do not match the new ones.
    Set<String> existingRoleMemberIds = item.getExistingRoleMemberIds();
    if (existingRoleMemberIds != null) {
        RoleXmlUtil.removeRoleMembers(item.getRoleId(), existingRoleMemberIds);
    }
    item.setExistingRoleMemberIds(null);
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:21,代码来源:RolesXmlDTO.java

示例13: validateAndPersistNewRole

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
/**
 * Performs the necessary validation on the new role, then saves it.
 * 
 * @param newRole The role to persist.
 * @return The ID of the persisted role.
 * @throws IllegalArgumentException if newRole is null.
 * @throws UnmarshalException if newRole contains invalid data.
 */
static String validateAndPersistNewRole(RoleXmlDTO newRole) throws UnmarshalException {
    if (newRole == null) {
        throw new IllegalArgumentException("Cannot persist a null role");
    }
    
    // Validate the role and (if applicable) retrieve the ID from an existing matching role.
    validateAndPrepareRole(newRole);

    Role.Builder builder = Role.Builder.create();
    builder.setActive(newRole.getActive());
    builder.setDescription(newRole.getRoleDescription());
    builder.setId(newRole.getRoleId());
    builder.setKimTypeId(newRole.getKimTypeId());
    builder.setName(newRole.getRoleName());
    builder.setNamespaceCode(newRole.getNamespaceCode());

    //save the role
    Role role = KimApiServiceLocator.getRoleService().createRole(builder.build());

    // Set a flag on the role to indicate that it has now been persisted so that the unmarshalling process will not save this role more than once.
    newRole.setAlreadyPersisted(true);
    
    return role.getId();
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:33,代码来源:RoleXmlUtil.java

示例14: validateAndPrepareRole

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
/**
 * Validates a new role's name, namespace, KIM type, and description, and sets the role's ID if the name and namespace match an existing role.
 */
private static void validateAndPrepareRole(RoleXmlDTO newRole) throws UnmarshalException {
    // Ensure that the role name, role namespace, KIM type, and description have all been specified.
    if (StringUtils.isBlank(newRole.getRoleName()) || StringUtils.isBlank(newRole.getNamespaceCode())) {
        throw new UnmarshalException("Cannot create or override a role with a blank name or a blank namespace");
    } else if (StringUtils.isBlank(newRole.getKimTypeId())) {
        throw new UnmarshalException("Cannot create or override a role without specikfying a KIM type");
    } else if (StringUtils.isBlank(newRole.getRoleDescription())) {
        throw new UnmarshalException("Cannot create or override a role with a blank description");
    }
    
    // Attempt to find an existing matching role, and assign its ID to the validated role if it exists.
    String matchingId = KimApiServiceLocator.getRoleService().getRoleIdByNamespaceCodeAndName(
            newRole.getNamespaceCode(), newRole.getRoleName());
    if (StringUtils.isNotBlank(matchingId)) {
        newRole.setRoleId(matchingId);
    }
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:21,代码来源:RoleXmlUtil.java

示例15: validateAndPersistNewPermission

import javax.xml.bind.UnmarshalException; //导入依赖的package包/类
/**
 * Validates a new permission and then saves it.
 * 
 * @param newPermission
 * @throws IllegalArgumentException if newPermission is null.
 * @throws UnmarshalException if newPermission contains invalid data.
 */
static void validateAndPersistNewPermission(PermissionXmlDTO newPermission) throws UnmarshalException {
    if (newPermission == null) {
        throw new IllegalArgumentException("Cannot persist a null permission");
    }
    
    // Validate the new permission.
    validatePermission(newPermission);
    
    // Save the permission.
    Permission.Builder builder = Permission.Builder.create(newPermission.getNamespaceCode(), newPermission.getPermissionName());
    builder.setDescription(newPermission.getPermissionDescription());
    builder.setActive(newPermission.getActive().booleanValue());
    builder.setAttributes(newPermission.getPermissionDetails());
    
    KimApiServiceLocator.getPermissionService().createPermission(builder.build());
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:24,代码来源:PermissionXmlUtil.java


注:本文中的javax.xml.bind.UnmarshalException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。