jaxb null values while unmarshalling - java

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xml>
<Settings version="3" xmlns="urn:Adapter-v3">
<Connections>
<Connection name ="A" description="DEV">
<SaveVersion version="M" siteURL="https://example.com" />
<Save>
<Id>id123</Id>
<Client>hello</Client>
</Save>
</Connection>
<Connection name ="B" description="DEV1">
<SaveVersion version="M" siteURL="https://example.com" />
<Auth>
<UserId>id123</UserId>
<Password>pass</Password>
</Auth>
</Connection>
</Connections>
<Mappings>
<Mapping cont="AA" auction="A1">
<Description>Desc</Description>
<Content
attr1="IO"
attr2="d"
attr3="Information"
attr4="false"
<Element enabled="false" count="200" prefix="DocLib_" itemPrefix="0" />
<Sub enabled="false" count="100" prefix="Folder_" itemPrefix="0" />
<FilenameA auction="N" delay="3" />
</Content>
</Mapping>
<Mapping cont="AB" auction="SharePointOLDev1">
<Description>Desc</Description>
<Content
attr1="IO"
attr2="d"
attr3="Information"
attr4="false"
<Element enabled="false" count="200" prefix="DocLib_" itemPrefix="0" />
<Sub enabled="false" count="100" prefix="1" itemPrefix="0" />
</Content>
</Mapping>
</Mappings>
<TypeMappings>
<TypeMapping Type="rfid" ext="msg" />
</TypeMappings>
</Settings>
Trying to unmarshal the above xml file to java objects.
Generated Settings.java and ObjectFactory.java file using xjc tool.These files are deployed in the src folder(along with other java files.)
WHen i unmarshal i get null valuues for Connections,Mappings and TypeMappings.
Is there any steps that i am missing?
public class JAXBImpl{
public static void main(String args[]){
JAXBContext jaxbContext;
Settings que= null;
jaxbContext = JAXBContext.newInstance(Settings.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
que= (Settings) jaxbUnmarshaller.unmarshal(file);
System.out.println(que.getConnections().getConnection());
}
}

Related

jBPM compilation error

Process Compilation error : org.drools.lang.descr.ProcessDescr#4c60d6e9
com/sample/Process_com_sample_ruleflowsample.java (21:862) : Type mismatch: cannot convert from int to String
com/sample/Process_com_sample_ruleflowsample.java (29:1151) : Type mismatch: cannot convert from int to String
This is my ruleflowsample.rf under src/main/rules that is throwing the above error.
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
type="RuleFlow" name="ruleflowsample" id="com.sample.ruleflowsample" package-name="com.sample" >
<header>
<imports>
<import name="com.sample.Employee" />
</imports>
<variables>
<variable name="caffeineIntake" >
<type name="org.drools.process.core.datatype.impl.type.FloatDataType" />
</variable>
</variables>
</header>
<nodes>
<start id="1" name="Start" x="12" y="129" width="48" height="48" />
<split id="2" name="Gateway" x="101" y="128" width="49" height="49" type="2" >
<constraints>
<constraint toNodeId="4" toType="DROOLS_DEFAULT" name="Coffee" priority="1" type="code" dialect="java" >return caffeineIntake>0.105F;</constraint>
<constraint toNodeId="5" toType="DROOLS_DEFAULT" name="Tea" priority="1" type="code" dialect="java" >return caffeineIntake>0.04F;</constraint>
</constraints>
</split>
<actionNode id="4" name="Coffee" x="198" y="205" width="80" height="48" >
<action type="expression" dialect="java" >String noOfCups = 1;
System.out.println("No of coffee cups = "+noOfCups);
System.out.println("caffeineIntake");</action>
</actionNode>
<actionNode id="5" name="Tea" x="196" y="61" width="80" height="48" >
<action type="expression" dialect="java" >String noOfCups = 1;
System.out.println("No of tea cups = "+noOfCups);
System.out.println("caffeineIntake");</action>
</actionNode>
<end id="6" name="End" x="386" y="127" width="48" height="48" />
<join id="7" name="Gateway" x="311" y="127" width="49" height="49" type="2" />
</nodes>
<connections>
<connection from="1" to="2" />
<connection from="2" to="4" />
<connection from="2" to="5" />
<connection from="7" to="6" />
<connection from="5" to="7" />
<connection from="4" to="7" />
</connections>
</process>
I know the error is occurring because of this line: System.out.println("caffeineIntake");
I want to access this input variable i.e. caffeineIntake to perform some operation on it.
The error is not occurring because of this line: System.out.println("caffeineIntake");
It is occurring because of the Dialect option selection:
Using this option as mvel rather than java resolved the issue.
Well,
from my point of view
String noOfCups = 1;
is the problem.
perhaps change it to
String noOfCups = "1";

Add new tag in XML file with different attributes

I'm trying to add a new line of tag "" with different attributes. I'm able to edit an existing line but not able to add new tag having different attributes.
The XML file
<elementDefinitionPackage elementDefinitionPackageName="kohler-decisionmaker" elementDefinitionPackageVersion="3.2.0.42" elementLibraryFilename="libkohler-decisionmaker.so" elementLibraryVersion="3.2.0.42" minSupportedGDDVersion="1.0" minSupportedUMGFirmwareVersion="1.1.0.0" xmlns="http://xmlns.commonplatform.avocent.com/mss/ddt/template" xmlns:cm="http://xmlns.commonplatform.avocent.com/mss/ddt/common" xmlns:r="http://xmlns.commonplatform.avocent.com/mss/ddt/rules" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.commonplatform.avocent.com/mss/ddt/template XSD_ddt.xsd http://xmlns.commonplatform.avocent.com/mss/ddt/rules XSD_rules.xsd http://xmlns.commonplatform.avocent.com/mss/ddt/common XSD_common.xsd">
<elementDefinitionModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="DEC4000" modelQualifierInSymbol="DEC4000" symbolTag="KOHLERDEC4000DEC4000">
<supportedprotocols>
<supportedProtocol isSubscribable="false" protocolName="MODBUS/RS-485">
<properties>
<property category="EXTCOMM" defaultValue="502" definition="PORT" valueType="Integer" />
<property category="EXTCOMM" defaultValue="60" definition="TIMEOUT" valueType="Integer" />
<property category="EXTCOMM" defaultValue="1" definition="SLAVEID" valueType="Integer"/>
</properties>
<datapoints>
<datapoint division="COLL_COMP_CEP" nature="PARAMETRIC" programmaticName="t_val_calc_enrg_interval"/>
</datapoints>
<events>
<event address="3.{SLAVEID}.40259.1" programmaticName="t_evt_gen_mainTankAlarm" values="a:1 i:0" />
</events>
<commands>
<command access="RW" address="#RWDA 3.{SLAVEID}.61105 6.{SLAVEID}.61105" division="CONTROL" nature="ENUM" programmaticName="t_st_gen_setControl" valueTypeInDevice="DATA_POINT_VALUE_TYPE_INTEGER" />
</commands>
</supportedProtocol>
</supportedprotocols>
<rules>
</rules>
<similarModels>
<similarModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="KD440" modelQualifierInSymbol="KD440" symbolTag="KOHLERKD440KD440"/>
</similarModels>
</elementDefinitionModel>
Expected Output XML file
<elementDefinitionPackage elementDefinitionPackageName="kohler-decisionmaker" elementDefinitionPackageVersion="3.2.0.42" elementLibraryFilename="libkohler-decisionmaker.so" elementLibraryVersion="3.2.0.42" minSupportedGDDVersion="1.0" minSupportedUMGFirmwareVersion="1.1.0.0" xmlns="http://xmlns.commonplatform.avocent.com/mss/ddt/template" xmlns:cm="http://xmlns.commonplatform.avocent.com/mss/ddt/common" xmlns:r="http://xmlns.commonplatform.avocent.com/mss/ddt/rules" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.commonplatform.avocent.com/mss/ddt/template XSD_ddt.xsd http://xmlns.commonplatform.avocent.com/mss/ddt/rules XSD_rules.xsd http://xmlns.commonplatform.avocent.com/mss/ddt/common XSD_common.xsd">
<elementDefinitionModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="DEC4000" modelQualifierInSymbol="DEC4000" symbolTag="KOHLERDEC4000DEC4000">
<supportedprotocols>
<supportedProtocol isSubscribable="false" protocolName="MODBUS/RS-485">
<properties>
<property category="EXTCOMM" defaultValue="502" definition="PORT" valueType="Integer" />
<property category="EXTCOMM" defaultValue="60" definition="TIMEOUT" valueType="Integer" />
<property category="EXTCOMM" defaultValue="1" definition="SLAVEID" valueType="Integer"/>
</properties>
<datapoints>
<datapoint division="COLL_COMP_CEP" nature="PARAMETRIC" programmaticName="t_val_calc_enrg_interval"/>
</datapoints>
<events>
<event address="3.{SLAVEID}.40259.1" programmaticName="t_evt_gen_mainTankAlarm" values="a:1 i:0" />
</events>
<commands>
<command access="RW" address="#RWDA 3.{SLAVEID}.61105 6.{SLAVEID}.61105" division="CONTROL" nature="ENUM" programmaticName="t_st_gen_setControl" valueTypeInDevice="DATA_POINT_VALUE_TYPE_INTEGER" />
</commands>
</supportedProtocol>
</supportedprotocols>
<rules>
</rules>
<similarModels>
<similarModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="KD440" modelQualifierInSymbol="KD440" symbolTag="KOHLERKD440KD440"/>
<similarModel manufacturerInSymbol="KOHLER" minSupportedVersionInSymbol="1.4" modelInSymbol="A" modelQualifierInSymbol="B" symbolTag="C"/>
</similarModels>
</elementDefinitionModel>
Java Code
private static void updat() {
NodeList similarmodels = doc.getElementsByTagName("similarModels");
Element model = null;
for(int i=0; i<similarmodels.getLength();i++){
model = (Element) similarmodels.item(i);
String model = model.getElementsByTagName("similarModel").item(0).getFirstChild().getNodeValue();
if(model.equalsIgnoreCase("KD440")){
model.setAttribute("A");
}else{
model.setAttribute("B");
}
}
}
Is there a way of doing this in JAXB & xsd??
Should be no problem, neither with DOM nor with JAXB. In JAXB you should simply be able to create a new SimilarModel object which you then can add in the SimilarModels object's list.

How to get the annotated text for a DictionaryAnnotator

I have a dictionary created from the DictionaryCreator from UIMA, I would like to annotate a piece of text using the DictionaryAnnotator and the aforementioned dictionary, I could not figure out how to get the annotated text. Please let me know if you do. Any help is appreciated. The code, the dictionary-file and the descriptor is mentioned below,
P.S. I'm new to Apache UIMA.
XMLInputSource xml_in = new XMLInputSource("DictionaryAnnotatorDescriptor.xml");
ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xml_in);
AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
JCas jCas = ae.newJCas();
String inputText = "Mark and John went down the rabbit hole to meet a wise owl and have curry with the owl.";
jCas.setDocumentText(inputText);
printResults(jCas);
public static void printResults(JCas jcas) {
FSIndex<Annotation> index = jcas.getAnnotationIndex();
for (Iterator<Annotation> it = index.iterator(); it.hasNext(); ) {
Annotation annotation = it.next();
List<Feature> features;
features = annotation.getType().getFeatures();
List<String> fasl = new ArrayList<String>();
for (Feature feature : features) {
try {
String name = feature.getShortName();
System.out.println(feature.getName());
String value = annotation.getStringValue(feature);
fasl.add(name + "=\"" + value + "\"");
System.out.println(value);
}catch (Exception e){
continue;
}
}
}
}
my_dictionary.xml
<?xml version="1.0" encoding="UTF-8"?>
<dictionary xmlns="http://incubator.apache.org/uima" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="dictionary.xsd">
<typeCollection>
<dictionaryMetaData caseNormalization="true" multiWordEntries="true" multiWordSeparator=" "/>
<languageId>en</languageId>
<typeDescription>
<typeName>org.apache.uima.DictionaryEntry</typeName>
</typeDescription>
<entries>
<entry>
<key>Mark</key>
</entry>
<entry>
<key>John</key>
</entry>
<entry>
<key>Rabbit</key>
</entry>
<entry>
<key>Owl</key>
</entry>
<entry>
<key>Curry</key>
</entry>
<entry>
<key>ATH-MX50</key>
</entry>
<entry>
<key>CC234</key>
</entry>
</entries>
</typeCollection>
</dictionary>
DictionaryAnnotatorDescriptor.xml
<?xml version="1.0" encoding="UTF-8"?>
<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier">
<frameworkImplementation>org.apache.uima.java</frameworkImplementation>
<primitive>true</primitive>
<annotatorImplementationName>org.apache.uima.annotator.dict_annot.impl.DictionaryAnnotator</annotatorImplementationName>
<analysisEngineMetaData>
<name>GeneDictionaryAnnotator</name>
<description></description>
<version>0.1</version>
<vendor></vendor>
<configurationParameters>
<configurationParameter>
<name>DictionaryFiles</name>
<description>list of dictionary files to configure the annotator</description>
<type>String</type>
<multiValued>true</multiValued>
<mandatory>true</mandatory>
</configurationParameter>
<configurationParameter>
<name>InputMatchType</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>true</mandatory>
</configurationParameter>
<configurationParameter>
<name>InputMatchFeaturePath</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>false</mandatory>
</configurationParameter>
<configurationParameter>
<name>InputMatchFilterFeaturePath</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>false</mandatory>
</configurationParameter>
<configurationParameter>
<name>FilterConditionOperator</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>false</mandatory>
</configurationParameter>
<configurationParameter>
<name>FilterConditionValue</name>
<description></description>
<type>String</type>
<multiValued>false</multiValued>
<mandatory>false</mandatory>
</configurationParameter>
</configurationParameters>
<configurationParameterSettings>
<nameValuePair>
<name>DictionaryFiles</name>
<value>
<array>
<string>src/main/resources/my_dictionary.xml</string>
</array>
</value>
</nameValuePair>
<nameValuePair>
<name>InputMatchType</name>
<value>
<string>org.apache.uima.TokenAnnotation</string>
</value>
</nameValuePair>
</configurationParameterSettings>
<typeSystemDescription>
<types>
<typeDescription>
<name>org.apache.uima.DictionaryEntry</name>
<description></description>
<supertypeName>uima.tcas.Annotation</supertypeName>
</typeDescription>
<typeDescription>
<name>org.apache.uima.TokenAnnotation</name>
<description>Single token annotation</description>
<supertypeName>uima.tcas.Annotation</supertypeName>
<features>
<featureDescription>
<name>tokenType</name>
<description>token type</description>
<rangeTypeName>uima.cas.String</rangeTypeName>
</featureDescription>
</features>
</typeDescription>
<typeDescription>
<name>example.Name</name>
<description>A proper name.</description>
<supertypeName>uima.tcas.Annotation</supertypeName>
</typeDescription>
</types>
</typeSystemDescription>
<capabilities>
<capability>
<inputs/>
<outputs>
<type>example.Name</type>
</outputs>
<languagesSupported/>
</capability>
</capabilities>
<operationalProperties>
<modifiesCas>true</modifiesCas>
<multipleDeploymentAllowed>true</multipleDeploymentAllowed>
<outputsNewCASes>false</outputsNewCASes>
</operationalProperties>
</analysisEngineMetaData>
</analysisEngineDescription>
Alternatively, you could also use Apache Ruta, either with the workbench (recommended to get started) or with java code.
For the latter, I created an example project at https://github.com/renaud/annotate_ruta_example. The main parts are:
a list of names in src/main/resources/ruta/resources/names.txt (a plain text file)
Mark
John
Rabbit
Owl
Curry
ATH-MX50
CC234
a Ruta script in src/main/resources/ruta/scripts/Example.ruta
PACKAGE example.annotate; // optional package def
WORDLIST MyNames = 'names.txt'; // declare dictionary location
DECLARE Name; // declare an annotation
Document{-> MARKFAST(Name, MyNames)}; // annotate document
and some java boilerplate code to launch the annotator:
JCas jCas = JCasFactory.createJCas();
// the sample text to annotate
jCas.setDocumentText("Mark wants to buy CC234.");
// configure the engine with scripts and resources
AnalysisEngine rutaEngine = AnalysisEngineFactory.createEngine(
RutaEngine.class, //
RutaEngine.PARAM_RESOURCE_PATHS,
"src/main/resources/ruta/resources",//
RutaEngine.PARAM_SCRIPT_PATHS,
"src/main/resources/ruta/scripts",
RutaEngine.PARAM_MAIN_SCRIPT, "Example");
// run the script. instead of a jCas, you could also provide a UIMA collection reader to process many documents
SimplePipeline.runPipeline(jCas, rutaEngine);
// a simple select to print the matched Names
for (Name name : JCasUtil.select(jCas, Name.class)) {
System.out.println(name.getCoveredText());
}
there is also some UIMA type (annotation) definitions, check src/main/resources/desc/type/ExampleTypes.xml, src/main/resources/META-INF/org.apache.uima.fit/types.txt and src/main/java/example/annotate.
how to test it
git clone https://github.com/renaud/annotate_ruta_example.git
cd annotate_ruta_example
mvn clean install
mvn exec:java -Dexec.mainClass="example.Annotate"

