當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。