List of usage examples for java.lang IllegalStateException getMessage
public String getMessage()
From source file:org.finra.herd.service.BusinessObjectDefinitionServiceTest.java
@Test public void testUpdateBusinessObjectDefinitionDuplicateOriginalAttributes() throws Exception { // Create and persist a business object definition entity with duplicate attributes. businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), ATTRIBUTE_VALUE_1), new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase(), ATTRIBUTE_VALUE_1_UPDATED))); // Try to update a business object definition that has duplicate attributes. try {/*from w w w. j a v a2 s . co m*/ businessObjectDefinitionService.updateBusinessObjectDefinition( new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME), new BusinessObjectDefinitionUpdateRequest(BDEF_DESCRIPTION_2, BDEF_DISPLAY_NAME_2, businessObjectDefinitionServiceTestHelper.getNewAttributes2())); fail("Should throw an IllegalStateException when business object definition contains duplicate attributes."); } catch (IllegalStateException e) { assertEquals(String.format( "Found duplicate attribute with name \"%s\" for business object definition {namespace: \"%s\", businessObjectDefinitionName: \"%s\"}.", ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), NAMESPACE, BDEF_NAME), e.getMessage()); } }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testUpdateWithDifferentContentTypes() { IllegalStateException exception = expectThrows(IllegalStateException.class, () -> { UpdateRequest updateRequest = new UpdateRequest(); updateRequest.doc(new IndexRequest().source(singletonMap("field", "doc"), XContentType.JSON)); updateRequest.upsert(new IndexRequest().source(singletonMap("field", "upsert"), XContentType.YAML)); RequestConverters.update(updateRequest); });/*from www . j av a2 s.c om*/ assertEquals( "Update request cannot have different content types for doc [JSON] and upsert [YAML] documents", exception.getMessage()); }
From source file:org.atricore.idbus.capabilities.sso.main.idp.producers.SingleSignOnProducer.java
protected AuthenticationState getAuthnState(CamelMediationExchange exchange) { CamelMediationMessage in = (CamelMediationMessage) exchange.getIn(); AuthenticationState state = null;//w w w . ja va2 s . com try { state = (AuthenticationState) in.getMessage().getState() .getLocalVariable("urn:org:atricore:idbus:samlr2:idp:authn-state"); if (logger.isTraceEnabled()) logger.trace("Using existing AuthnState " + state); } catch (IllegalStateException e) { // This binding does not support provider state ... if (logger.isDebugEnabled()) logger.debug("Provider state not supported " + e.getMessage()); if (logger.isTraceEnabled()) logger.trace(e.getMessage(), e); state = new AuthenticationState(); } if (state == null) { state = newAuthnState(exchange); } return state; }
From source file:org.de.jmg.learn.MainActivity.java
public void RemoveFragSettings() { if (fPA.fragSettings != null && mPager.getCurrentItem() != SettingsActivity.fragID) { try {//from w ww . j a v a 2 s .com libLearn.gStatus = "getSupportFragmentmanager remove fragment"; getSupportFragmentManager().beginTransaction().remove(fPA.fragSettings).commitAllowingStateLoss(); } catch (IllegalStateException ex2) { Log.e(libLearn.gStatus, ex2.getMessage(), ex2); } fPA.fragSettings = null; } }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java
/** * Implements the <tt>ChatPanel.sendMessage</tt> method. Obtains the * appropriate operation set and sends the message, contained in the write * area, through it./*w w w .j a va 2 s .c o m*/ */ protected void sendInstantMessage() { String htmlText; String plainText; // read the text and clear it as quick as possible // to avoid double sending if the user hits enter too quickly synchronized (writeMessagePanel) { if (isWriteAreaEmpty()) return; // Trims the html message, as it sometimes contains a lot of empty // lines, which causes some problems to some protocols. htmlText = getTextFromWriteArea(OperationSetBasicInstantMessaging.HTML_MIME_TYPE).trim(); plainText = getTextFromWriteArea(OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE).trim(); // clear the message earlier // to avoid as much as possible to not sending it twice (double enter) this.refreshWriteArea(); } String messageText; String mimeType; if (chatSession.getCurrentChatTransport() .isContentTypeSupported(OperationSetBasicInstantMessaging.HTML_MIME_TYPE) && (htmlText.indexOf("<b") > -1 || htmlText.indexOf("<i") > -1 || htmlText.indexOf("<u") > -1 || htmlText.indexOf("<font") > -1)) { messageText = htmlText; mimeType = OperationSetBasicInstantMessaging.HTML_MIME_TYPE; } else { messageText = plainText; mimeType = OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE; } try { if (isMessageCorrectionActive() && chatSession.getCurrentChatTransport().allowsMessageCorrections()) { chatSession.getCurrentChatTransport().correctInstantMessage(messageText, mimeType, correctedMessageUID); } else { chatSession.getCurrentChatTransport().sendInstantMessage(messageText, mimeType); } stopMessageCorrection(); } catch (IllegalStateException ex) { logger.error("Failed to send message.", ex); this.addMessage(chatSession.getCurrentChatTransport().getName(), new Date(), Chat.OUTGOING_MESSAGE, messageText, mimeType); String protocolError = ""; if (ex.getMessage() != null) protocolError = " " + GuiActivator.getResources().getI18NString("service.gui.ERROR_WAS", new String[] { ex.getMessage() }); this.addErrorMessage(chatSession.getCurrentChatTransport().getName(), GuiActivator.getResources().getI18NString("service.gui.MSG_SEND_CONNECTION_PROBLEM") + protocolError); } catch (Exception ex) { logger.error("Failed to send message.", ex); this.refreshWriteArea(); this.addMessage(chatSession.getCurrentChatTransport().getName(), new Date(), Chat.OUTGOING_MESSAGE, messageText, mimeType); String protocolError = ""; if (ex.getMessage() != null) protocolError = " " + GuiActivator.getResources().getI18NString("service.gui.ERROR_WAS", new String[] { ex.getMessage() }); this.addErrorMessage(chatSession.getCurrentChatTransport().getName(), GuiActivator.getResources() .getI18NString("service.gui.MSG_DELIVERY_ERROR", new String[] { protocolError })); } if (chatSession.getCurrentChatTransport().allowsTypingNotifications()) { // Send TYPING STOPPED event before sending the message getChatWritePanel().stopTypingTimer(); } }
From source file:org.eclipse.smarthome.binding.sonos.handler.ZonePlayerHandler.java
public void playQueue() { try {//w ww .java 2 s . c o m ZonePlayerHandler coordinator = getCoordinatorHandler(); // set the current playlist to our new queue coordinator.setCurrentURI(QUEUE_URI + coordinator.getUDN() + "#0", ""); // take the system off mute coordinator.setMute(OnOffType.OFF); // start jammin' coordinator.play(); } catch (IllegalStateException e) { logger.warn("Cannot play queue ({})", e.getMessage()); } }
From source file:org.eclipse.smarthome.binding.sonos.handler.ZonePlayerHandler.java
public void addMember(Command command) { if (command != null && command instanceof StringType) { SonosEntry entry = new SonosEntry("", "", "", "", "", "", "", GROUP_URI + getUDN()); try {/*from ww w . j a v a2s. c o m*/ getHandlerByName(command.toString()).setCurrentURI(entry); } catch (IllegalStateException e) { logger.warn("Cannot add group member ({})", e.getMessage()); } } }
From source file:org.exolab.castor.xml.StartElementProcessor.java
public void compute(String name, String namespace, AttributeSet atts) throws SAXException { UnmarshalState state = null;//from w w w . jav a2s . c o m String xmlSpace = null; // -- handle special atts if (atts != null) { // -- xml:space xmlSpace = atts.getValue(UnmarshalHandler.XML_SPACE, Namespaces.XML_NAMESPACE); if (xmlSpace == null) { xmlSpace = atts.getValue(UnmarshalHandler.XML_SPACE_WITH_PREFIX, ""); } } if (_unmarshalHandler.getStateStack().isEmpty()) { // -- Initialize since this is the first element _unmarshalHandler.processFirstElement(name, namespace, atts, xmlSpace); return; } // --rootElement // -- get MarshalDescriptor for the given element UnmarshalState parentState = _unmarshalHandler.getStateStack().getLastState(); // Test if we can accept the field in the parentState // in case the parentState fieldDesc is a container // -- This following logic tests to see if we are in a // -- container and we need to close out the container // -- before proceeding: boolean canAccept = false; while ((parentState.getFieldDescriptor() != null) && (parentState.getFieldDescriptor().isContainer() && !canAccept)) { XMLClassDescriptor tempClassDesc = parentState.getClassDescriptor(); // -- Find ClassDescriptor for Parent if (tempClassDesc == null) { tempClassDesc = (XMLClassDescriptor) parentState.getFieldDescriptor().getClassDescriptor(); if (tempClassDesc == null) tempClassDesc = _unmarshalHandler.getClassDescriptor(parentState.getObject().getClass()); } canAccept = tempClassDesc.canAccept(name, namespace, parentState.getObject()); if (!canAccept) { // -- Does container class even handle this field? if (tempClassDesc.getFieldDescriptor(name, namespace, NodeType.Element) != null) { if (!parentState.getFieldDescriptor().isMultivalued()) { String error = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.container.full"), new Object[] { tempClassDesc.getJavaClass().getName(), name }); ValidationException vx = new ValidationException(error); throw new SAXException(vx); } } _unmarshalHandler.endElement(parentState.getElementName()); parentState = _unmarshalHandler.getStateStack().getLastState(); } tempClassDesc = null; } // -- create new state object state = new UnmarshalState(); state.setElementName(name); state.setParent(parentState); if (xmlSpace != null) { state.setWhitespacePreserving(UnmarshalHandler.PRESERVE.equals(xmlSpace)); } else { state.setWhitespacePreserving(parentState.isWhitespacePreserving()); } _unmarshalHandler.getStateStack().pushState(state); // -- make sure we should proceed if (parentState.getObject() == null) { if (!parentState.isWrapper()) { return; } } Class cls = null; // -- Find ClassDescriptor for Parent XMLClassDescriptor classDesc = parentState.getClassDescriptor(); if (classDesc == null) { classDesc = (XMLClassDescriptor) parentState.getFieldDescriptor().getClassDescriptor(); if (classDesc == null) classDesc = _unmarshalHandler.getClassDescriptor(parentState.getObject().getClass()); } else { // classDesc.resetElementCount(); } // ----------------------------------------------------/ // - Find FieldDescriptor associated with the element -/ // ----------------------------------------------------/ // -- A reference to the FieldDescriptor associated // -- the the "current" element XMLFieldDescriptor descriptor = null; // -- inherited class descriptor // -- (only needed if descriptor cannot be found directly) XMLClassDescriptor cdInherited = null; // -- loop through stack and find correct descriptor // int pIdx = _stateInfo.size() - 2; //-- index of parentState UnmarshalState targetState = parentState; String path = ""; int count = 0; boolean isWrapper = false; XMLClassDescriptor oldClassDesc = classDesc; while (descriptor == null) { // -- NOTE (kv 20050228): // -- we need to clean this code up, I made this // -- fix to make sure the correct descriptor which // -- matches the location path is used if (path.length() > 0) { String tmpName = path + "/" + name; descriptor = classDesc.getFieldDescriptor(tmpName, namespace, NodeType.Element); } // -- End Patch if (descriptor == null) { descriptor = classDesc.getFieldDescriptor(name, namespace, NodeType.Element); } // -- Namespace patch, should be moved to XMLClassDescriptor, but // -- this is the least intrusive patch at the moment. kv - 20030423 if ((descriptor != null) && (!descriptor.isContainer())) { if (StringUtils.isNotEmpty(namespace)) { if (!MarshalFramework.namespaceEquals(namespace, descriptor.getNameSpaceURI())) { // -- if descriptor namespace is not null, then we must // -- have a namespace match, so set descriptor to null, // -- or if descriptor is not a wildcard we can also // -- set to null. if ((descriptor.getNameSpaceURI() != null) || (!descriptor.matches("*"))) { descriptor = null; } } } } // -- end namespace patch /* * If descriptor is null, we need to handle possible inheritence, which might not be described * in the current ClassDescriptor. This can be a slow process...for speed use the match * attribute of the xml element in the mapping file. This logic might not be completely * necessary, and perhaps we should remove it. */ // handle multiple level locations (where count > 0) (CASTOR-1039) // if ((descriptor == null) && (count == 0) && // (!targetState.wrapper)) { if ((descriptor == null) && (!targetState.isWrapper())) { MarshalFramework.InheritanceMatch[] matches = null; try { matches = _unmarshalHandler.searchInheritance(name, namespace, classDesc); // TODO: // Joachim, // _cdResolver); } catch (MarshalException rx) { // -- TODO: } if (matches.length != 0) { InheritanceMatch match = null; // It may be the case that this class descriptor can // appear under multiple parent field descriptors. Look // for the first match whose parent file descriptor XML // name matches the name of the element we are under for (int i = 0; i < matches.length; i++) { if (parentState.getElementName().equals(matches[i].parentFieldDesc.getLocationPath())) { match = matches[i]; break; } } if (match == null) match = matches[0]; descriptor = match.parentFieldDesc; cdInherited = match.inheritedClassDesc; break; // -- found } /* */ // handle multiple level locations (where count > 0) // (CASTOR-1039) // isWrapper = (isWrapper || hasFieldsAtLocation(name, // classDesc)); StringBuilder tmpLocation = new StringBuilder(); if (count > 0) { tmpLocation.append(path).append('/'); } tmpLocation.append(name); isWrapper = (isWrapper || MarshalFramework.hasFieldsAtLocation(tmpLocation.toString(), classDesc)); } else if (descriptor != null) { String tmpPath = descriptor.getLocationPath(); if (path.equals(StringUtils.defaultString(tmpPath))) break; // -- found descriptor = null; // -- not found, try again } else { isWrapper = (isWrapper || MarshalFramework.hasFieldsAtLocation(path + '/' + name, classDesc)); } // -- Make sure there are more parent classes on stack // -- otherwise break, since there is nothing to do // if (pIdx == 0) break; if (targetState == _unmarshalHandler.getTopState()) break; // -- adjust name and try parent if (count == 0) path = targetState.getElementName(); else { path = targetState.getElementName() + '/' + path; } // -- get // --pIdx; // targetState = (UnmarshalState)_stateInfo.elementAt(pIdx); targetState = targetState.getParent(); classDesc = targetState.getClassDescriptor(); count++; } if (descriptor != null && _unmarshalHandler.isValidating() && !_unmarshalHandler.getInternalContext().getLenientSequenceOrder()) { try { classDesc.checkDescriptorForCorrectOrderWithinSequence(descriptor, parentState, name); } catch (ValidationException e) { throw new SAXException(e); } } // -- The field descriptor is still null, we face a problem if (descriptor == null) { // -- reset classDesc classDesc = oldClassDesc; // -- isWrapper? if (isWrapper) { state.setClassDescriptor(new XMLClassDescriptorImpl(ContainerElement.class, name)); state.setWrapper(true); if (LOG.isDebugEnabled()) { LOG.debug("wrapper-element: " + name); } // -- process attributes _unmarshalHandler.processWrapperAttributes(atts); return; } String error = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.find.field.descriptor"), new Object[] { name, classDesc.getXMLName() }); // -- unwrap classDesc, if necessary, for the check // -- Introspector.introspected done below if (classDesc instanceof InternalXMLClassDescriptor) { classDesc = ((InternalXMLClassDescriptor) classDesc).getClassDescriptor(); } // -- If we are skipping elements that have appeared in the XML but // for // -- which we have no mapping, increase the ignore depth counter // and return boolean lenientElementStrictnessForIntrospection = _unmarshalHandler.getInternalContext() .getBooleanProperty(XMLProperties.LENIENT_INTROSPECTED_ELEMENT_STRICTNESS).booleanValue(); // checks if the element could be skipped if (_unmarshalHandler.getStrictElementHandler().skipStartElementIgnoringDepth()) { // -- remove the StateInfo we just added _unmarshalHandler.getStateStack().removeLastState(); // drop Namespace instance as well _unmarshalHandler.getNamespaceHandling().removeCurrentNamespaceInstance(); if (LOG.isDebugEnabled()) { String debug = MessageFormat.format( resourceBundle.getString("unmarshalHandler.log.debug.ignore.extra.element"), new Object[] { error }); LOG.debug(debug); } return; } // if we have no field descriptor and // the class descriptor was introspected // just log it else if (lenientElementStrictnessForIntrospection && Introspector.introspected(classDesc)) { LOG.warn(error); return; } // -- otherwise report error since we cannot find a suitable // -- descriptor else { throw new SAXException(error); } } // -- end null descriptor // / DEBUG: System.out.println("path: " + path); // -- Save targetState (used in endElement) if (targetState != parentState) { state.setTargetState(targetState); parentState = targetState; // -- reassign } Object object = parentState.getObject(); // --container support if (descriptor.isContainer()) { // create a new state to set the container as the object // don't save the current state, it will be recreated later if (LOG.isDebugEnabled()) { LOG.debug("#container: " + descriptor.getFieldName()); } // -- clear current state and re-use for the container state.clear(); // -- inherit whitespace preserving from the parentState state.setWhitespacePreserving(parentState.isWhitespacePreserving()); state.setParent(parentState); // here we can hard-code a name or take the field name state.setElementName(descriptor.getFieldName()); state.setFieldDescriptor(descriptor); state.setClassDescriptor((XMLClassDescriptor) descriptor.getClassDescriptor()); Object containerObject = null; // 1-- the container is not multivalued (not a collection) if (!descriptor.isMultivalued()) { // Check if the container object has already been instantiated FieldHandler handler = descriptor.getHandler(); containerObject = handler.getValue(object); if (containerObject != null) { if (state.getClassDescriptor() != null) { if (state.getClassDescriptor().canAccept(name, namespace, containerObject)) { // remove the descriptor from the used list parentState.markAsNotUsed(descriptor); } } else { // remove the descriptor from the used list parentState.markAsNotUsed(descriptor); } } else { containerObject = handler.newInstance(object); } } // 2-- the container is multivalued else { Class containerClass = descriptor.getFieldType(); try { containerObject = containerClass.newInstance(); } catch (Exception ex) { throw new SAXException(ex); } } state.setObject(containerObject); state.setType(containerObject.getClass()); // we need to recall startElement() // so that we can find a more appropriate descriptor in for the // given name _unmarshalHandler.getNamespaceHandling().createNamespace(); _unmarshalHandler.startElementProcessing(name, namespace, atts); return; } // --End of the container support // -- Find object type and create new Object of that type state.setFieldDescriptor(descriptor); /* * <update> we need to add this code back in, to make sure we have proper access rights. * * if (!descriptor.getAccessRights().isWritable()) { if (debug) { buf.setLength(0); buf.append( * "The field for element '"); buf.append(name); buf.append("' is read-only."); * message(buf.toString()); } return; } */ // -- Find class to instantiate // -- check xml names to see if we should look for a more specific // -- ClassDescriptor, otherwise just use the one found in the // -- descriptor classDesc = null; if (cdInherited != null) classDesc = cdInherited; else if (!name.equals(descriptor.getXMLName())) classDesc = _unmarshalHandler.resolveByXMLName(name, namespace, null); if (classDesc == null) classDesc = (XMLClassDescriptor) descriptor.getClassDescriptor(); FieldHandler handler = descriptor.getHandler(); boolean useHandler = true; try { // -- Get Class type...first use ClassDescriptor, // -- since it could be more specific than // -- the FieldDescriptor if (classDesc != null) { cls = classDesc.getJavaClass(); // -- XXXX This is a hack I know...but we // -- XXXX can't use the handler if the field // -- XXXX types are different if (descriptor.getFieldType() != cls) { state.setDerived(true); } } else { cls = descriptor.getFieldType(); } // -- This *shouldn't* happen, but a custom implementation // -- could return null in the XMLClassDesctiptor#getJavaClass // -- or XMLFieldDescriptor#getFieldType. If so, just replace // -- with java.lang.Object.class (basically "anyType"). if (cls == null) { cls = java.lang.Object.class; } // Retrieving the xsi:type attribute, if present String currentPackage = _unmarshalHandler.getJavaPackage(parentState.getType()); String instanceType = _unmarshalHandler.getInstanceType(atts, currentPackage); if (instanceType != null) { Class instanceClass = null; try { XMLClassDescriptor instanceDesc = _unmarshalHandler.getClassDescriptor(instanceType, _unmarshalHandler.getClassLoader()); boolean loadClass = true; if (instanceDesc != null) { instanceClass = instanceDesc.getJavaClass(); classDesc = instanceDesc; if (instanceClass != null) { loadClass = (!instanceClass.getName().equals(instanceType)); } } if (loadClass) { instanceClass = _unmarshalHandler.loadClass(instanceType, null); // the FieldHandler can be either an XMLFieldHandler // or a FieldHandlerImpl FieldHandler tempHandler = descriptor.getHandler(); boolean collection = false; if (tempHandler instanceof FieldHandlerImpl) { collection = ((FieldHandlerImpl) tempHandler).isCollection(); } else { collection = Introspector.isCollection(instanceClass); } if ((!collection) && !cls.isAssignableFrom(instanceClass)) { if (!MarshalFramework.isPrimitive(cls)) { String err = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.not.subclass"), new Object[] { instanceClass.getName(), cls.getName() }); throw new SAXException(err); } } } cls = instanceClass; useHandler = false; } catch (Exception ex) { String err = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.unable.instantiate.exception"), new Object[] { instanceType, ex.getMessage() }); throw new SAXException(err, ex); } } // -- Handle ArrayHandler if (cls == Object.class) { if (parentState.getObject() instanceof ArrayHandler) cls = ((ArrayHandler) parentState.getObject()).componentType(); } // -- Handle support for "Any" type if (cls == Object.class) { Class pClass = parentState.getType(); ClassLoader loader = pClass.getClassLoader(); // -- first look for a descriptor based // -- on the XML name classDesc = _unmarshalHandler.resolveByXMLName(name, namespace, loader); // -- if null, create classname, and try resolving String cname = null; if (classDesc == null) { // -- create class name cname = _unmarshalHandler.getJavaNaming().toJavaClassName(name); classDesc = _unmarshalHandler.getClassDescriptor(cname, loader); } // -- if still null, try using parents package if (classDesc == null) { // -- use parent to get package information String pkg = pClass.getName(); int idx = pkg.lastIndexOf('.'); if (idx > 0) { pkg = pkg.substring(0, idx + 1); cname = pkg + cname; classDesc = _unmarshalHandler.getClassDescriptor(cname, loader); } } if (classDesc != null) { cls = classDesc.getJavaClass(); useHandler = false; } else { // we are dealing with an AnyNode state.setObject(_unmarshalHandler.getAnyNodeHandler().commonStartElement(name, namespace, state.isWhitespacePreserving())); state.setType(cls); return; } } boolean byteArray = false; if (cls.isArray()) byteArray = (cls.getComponentType() == Byte.TYPE); // -- check for immutable if (MarshalFramework.isPrimitive(cls) || descriptor.isImmutable() || byteArray) { state.setObject(null); state.setPrimitiveOrImmutable(true); // -- handle immutable types, such as java.util.Locale if (descriptor.isImmutable()) { if (classDesc == null) classDesc = _unmarshalHandler.getClassDescriptor(cls); state.setClassDescriptor(classDesc); Arguments args = _unmarshalHandler.processConstructorArgs(atts, classDesc); if (args != null && args.size() > 0) { state.setConstructorArguments(args); } } } else { if (classDesc == null) classDesc = _unmarshalHandler.getClassDescriptor(cls); // -- XXXX should remove this test once we can // -- XXXX come up with a better solution if ((!state.isDerived()) && useHandler) { boolean create = true; if (_unmarshalHandler.isReuseObjects()) { state.setObject(handler.getValue(parentState.getObject())); create = (state.getObject() == null); } if (create) { Arguments args = _unmarshalHandler.processConstructorArgs(atts, classDesc); if ((args.getValues() != null) && (args.getValues().length > 0)) { if (handler instanceof ExtendedFieldHandler) { ExtendedFieldHandler efh = (ExtendedFieldHandler) handler; state.setObject(efh.newInstance(parentState.getObject(), args.getValues())); } else { String err = resourceBundle .getString("unmarshalHandler.error.constructor.arguments"); throw new SAXException(err); } } else { state.setObject(handler.newInstance(parentState.getObject())); } } } // -- reassign class in case there is a conflict // -- between descriptor#getFieldType and // -- handler#newInstance...I should hope not, but // -- who knows if (state.getObject() != null) { cls = state.getObject().getClass(); if (classDesc != null) { if (classDesc.getJavaClass() != cls) { classDesc = null; } } } else { try { if (cls.isArray()) { state.setObject(new ArrayHandler(cls.getComponentType())); cls = ArrayHandler.class; } else { Arguments args = _unmarshalHandler.processConstructorArgs(atts, classDesc); state.setObject(_unmarshalHandler.createInstance(cls, args)); // state.object = _class.newInstance(); } } catch (java.lang.Exception ex) { String err = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.unable.instantiate.exception"), new Object[] { _unmarshalHandler.className(cls), ex.getMessage() }); throw new SAXException(err, ex); } } } state.setType(cls); } catch (java.lang.IllegalStateException ise) { LOG.error(ise.toString()); throw new SAXException(ise); } // -- At this point we should have a new object, unless // -- we are dealing with a primitive type, or a special // -- case such as byte[] if (classDesc == null) { classDesc = _unmarshalHandler.getClassDescriptor(cls); } state.setClassDescriptor(classDesc); if ((state.getObject() == null) && (!state.isPrimitiveOrImmutable())) { String err = MessageFormat.format(resourceBundle.getString("unmarshalHandler.error.unable.unmarshal"), new Object[] { name, _unmarshalHandler.className(cls) }); throw new SAXException(err); } // -- assign object, if incremental if (descriptor.isIncremental()) { if (LOG.isDebugEnabled()) { String debug = MessageFormat.format( resourceBundle.getString("unmarshalHandler.log.debug.process.incrementally"), new Object[] { name }); LOG.debug(debug); } try { handler.setValue(parentState.getObject(), state.getObject()); } catch (java.lang.IllegalStateException ise) { String err = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.unable.add.element"), new Object[] { name, parentState.getFieldDescriptor().getXMLName(), ise.getMessage() }); throw new SAXException(err, ise); } } if (state.getObject() != null) { // --The object has just been initialized // --notify the listener Object stateObject = state.getObject(); Object parentObject = (state.getParent() == null) ? null : state.getParent().getObject(); _unmarshalHandler.getDelegateUnmarshalListener().initialized(stateObject, parentObject); _unmarshalHandler.processAttributes(atts, classDesc); _unmarshalHandler.getDelegateUnmarshalListener().attributesProcessed(stateObject, parentObject); _unmarshalHandler.getNamespaceHandling().processNamespaces(classDesc, _unmarshalHandler.getStateStack().getLastState().getObject()); } else if ((state.getType() != null) && (!state.isPrimitiveOrImmutable())) { if (atts != null) { _unmarshalHandler.processWrapperAttributes(atts); String warn = MessageFormat.format( resourceBundle.getString("unmarshalHandler.log.warn.process.attribute.as.location"), new Object[] { name }); LOG.warn(warn); } } else { // -- check for special attributes, such as xsi:nil if (atts != null) { String nil = atts.getValue(MarshalFramework.NIL_ATTR, MarshalFramework.XSI_NAMESPACE); state.setNil("true".equals(nil)); _unmarshalHandler.processWrapperAttributes(atts); } } }
From source file:org.eclipse.smarthome.binding.sonos.handler.ZonePlayerHandler.java
/** * Set the VOLUME command specific to the current grouping according to the Sonos behaviour. * AdHoc groups handles the volume specifically for each player. * Bonded groups delegate the volume to the coordinator which applies the same level to all group members. *///from w w w . j ava 2 s. c o m public void setVolumeForGroup(Command command) { if (isAdHocGroup() || isStandalonePlayer()) { setVolume(command); } else { try { getCoordinatorHandler().setVolume(command); } catch (IllegalStateException e) { logger.warn("Cannot set group volume ({})", e.getMessage()); } } }
From source file:org.eclipse.smarthome.binding.sonos.handler.ZonePlayerHandler.java
private void updateGroupCoordinator() { try {/*w w w .j ava 2 s . c o m*/ coordinatorHandler = getHandlerByName(getCoordinator()); } catch (IllegalStateException e) { logger.warn("Cannot update the group coordinator ({})", e.getMessage()); coordinatorHandler = null; } }