Delete line from xml based on condition

I have an xml as shown below.
<?xml version="1.0" encoding="utf-8"?>
<package date-created="11/4/2014" client-version="blah" system-version="blah">
<description />
<system>
<language />
</system>
<res id="blah" name="name" path="path" type="F" mimeType="mimetype-blah">
<description />
<keywords />
<resver id="1690047800" major="50" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690167421" major="68" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690176842" major="71" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
</res>
<res id="blah1" name="name1" path="path1" type="F" mimeType="mimetype-blah1">
<description />
<keywords />
<resver id="1690145841" major="34" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690161885" major="64" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690165275" major="66" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690169108" major="69" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
<resver id="1690175442" major="87" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
</res>
</package>
I want to delete all <resver> elements except for the one with highest "major" attribute value.
For example above major="71" is highest in the first resver group and major="87" is the highest in second resver group.
So overall output looks like this:
<?xml version="1.0" encoding="utf-8"?>
<package date-created="11/4/2014" client-version="blah" system-version="blah">
<description />
<system>
<language />
</system>
<res id="blah" name="name" path="path" type="F" mimeType="mimetype-blah">
<description />
<keywords />
<resver id="1690176842" major="71" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
</res>
<res id="blah1" name="name1" path="path1" type="F" mimeType="mimetype-blah1">
<description />
<keywords />
<resver id="1690175442" major="87" minor="0" revision="0" effective-from="20010101000000" effective-to="20991231235959" workflow-step="1000" />
</res>
</package>
I thought of using JAXB to do the work. Is there a better way to solve this?
Can this be done with Simple Java File api?
Answer
I have written this thing using JAXB to acheive this.
Here is the code
try {
File file = new File(FILE);
JAXBContext jaxbContext = JAXBContext.newInstance(Package.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Package pack = (Package) jaxbUnmarshaller.unmarshal(file);
if (pack.getRes() == null || pack.getRes().size() == 0) {
System.out.println("Size zero - exit");
return;
}
for (Package.Res res : pack.getRes()) {
if (! (res.getResver().size() == 1)) {
Short max = getMaxMajorVersion(res);
List<Package.Res.Resver> resverList = removeNonMaxResver(res, max);
for (Package.Res.Resver resver : resverList)
res.getResver().remove(resver);
}
}
finalPack = pack;
} catch (JAXBException e) {
e.printStackTrace();
}
marshal();
Method: extractNonMaxResver
private static List<Package.Res.Resver> removeNonMaxResver(
Package.Res res, Short max) {
List<Package.Res.Resver> resverList = new ArrayList<Package.Res.Resver>();
for (Package.Res.Resver resver : res.getResver()) {
if (resver.getMajor() != max)
resverList.add(resver);
}
return resverList;
}
Method: getMaxMajorVersion
private static Short getMaxMajorVersion(Package.Res res) {
List<Short> list = new ArrayList<Short>();
for (Package.Res.Resver resver : res.getResver()) {
list.add(resver.getMajor());
}
Short max = Collections.max(list);
System.out.println("Max: " + max);
return max;
}
Method: marshal
public static void marshal() {
try {
File file = new File(FILE_OUT);
JAXBContext jaxbContext = JAXBContext.newInstance(Package.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE);
jaxbMarshaller.marshal(finalPack, file);
jaxbMarshaller.marshal(finalPack, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
}
You need to load the XML into either XMLElement or a Java object(using JAXB or other lib). If using XMLEement then you will be iterating through nodes and deleting as per your condition. and in case of Java Model object, just iterate through the list delete them and then persist the same Model as XML file.
Go through the Java Docs :https://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Element.html
It has all API which you can use to manipulate XML.
XML is not a programming language.
you cant add conditions on it, but the same is possible with processing languages such as XSLT.
<xsl:if test="#foo='bar'">
<xsl:text>Hello, world!</xsl:text>
</xsl:if>
I suggest that as the best way to do this kind of operations.
Other possible operations are by parsing the XML String using basic String operations. Its complex and confusing and more error prone.
Ref This

how to develop chatting application in java using flex?

In my Flex Application MXML file i'm writing..
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
width="598" height="459" creationComplete="consumer.subscribe()" layout="vertical">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.messaging.messages.AsyncMessage;
import mx.messaging.messages.IMessage;
public function send():void {
var message:IMessage = new AsyncMessage();
message.destination = "SimpleChatDestination";
message.body = "\n" + usernameInput.text + ":\t" + messageInput.text;
trace(producer.connected);
producer.send(message);
messageInput.text = "";
}
public function messageHandler( message:IMessage ):void {
textArea.text += message.body;
}
]]>
</mx:Script>
<mx:Producer id="producer" destination="SimpleChatDestination"/>
<mx:Consumer id="consumer" destination="SimpleChatDestination" message="messageHandler(event.message)"/>
<mx:TextArea id="textArea" width="400" height="300" color="#F31C1C" editable="false"
enabled="false"/>
<mx:HBox horizontalGap="0">
<mx:TextInput id="usernameInput" width="80"/>
<mx:TextInput id="messageInput" width="180"/>
<mx:Button label="Send" click="send();"/>
</mx:HBox>
</mx:Application>
And in BlazeDs(java side) message-config.xml file i wrote code like this.
<?xml version="1.0" encoding="UTF-8"?>
<service id="message-service"
class="flex.messaging.services.MessageService">
<adapters>
<adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
<!-- <adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/> -->
</adapters>
<default-channels>
<channel ref="my-polling-amf"/>
</default-channels>
<adapters>
<adapter-definition id="actionscript" default="true" />
<!-- <adapter-definition id="jms"/> -->
</adapters>
<default-channels>
<channel ref="my-polling-amf"/>
</default-channels>
<destination id="SimpleChatDestination">
<properties>
<network>
<subscription-timeout-minutes>0</subscription-timeout-minutes>
</network>
<server>
<message-time-to-live>0</message-time-to-live>
<allow-subtopics>true</allow-subtopics>
<subtopic-separator>.</subtopic-separator>
</server>
</properties>
</destination>
</service>
So it is Working fine. But problem is when ever we open three are four chat boxes then all chat boxes are participated.
i want only allow two user can only chat if 3rd user came not visiable 2nd person chating information.
just it is like Facebook,Gmail chating.
plz help me..

Categories